[clug] VM disk conversion....
sjenkin at canb.auug.org.au
Fri Jul 23 23:45:55 MDT 2010
We have been doing testing running a system under XEN and I wanted to
try it under VirtualBox. Guest system is Debian Lenny.
Has anyone experience in doing this??
I 'made it happen', but wasn't pretty :-(
I had 5 'drives' mapped for /boot, /, /data, /home and swap.
These lived in plain files in the host file-system.
VBoxManage has a function, 'convertdd', that converts a 'raw image' to a
'.vdi' (Vbox disk format).
I created 5 .vdi's where I really only wanted *1* .vdi.
If it was a physical disk, I'd have /boot in /dev/sda1, and 4 logical
Thinking about this later, could I have used the 5 .vdi files as
/dev/sda, /dev/sdb, ....??? not sure, something to test.
Next option I'd suggest to anyone (now) is:
- under Vbox, do a fresh guest install and partition
your disks how you want, then copy in those old images,
either as 'dd' to an empty partition,
or tar/cp -a as filesystem.
- You've then got a little mucking around to bring up the
new guest, depending on what style of copy you did...
I followed a more circuitous route, which I'm writing up for your
amusement :-) For 'extra credit', I used VirtualBox on my home m/c which
runs OS/X and couldn't read the ext2 'images'.
I had a working Debian guest, with network access, already setup.
Decided to create the new guest with LVM partitions.
Create a 40Gb VDI for new guest.
Attach as 2nd SATA drive to existing guest. (/dev/sdb)
Get access to the images (in an 'ext2' partition on a USB drive)
- OS/X doesn't support 'ext2' and wouldn't map the USB drive through.
- so, create a VMDK 'drive image' mapping physical partitions.
attach this as 3rd SATA drive (/dev/sdc)
OS/X specific commands for the VMDK:
VBoxManage internalcommands listpartitions -rawdisk /dev/disk0
VBoxManage internalcommands listpartitions -rawdisk /dev/disk1
VBoxManage internalcommands createrawvmdk -filename disk1s1.vmdk
-rawdisk /dev/disk1 -partitions 1
Boot existing guest, run "fdisk -l /dev/sd?", stand well back.
Nothing abnormal, good to go.
Mount /dev/sdb1, the ext2 partition with .img files,
then loop-back mount each of the filesystem images.
[was using ext2/3 everywhere]
for d in boot root data home
do mkdir /mnt/$d; mount -o loop $d.img /mnt/$d; done
Use "df -h" + "Used" to give sizes needed in lvcreate
SEtup new 'drive':
Fdisk create 3 partitions on /dev/sdc:
1 - primary /boot [250Mb][used ls -s boot.img to get size in K]
2 - extended rest of drive
5 - LVM partition [type '8e'], whole of extended partn
dd if=boot.img of=/dev/sdc1 [mount and check OK]
vgcreate /dev/sdc5 VG01
lvcreate for root, data, home, swap in VG01
mkfs.xfs for root, data, home
Create directories and mount each of the empty filesystems.
for d in root data home
do mkdir /media/$d; mount /dev/mapper/VG01-$d /media/$d; done
then use your favourite filecopy tool (tar, cp, rsync, ...) to copy from
the source to destination filesystems.
Go for a long walk while it runs :-)
Prepare to 'chroot' to LVM'd disk.
mount -t proc proc /media/root/proc
mount --bind /dev /media/root/dev
umount /media/data /media/home
mount /dev/sdc1 /media/root/boot
mount /dev/mapper/VG01-data /media/root/data
mount /dev/mapper/VG01-home /media/root/home
chroot /media/root, hold breath... Hope it works.
Run apt-get update and anything else that takes your fancy.
I forgot that XEN guests don't use their own kernel+initrd, but Dom0's.
At this stage, install 'grub' in the chroot.
apt-get install grub.
'grub-install --recheck /dev/sdc'
I forgot to twiddle /boot/grub/menu.lst [change root=/dev/mapper/....]
this caused a couple of extra reboots and editing in initrd/busybox
you *must* edit /etc/fstab and fix device paths.
/dev/sda1 /boot ext2
/dev/mapper/VG01-root / xfs
/dev/mapper/VG01-data /data xfs
/dev/mapper/VG01-home /home xfs
/dev/mapper/VG01-swap swap swap
Not having used xfs on a root partition before, I left the ext2 defaults
(errors=remount-ro) and it caused me grief.
I set the options to "defaults" and it worked. Not sure if that's
A little surprise. On boot, there were errors: "fsck.xfs not found"
Not to worry, XFS doesn't have an fsck... xfs_admin and friends. More to
read up on later.
I later installed and ran "update-initramfs" (aptitude search ramfs for
correct name). I thought I had a problem not loading an ethernet driver.
Exit the chroot, unwind all the mounts.
Shutdown the old debian guest.
Detach the extra two Vbox drives (VMDK to USB disk, VDI of new guest)
I rebooted the original debian guest "just to be sure" I'd done no damage.
Create a new Vbox guest and attach the recently created VDI disk.
[Unlike me, you may like to consider if the default (NAT+DHCP) 10.0
network is what you want just now.]
Farnarckle for an hour or two...
I'd setup 'eth0' for a static IP (for a different subnet)
the guest came up without eth0.
The boot process had renamed it to eth1.
By adding a line for eth1 to /etc/network/interfaces
[auto eth1 inet dhcp, IIRC]
ifdown eth1;ifup eth1
resulted in working interface, routing and correct /etc/resolv.conf
You will need "dhcp-client" already installed or that won't work...
apt-get install vbox-modules [use aptitude search for the right name]
The debian repo has the OSE (open source edition) version.
Get VBox Guest Additions working. Needed to 'share folders'.
Mount the cdrom image and run the obvious script.
BUT, you need kernel sources and the bits to build kernel modules.
I found the bits and pieces on my original Debian guest where I'd
built/installed them (and same kernel) and copied them over. Cheating :-)
VirtualBox provides 'shared folders' to allow a guest to read/write into
the host filesystem.
Setting them up is two part:
- in Vbox (even while running) create a shared folder.
The host path you map is pretty obvious.
The 'name' you set, you have to use in the guest.
- in the guest, run 'mount -t vboxfs that-name /mount/point/path'
Shutdown new guest.
Copy new VDI file to your portable HDD. (find in ~/.VirtualBox/HardDisks
or (OS/X) ~/Libary/VirtualBox/HardDisk)
I had to get around OS/X's not-reading-ext2,
used the existing debian guest, the already created VMDK, created a new
shared folder (to the HardDisk dir), attached it to the guest, and in
the host, mounted it.
Mounted /dev/sdb1 (the USB drive) in the guest.
cp -p shared/thingy.vdi /media/sdb1/path/
Umwind the mounts, shutdown the guest.
eject the portable drive.
Steve Jenkin, Info Tech, Systems and Design Specialist.
0412 786 915 (+61 412 786 915)
PO Box 48, Kippax ACT 2615, AUSTRALIA
sjenkin at canb.auug.org.au http://members.tip.net.au/~sjenkin
More information about the linux