Donnerstag Mai 08, 2008

VirtualBox 1.6 on OpenSolaris (Build 85)

I'm using VirtualBox on OpenSolaris very often. VBox allows me to start other guest OS (eg Windows XP) in a really simple way and in addition using some great features of solaris natively. One of this features is ZFS. Think about running a VBox guest OS within a ZFS volume. With all the extra stuff like encryption or compression. Sounds good?

The first build of VirtualBox for OpenSolaris was released in Feb 08 and was version 1.5.51. This version worked really good, but some features were not in, eg raw disc access. But to get some expertice with VBox, I've started building some VMs without using that raw disc access feature. I've built just some plain Windows XP VMs using VirtualBox default file format „vdi“. I was impressed about the really good speed of Windows XP running within a VM. Sometimes I thought it runs faster within a VBox VM than running natively on the same metal of hardware (my Toshiba Tecra M5).

Anyway. In May 08 Sun released version 1.6 of VirtualBox. This version left the beta state (1.5.51 was a beta version) and comes with mostly all needed features that I need to work. Basicly this raw disk access was fixed.

In this entry I want to write about

„How to upgrade your system to VirtualBox 1.6 and convert a plan VDI based VM to a ZFS volume“

First download VirtualBox 1.6 from here:

http://www.virtualbox.org/wiki/Downloads

There are two version for OpenSolaris: AMD64 and i386. To make sure you are getting the right one, use

# isainfo -k
amd64

„amd64“ is what I'm running on (not really myself, but my laptop :)

Before you start with the upgrade, make sure you have read that advice on the download page:

Warning: saved states and snapshots are not compatible between different versions of VirtualBox. Merge all snapshots, restore all saved states and shutdown all VMs properly before attempting to upgrade.

Please: do it!

Next you can uninstall the beta version. Become root and remove the package.

# pkgrm INNOvbox

Unzip and extract the download of VBox 1.6.

# gunzip < VirtualBox-1.6.0-SunOS-amd64.tar.gz| tar xvf -

Install the package.

# pkgadd -d VirtualBox-1.6.0-SunOS-amd64.pkg

The installation took some time on my laptop (around 5 minutes). It seems that the pkgadd postinstall script hangs up on a call of /usr/sbin/devlinks. After this the script finished fine without an error message.

Now we are ready to start migrating the VDI based disk to a ZFS volume. First create a ZFS volume.

# zfs create -V 10G zfs/zvol_WinXP

This command will create a ZFS called „zvol_WinXP“ within the ZFS filesystem „zfs“ with a volume size of 10 gig.

# zfs list
NAME USED AVAIL REFER MOUNTPOINT
zfs 14,2G 17,3G 4,23G /zfs
zfs/zvol_WinXP 10G 27,3G 16K -

As you can see from this output ZFS will just allocate a very small piece (16K) on disk, when creating a ZFS volume.

Solaris will create automatically the following devices for you

/dev/zvol/dsk/zfs/zvol_WinXP
/dev/zvol/rdsk/zfs/zvol_WinXP

If you are working on you daily business as a non-root user (as I do), you must make sure that this user will be the owner of that devices.

# chown <your-user-id> /dev/zvol/rdsk/zfs/zvol_WinXP

Next we create the VMDK file with raw disk access. I do this with my normal user account (not root).

$ cd /opt/VirtualBox/
$ ./VBoxManage internalcommands
createrawvmdk -filename /zfs/VMDKs/zvol_WinXP.vmdk -rawdisk
/dev/zvol/rdsk/zfs/zvol_WinXP>
[..]
RAW host disk access VMDK file /zfs/VMDKs/zvol_WinXP.vmdk created successfully.

This command will create a file called /zfs/VMDKs/zvol_WinXP.vmdk, which basically just points to that raw disk /dev/zvol/rdsk/zfs/zvol_WinXP.

Here is how my VMDK looks.

$ cat /zfs/VMDKs/zvol_WinXP.vmdk
# Disk DescriptorFile
version=1
CID=02a81820
parentCID=ffffffff
createType="fullDevice"

# Extent description
RW 20971520 FLAT
"/dev/zvol/rdsk/zfs/zvol_WinXP"
# The disk Data Base
#DDB

ddb.virtualHWVersion = "4"
ddb.adapterType="ide"
ddb.geometry.cylinders="16383"
ddb.geometry.heads="16"
ddb.geometry.sectors="63"
ddb.uuid.image="04832894-c688-4daf-ceb6-303fcc207a7d"
ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
ddb.uuid.modification="00000000-0000-0000-0000-000000000000"
ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"

To use this VMDK file as a disk for guest OS you need to register it against VirtualBox.

$ ./VBoxManage registerimage disk /zfs/VMDKs/zvol_WinXP.vmdk 

You can list all your registered virtual disks by using the VBoxMange command.

$ ./VBoxManage list hdds
[..]
UUID: 46bdc3bb-b375-41da-2581-bd1676a48266
Storage type: Virtual Disk Image
Path: /zfs/WinXP/hdd0.vdi
Accessible: yes
Usage: WinXP (UUID: b0890587-9637-46bd-4ba5-7f062e2be51b)
UUID:         04832894-c688-4daf-ceb6-303fcc207a7d
Storage type: unknown
Path: /zfs/VMDKs/zvol_WinXP.vmdk
Accessible: yes

