Saturday, July 2, 2011

Converting an Oracle VM VirtualBox VM into an Oracle VM Server image


As we are working on tighter seemless moving of VM's between the 2 products, here are a few simple steps to convert an existing Oracle VM VirtualBox image over.
Steps involved to make it easy/straightforward :
(1) When creating a VM in Virtualbox, using Oracle Linux as an example, make sure that /etc/fstab only uses labels. Do not use hardcoded device names.
instead of an entry
/dev/sda1 /u01 ext3 defaults 1 1
use
LABEL=foo /u01 ext3 defaults 1 1

for more info on labels : man e2label
or use a logical volume
/dev/VolGroup00/LVfoo /u01 ext3 defaults 1 1
Doing so will make it easier to have an OS boot up on a different hypervisor with potentially different device names. For instance, the VirtualBox VM might expose a scsi driver while in Oracle VM Server you might end up with an ide disk, this then changes /dev/sda to /dev/hda.
(2) If you have a VM created that you want to convert, then shut down the VM in VirtualBox and convert the image files :
go the the directory that contains your HardDisk image files (.VirtualBox/HardDisks/* as an example)
for each of the virtual disks run the following command :
VBoxManage clonehd virtualdiskfilename.vdi system.img --format raw
where virtualdiskfilename.vdi is the original VBox VM file (this can also be a vmdk file) and system.img is the name of the virtualdisk for Oracle VM. this can be any filename as well, I typically use system.img to specify the boot disk (as is common for Oracle VM template creation)
(3) create a vm.cfg
To run a VM converted from VirtualBox, you have to create a vm.cfg for Oracle VM server that creates an HVM guest. The easiest is to use a simple hvm vm.cfg and change it for your vm. I have an example here :
acpi = 1
apic = 1
builder = 'hvm'
device_model = '/usr/lib/xen/bin/qemu-dm'
disk = ['file:system.img,hda,w', 'file:oracle.img,hdb,w',',hdc:cdrom,r',]
kernel = '/usr/lib/xen/boot/hvmloader'
memory = '1024'
name = 'vmname'
on_crash = 'restart'
on_reboot = 'restart'
pae = 1
serial = 'pty'
timer_mode = '0'
usbdevice = 'tablet'
vcpus = 1
vif = ['bridge=xenbr0,type=ioemu']
vif_other_config = []
vnc = 1
vncconsole = 1
vnclisten = '0.0.0.0'
vncpasswd = ''
vncunused = 1
If you take the above vm.cfg, all you need to do
- modify disk = (add your virtual disks in there)
- modify memory = (amount of memory your VM needs)
- modify name = (enter a name for your VM here)
- modify vif = (might want to replace bridge=xenbr0 to the bridge you want to use)
if you want more than 1 vcpu or other changes of course you have to make those as well.
(4) copy this set of files onto your Oracle VM server or onto a webserver in a subdirectory and import the template through Oracle VM Manager. You can also just start the vm using xm create vm.cfg if you like.
And that's it. As I said, we are working on automation around all this but it is relatively trivial to convert VM's over as long as you take the basic issues into account. Primarily the set up of the filesystems and the use of labels in/etc/fstab.
There are other potential things to look at, such as network config. If you want to make that part clean then prior to shutting down the VM change /etc/modprobe.conf and/or add the mac address of the VM into the vm.cfg in the vifs line. The good thing, at least with Linux, is that even tho the virtual hardware changes, Linux will deal with it just fine (e1000 vs 8139 realtek, ide vs scsi etc).
hope this helps.

No comments:

Post a Comment