howto virtual box to kvm

5
How To Migrate from VirtualBox to KVM on Ubuntu 11.04 (NattyNarwhal) I needed to migrate my development VM (running Fedora 14) from VirtualBox running on my Mac to my Ubuntu Server (11.04, NattyNarwhal). Don't ask why...I'm a masochist. As with all things virtual, this usually means shaving a few yaks. Yak 1 (baby yak): Install VirtualBox on the Ubuntu server, so that you can use VboxManage apt-get install VirtualBox : FAIL! For some reason the VirtualBox package on Ubuntu is named something else. An apt-cache search tells me what I'm missing: apt-get install virtualbox-ose Success!!! Takes about 40 mins on my pathetic BSNL broadband connection, but eventually, I have VirtualBox installed Yak 2 (second baby yak) Convert the .vdi image used by VirtualBox to the qcow format that KVM prefers So I copy over my 5.6 GB .vdi file (takes me a while to locate it on my Mac) to the Ubuntu box. Simple scp command that I refuse to provide...just because I'm feeling nasty. If you don't know how, use a USB stick. First, I convert my .vdi file to a raw image: VBoxManage clonehd --format RAW mydiskname.vdi mydiskname.img Then I convert the .img file to a .qcow file: qemu-img convert -f raw mydiskimage.img -O qcow2 mydiskimage.qcow Success!!! Now I have a qcow image. I quickly test this image by running: kvm -m 1024 -usbdevice tablet -hda mydiskimage.qcow -vnc :1 Since I am running a headless server, I need the VNC argument. I use Chicken on the VNC (cotvnc from Sourceforge) to connect to my server and voila!! my VM is running. Yak 3 (Momma Yak) Getting my KVM virtual machine to connect to my network in bridged mode (i.e. like its an

Upload: arjun1611

Post on 24-Mar-2015

185 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Howto Virtual Box to KVM

How To Migrate from VirtualBox to KVM on Ubuntu 11.04 (NattyNarwhal)

I needed to migrate my  development VM (running Fedora 14) from VirtualBox running on my Mac to my Ubuntu Server (11.04, NattyNarwhal).  Don't ask why...I'm a masochist.

As with all things virtual, this usually means shaving a few yaks.

Yak 1 (baby yak):Install VirtualBox on the Ubuntu server, so that you can use VboxManage

apt-get install VirtualBox : FAIL!

For some reason the VirtualBox package on Ubuntu is named something else. An apt-cache search tells me what I'm missing:

apt-get install virtualbox-ose

Success!!! Takes about 40 mins on my pathetic BSNL broadband connection, but eventually, I have VirtualBox installed

Yak 2 (second baby yak)Convert the .vdi image used by VirtualBox to the qcow format that KVM prefers

So I copy over my 5.6 GB .vdi file (takes me a while to locate it on my Mac) to the Ubuntu box. Simple scp command that I refuse to provide...just because I'm feeling nasty.  If you don't know how, use a USB stick.

First, I convert my .vdi file to a raw image:VBoxManage clonehd --format RAW mydiskname.vdi mydiskname.imgThen I convert the .img file to a .qcow file:qemu-img convert -f raw mydiskimage.img -O qcow2 mydiskimage.qcowSuccess!!! Now I have a qcow image. I quickly test this image by running:

kvm -m 1024 -usbdevice tablet -hda mydiskimage.qcow -vnc :1Since I am running a headless server,  I need  the VNC argument.

I use Chicken on the VNC (cotvnc from Sourceforge) to connect to my server and voila!! my VM is running.

Yak 3  (Momma Yak)Getting my KVM virtual machine to connect to my network in bridged mode (i.e. like its an

Page 2: Howto Virtual Box to KVM

independent machine on the network, not some second class NAT-ted citizen)

First I need to set up my bridge. A little googling tells me to change my /etc/network/interfaces file from being like so:# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).

# The loopback network interfaceauto loiface lo inet loopback

# The primary network interfaceauto eth0iface eth0 inet static address 192.168.0.100 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1 

to being like so:

# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).

# The loopback network interfaceauto loiface lo inet loopback

# The primary network interfaceauto eth0iface eth0 inet manual

