HOWTO+-+From+OpenVZ+to+IMG

From openvz to VMWare
I was recently asked to convert an openvz container to a VMWare instance. I found a [|tutorial on a forum] which helped but had to be adapted slightly.

Here is how I eventually managed to do the conversion: > dd if=/dev/zero of=test.img bs=516096c count=40000 > fdisk test.img > Type: o n p 1 > Recent versions of fdisk force partitions to start at 2048, so we want to change that back to 63: x b 1 63 r w > losetup -o32256 /dev/loop0 test.img > mke2fs -b1024 /dev/loop0 > tune2fs -j /dev/loop0 > mount /dev/loop0 /mnt > rsync -av --exclude 'somedir' /vz/root/1234/ mnt > umount /mnt > kvm-img convert -f raw test.img -O vmdk test.vmdk > blkid /dev/sda1 > mount /dev/sda1 /mnt > grub-install --root-directory /mnt /dev/sda1 > chroot /mnt > apt-get install linux-image-foobar #adapt to your kernel version > apt-get install grub-pc > passwd > 1:2345:respawn:/sbin/getty 38400 tty1 > 2:23:respawn:/sbin/getty 38400 tty2 > 3:23:respawn:/sbin/getty 38400 tty3 > 4:23:respawn:/sbin/getty 38400 tty4 > 5:23:respawn:/sbin/getty 38400 tty5 > 6:23:respawn:/sbin/getty 38400 tty6 > proc /proc proc nodev,noexec,nosuid 0 0 > UUID=7925e5b1-f2ad-4cdc-95f9-984d25378194 / ext4 errors=remount-ro 0 1 > grub> insmod ext2 > grub> set root='(hd0,msdos1)' > grub> linux /boot/vmlinuz-foobar root=UUID=7925e5b1-f2ad-4cdc-95f9-984d25378194 ro > grub> initrd /boot/initrd-foobar > grub> boot
 * 1) On the openvz host, create an image (in my case, I need 20GB):
 * 1) Create a partition table in the image:
 * 1) Mount the image using the offset corresponding to the partition table (in our case, 63*512=32256):
 * 1) Copy the container files to the image. I used rsync to exclude some data that were too big:
 * 1) Umount the image and convert it to a vmdk image:
 * 1) Link the vmdk image to a new virtualbox instance (using IDE or SATA for example), booting on a live CD image of your choice
 * 2) Retrieve the UUID of the partition. Note it somewhere, you will need it several times:
 * 1) Mount the partition in the virtualbox instance
 * 1) Install grub on the disk:
 * 1) Chroot into the mounted partition:
 * 1) Install a kernel and grub (using apt for example):
 * 1) Give a password to root:
 * 1) Change inittab to add the ttys:
 * 1) Create an /etc/fstab file (change the UUID with yours):
 * 1) Log out of the chroot and reboot the machine on the virtual disk. You should get a grub prompt (adapt with your UUID). In grub2, you can use autocompletion for the Linux kernel and the initrd image:
 * 1) Log in to the machine and run update-grub
 * 2) Adapt your network settings