vmdk to kvm (qemu)

I finally decided to migrate the last of my vmware-server systems to KVM.

The process is pretty simple and this is what I did.

  1. As my vmdk file was split into many 2Gb chunks I had to firstly convert that into a monolithic file.  This is easily achieved with the vmware-vdiskmanager utility supplied with vmware-server (or at least the version 1.0.x of vmware-server I was running 🙂 )

    vmware-vdiskmanager -r winxp.vmdk -t 2 winxp-full.vmdk

    The -t 2 is the important part taking all the 2Gb chunks *referenced* by the vmdk file and creating an equivalen single pre-allocated vmdk file.

  2. Once you have that file then it’s a simple qemu-img command to convert it to something that KVM is happy with.  In my case I wanted QCOW2 format.

    qemu-img convert winxp-full-flat.vmdk -O qcow2 winxp.img

    You will notice that I said -full.flat.vmdk – this is the pre-allocated file referred to by the new winxp-full.vmdk file.

  3. That’s it 🙂

pxe boot kvm guests

Bang Bang Bang – that’s my head on the table.  Why wont my Ubuntu Lucid KVM system PXE boot VM’s

Starting SeaBIOS (version 0.5.1-20100120_010601-rothera)

No bootable device.

Is all I got when using -boot n

Clearly something was wrong – and it was = there were no pxe boot roms in /usr/share/kvm .

It seems the problem sources back to this original ubuntu bug report which details how Ubuntu wouldn’t  ship the PXE roms as there is no source for them.

Anyway, I needed to install kvm-pxe from lucid universe and hey presto :

# dpkg -L kvm-pxe
/.
/usr
/usr/share
/usr/share/kvm
/usr/share/kvm/pxe-e1000.bin
/usr/share/kvm/pxe-ne2k_pci.bin
/usr/share/kvm/pxe-pcnet.bin
/usr/share/kvm/pxe-rtl8139.bin
/usr/share/kvm/pxe-virtio.bin

PXE booting now works….  you may all return to your scheduled viewing.

augeas and appending lines to /etc/fstab

Ok, now that’s a specific title 🙂

The reason i’m writing this is because I googled for what appeared to be an eternity and could only find people re-hashing other peoples blog posts that really didn’t help at all.  ps. re-blogging is not the same as re-tweeting and is best avoided.

In this case I wanted to use augeas to append an entry to /etc/fstab.

[root@cobbler manifests]# augtool
augtool> print /files/etc/fstab
/files/etc/fstab
/files/etc/fstab/1
/files/etc/fstab/1/spec = “LABEL=/”
/files/etc/fstab/1/file = “/”
/files/etc/fstab/1/vfstype = “ext3”
/files/etc/fstab/1/opt = “defaults”
/files/etc/fstab/1/dump = “1”
/files/etc/fstab/1/passno = “1”
/files/etc/fstab/2
/files/etc/fstab/2/spec = “LABEL=/boot”
.
.
.
/files/etc/fstab/7
/files/etc/fstab/7/spec = “LABEL=SWAP-vda3”
/files/etc/fstab/7/file = “swap”
/files/etc/fstab/7/vfstype = “swap”
/files/etc/fstab/7/opt = “defaults”
/files/etc/fstab/7/dump = “0”
/files/etc/fstab/7/passno = “0”
Now I wanted to add a NFS entry and since /etc/fstab has line numbers (from an augeas perspective) rather than arrays you have to use a little hack to add the entry.
If you specify a line number that exists then you will replace that entry, however if you specify a line number that doesn’t exist then the line is appended.  So how can you be sure the line number doesn’t exist ?  – well there’s the hack – just put a 0 in front of it and it will never exist 🙂
augtool> set /files/etc/fstab/01/spec “192.168.1.2:/srv/vs”
augtool> set /files/etc/fstab/01/file “/srv/vs”
augtool> set /files/etc/fstab/01/vfstype “nfs”
augtool> set /files/etc/fstab/01/opt[1] “soft”
augtool> set /files/etc/fstab/01/opt[2] “intr”
augtool> set /files/etc/fstab/01/opt[3] “rsize=8192”
augtool> set /files/etc/fstab/01/opt[4] “wsize=8192”
augtool> set /files/etc/fstab/01/opt[5] “nosuid”
augtool> set /files/etc/fstab/01/dump “0”
augtool> set /files/etc/fstab/01/passno “0”
augtool> save
Saved 1 file(s)
[root@cobbler manifests]# cat /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
.
.
.
192.168.1.2:/srv/vs /srv/vs nfs soft,intr,rsize=8192,wsize=8192,nosuid 0 0
So there you go.   Why the hell was I doing this?   Well it was part of a puppet deployment so it was actually part of a puppet class that looks like…
augeas{ “vs mount” :
context => “/files/etc/fstab”,
changes => [
“set 01/spec 192.168.1.2:/srv/vs”,
“set 01/file /srv/vs”,
“set 01/vfstype nfs”,
“set 01/opt[1] soft”,
“set 01/opt[2] intr”,
“set 01/opt[3] rsize=8192”,
“set 01/opt[4] wsize=8192”,
“set 01/opt[5] nosuid”,
“set 01/dump 0”,
“set 01/passno 0”,
],
onlyif => “match *[spec=’192.168.1.2:/srv/vs’] size == 0”,
}
I’m an augeas newbie but given how much I had to search to come even close to the above item may mean this post is of use to someone else.  If it’s already common knowledge then no harm done 🙂