auto br0iface br0 inet static address 192.168.0.100 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 gateway 192.168.0.1

Page 3: Howto Virtual Box to KVM

bridge_ports eth0 bridge_fd 9 bridge_hello 2 bridge_maxage 12 bridge_stp off

(thanks mr falko and howtoforge) 

Next I restart my network (of course this promptly kicks me off my SSH session).

/etc/init.d/networking restart

Yak 4 (Big daddy Yak) So now I have my br0 bridge configured. Next I need to figure out how to make KVM use it. Unfortunately all googling reveals that I need to use the virt-manager to make this happen because enough people have almost killed themselves trying to fight KVM on the command line.

virt-manager is apparently a GUI app. So I spend a few minutes cursing the world for making me install X, until I find this by some Anonymous angel in some comment on howtoforge:"you CAN run virt-manager on a headless server.On my Mac, I ran "xhost +my.server.ip".  Then "ssh -X my.server.ip".  Once there, "sudo apt-get install virt-manager".  This will install a bunch of stuff, including GTK libs and some supporting X apps, but it DOESNT actually require X, a Window Manager, or all the other X bloat you don't need if you aren't using the local monitor. 

Then make sure the DISPLAY variable is set: "echo $DISPLAY".  If not, set it: "export DISPLAY='my.mac.ip:0' ".  Then by just typing "sudo virt-manager" on the server (via the ssh session), virt-manager will RUN on the headless server, but DISPLAY on your Mac.

 This assumes you have X11 installed on the Mac.  If not, install it from the Leopard DVD."

So I download virt-manager:apt-get install virt-managerDespite its best intentions it can't avoid downloading some bloat. Once its up and running I follow Mr. Anonymous' instructions and try to get it launched. It works the first time, but then it just keeps giving me the infamous "cannot open display error".So I spend a couple of hours trying to fix that. Ultimately I resort to the:ssh -X user@myserverip xtermIn the xterm:sudo virt-manager

This launches the program. I choose to use an existing image for a new VM and choose the qcow I created while dealing with Yak1.

Page 4: Howto Virtual Box to KVM

However, when I try to boot it, it gives me a "Not a bootable device" error. Meet Granddaddy Yak!

Yak 5 (Granddaddy Yak)Apparently, (According to Dev's blog, found only in Google's cache, bless their heart):

It appears that virt-manager does not read the hard drive image format of a pre-existing image when creating a new virtual machine and instead chooses the “raw” format. Since virt-manager seems to store it’s setting internally, you cannot just edit the /usr/libvirt/qemu/VMNameHere.xml file.You must export the libvirt vm settings to xml, fix the hard drive image formatting, and import the vm settings back into libvirt.

• Get vm name:

virsh -c qemu:///session list –all

• Export vm settings:

virsh -c qemu:///session dumpxml VMName > /tmp/VMName.xml

• Update the hard drive format in the xml file:

From

<devices>

<emulator>/usr/bin/kvm</emulator>

Page 5: Howto Virtual Box to KVM

<disk type=�file� device=�disk�>

<driver name=�qemu� type=�raw�/>

<source file=�/storage/node1.qcow�/>

<target dev=�hda� bus=�ide�/>

</disk>

To

<devices>

<emulator>/usr/bin/kvm</emulator>

<disk type=�file� device=�disk�>

<driver name=�qemu� type=�qcow2�/>

<source file=�/storage/node1.qcow�/>

<target dev=�hda� bus=�ide�/>

</disk>

• Remove old vm settings in virt-manager:

Open virt-manager and delete the problem vm but make sure to leave the hard drive image

• Import in the fixed xml file:

virsh -c qemu:///session define /tmp/VMName.xml

The vm will automatically appear in virt-manager.

The vm should boot fine now.

Thanks Dev! It works now.  The floor is thick with Yak wool, I've exhausted an amount of coffee that my mother would have considered appropriate for consumption over a few months and my mouth tastes of burnt tobacco, but my Virtual Machine is migrated from VirtualBox to KVM.

Parting shot: Still easier than installing VMware ESX on an AMD Phenom X6 1090T...with a NIC not on the VMware HCL. Viva Le Open Source