As you can see, I've got two registered virtual disks. One is the plain VDI file (/zfs/WinXP/hdd0.vdi ) and the other one is the newly registered VMDK file. You may also notice that the VDI file is used by a VM called „WinXP“.

But how can we transfer data from VDI to VMDK? Google'ing around some minutes gives you some ideas how to do it. Here is a my summary of approaches.

  • Create a new VM with both virtual disks attached (VDI and VMDK). Next attach a mini linux distro iso image to it and fire it up booting the iso. Use dd to do the transfer between disks. The transfer will be done inside the guest OS.

  • Cut away the VDI related stuff from the VDI file and extract the file system related blocks with dd. This approach will do the transfer from the host OS.

Let's start with the first approach.

We need to detach the VDI file from the WinXP VM first.

$ ./VBoxManage modifyvm WinXP -hda none

Create the transfer VM. I will give it a really „talking“ name: tempVM.

$ ./VBoxManage createvm -name tempVM -register
[..]
Virtual machine 'tempVM' is created and registered.
UUID: fa253d62-015a-4ede-02ad-6b02acae2b12
Settings file: '/zfs/Machines/tempVM/tempVM.xml'

Now attach both disks to tempVM. The VDI virtual disk should be connected as „hda“ and the VMDK based virtual disk (raw disk) should be connected as „hdb“. I will use the UUIDs of the virtual disks (see output of „VBoxMange list hdds“).

$ ./VBoxManage modifyvm tempVM -hda 46bdc3bb-b375-41da-2581-bd1676a48266 -hdb 04832894-c688-4daf-ceb6-303fcc207a7d

The iso image for booting this tempVM is in my case a GParted Live CD (version 0.3.6-7). Register this iso image for using it for a guest OS.

$ ./VBoxManage registerimage dvd /share/Images/gparted-live-0.3.6-7.iso 

Sneak out the UUID of that virtual DVD device.

$ ./VBoxManage list dvds
[..]
UUID: d595a411-19a6-47cc-e8af-15672a7555ce
Path: /share/Images/gparted-live-0.3.6-7.iso
Accessible: yes

Attach that UUID to the VM and define the boot order.

$ ./VBoxManage modifyvm tempVM -dvd d595a411-19a6-47cc-e8af-15672a7555ce -boot1 dvd
Do some fine tuning of the tempVM. Define the guest OS as „debian“ (GParted is based on Debian) and give the VM a piece of virtual memory.
$ ./VBoxManage modifyvm tempVM -ostype debian -memory 256M

Now it is time to fire it up :)

$ ./VBoxManage startvm tempVM -type gui

When the VM came up, just wait until the text based console start and enter

$ sudo su -
# dd if=/dev/hda of=/dev/hdb

This step takes some time...go and get a beer or two or a coffee or just get well informed and read the VirtualBox User Manual for the actual version. It's your choice. I will take the beer...

http://www.virtualbox.de/download/1.6.0/UserManual.pdf

After dd finished you can shutdown the VM with a

# shutdown -h now

It's time for some house cleaning now. Detach virtual disks and dvd and unregister „tempVM“.

$ ./VBoxManage modifyvm tempVM -hda none -hdb none -dvd none 
$ ./VBoxManage unregistervm tempVM -delete

Checking the result is the final part of this entry. First we need to attach the VMDK file to the old WinXP VM.

$ ./VBoxManage modifyvm WinXP -hda 04832894-c688-4daf-ceb6-303fcc207a7d

And final power on the VM.

$ ./VBoxManage startvm WinXP -type gui

Voila! You now have a ZFS volume based Windows XP virtual machine running on the best operating system ever. :)

If you've finished testing the VM you can clean up the rest with the following commands.

$ ./VBoxManage list hdds 
[..]
UUID: 46bdc3bb-b375-41da-2581-bd1676a48266
Storage type: Virtual Disk Image
Path: /zfs/WinXP/hdd0.vdi
Accessible: yes

UUID: 04832894-c688-4daf-ceb6-303fcc207a7d
Storage type: unknown
Path: /zfs/VMDKs/zvol_WinXP.vmdk
Accessible: yes
Usage: WinXP (UUID: b0890587-9637-46bd-4ba5-7f062e2be51b)

$ ./VBoxManage unregisterimage disk 46bdc3bb-b375-41da-2581-bd1676a48266

$ ./VBoxManage list dvds
[..]
UUID: d595a411-19a6-47cc-e8af-15672a7555ce
Path: /share/Images/gparted-live-0.3.6-7.iso
Accessible: yes

$ ./VBoxManage unregisterimage dvd d595a411-19a6-47cc-e8af-15672a7555ce

Kommentare:

Ingenious... I think it was a good idea to give Solaris a chance and take a look on it. :)

Gesendet von Patrick am Juli 06, 2008 at 01:54 PM CEST #

Linkback to your blog...

Note: the parent website (Cognition Group) is going through come company reorganization at the moment. So don't be confused by what you see on www.cognitiongoup.biz if you go there.

That will change soon enough.

Gesendet von Richard Schilling am März 22, 2009 at 08:46 PM CET #

In case you didn't see to click on my name... here's the link to a wiki that references this blog:

http://wiki.cognitiongroup.biz/moin.cgi/CategoryOpenSolaris

Gesendet von Richard Schilling am März 22, 2009 at 08:47 PM CET #

Senden Sie einen Kommentar:
  • HTML Syntax: Ausgeschaltet