Bienvenido! - Willkommen! - Welcome!

Bitácora Técnica de Tux&Cía., Santa Cruz de la Sierra, BO
Bitácora Central: Tux&Cía.
Bitácora de Información Avanzada: Tux&Cía.-Información
May the source be with you!

Sunday, December 5, 2010

Sharing VirtualBox Images

between Windows/Linux
NOTE: openSUSE 11.2
I have a dual-boot machine, and I like to use VirtualBox, but I don't want to have duplicate VB's on each partition. I wanted to create a guest VB, and be able to use it from either Host Windows or Host Linux, so any changes I made while booted in Linux using the shared VB would be available when I booted to Windows using the share VB. I received all sorts of weird problems when trying to do this.
The problem I had is that I was trying to share the actual IMAGE/Machine. Instead create a VB Image/Machine and share the HARD-DRIVE!!! This is actually pretty clever the way VB does it. You can create VBoxes that have no hard drive. You can create Virtual HardDrives that aren't connected to any machine. Or you can connect Virtual Hard Drives to different Machines (similar to what we do in the labs). The only problem I ran into was the read/write permissions of using a file on a windows partition.
Here is what I had to do to accomplish this.

First - create the VB image in Windows. Include all the configurations you want.
When you boot to linux, your Windows Drives must be mounted. By default, linux mounts NTFS drives as "ntfs-3g" and makes them read-only. (That is how openSUSE does.) You have to unmount the windows drive, and remount it with different permissions.
Example: Your Windows "C" drive is mounted read-only as an NTFS-3G filesystem under /windows/C Let's say this is under /dev/sda1
So you would issue (as root)
umount /dev/sda1
OR
umount /windows/C
Then remount the drive with these options
mount -t ntfs-3g -o inherit /dev/sda1 /windows/C
The other option is to edit your /etc/fstab file. Mine had an entry like this:
/dev/disk/by-id/ata-ST9500325AS_5VE3C3LX-part2 /windows/C           ntfs-3g    users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0
Which basically was seen by the OS as /dev/sda2
I edited the line to look like this:
/dev/disk/by-id/ata-ST9500325AS_5VE3C3LX-part2 /windows/C ntfs-3g rw 0 0
Now - all those pesky read/write permissions don't get in the way.
I start VB in Linux - create a NEW MACHINE, and attach the EXISTING Virtual Hard Drive from my Windows partition. I also set up the network adapters to be the same. (Example: NIC1 is bridged to my Wired LAN in windows, and to eth0 in linux. NIC2 is bridged to my WIFI card in Windows, and to wlan0 in linux.) Now - I can just connect/disconnect the cable to the correct virtual NIC depending on how my host machine connects to the network.
========================
Assuming you have your Virtual Machines images as /windows/VMs at /dev/sda7
Look for the line in fstab
sudo nano /etc/fstab

/dev/sda7 /windows/VMs ntfs-3g   users,gid=users,fmask=133,dmask=022,locale=en_GB.UTF-8 0 0
and replace it with 
/dev/sda7 /windows/VMs ntfs-3g defaults,umask=0  0 0
====================
If write permission fails for NTFS partition
It  could be just because Windows hybernate!
If you have Windows and Linux on the same machine, don't hybernate Windows, because NTFS partitions can not be accessible with write permission through Linux.
An issue with an external USB drive with NTFS can be that the NTFS partition would become corrupt, it would allow me to continue writing to it until I rebooted, then it would mount read only.Running following command under Vista would fix it

chkdsk {drive}: /f /r /x

and then you could write again in Suse as it would mount read/write once again.

No comments: