How to convert OpenVz/LXC containers to ESXi?

 

Here my short course of action – perhaps someone will be helpful.

1. create 2Gb clean image on openvz host

dd if=/dev/zero of=/opt2/VHD/speed.img bs=516096c count=4000
fdisk -u -C4000 -S63 -H16 /opt2/VHD/speed.img
2. mount image, create fs

losetup -o32256 /dev/loop0 /opt2/VHD/speed.img
mke2fs -b1024 /dev/loop0 2015968
tune2fs -j /dev/loop0
3. mount image with fs

mount -text3 /dev/loop0 /mnt/speed/
4. copy container files to image

cp -av /var/lib/vz/private/131/* /mnt/speed/

5. umount image

6. convertĀ  image to VMDK format

kvm-img convert -f raw speed.img -O vmdk speed.vmdk
7. on esxi host create VM without hdd
8. copy speed.vmdk to esxi (best way – use FTP)
9. on esxi convert VMDK image to thin format

vmkfstools -i speed.vmdk -d thin speed-thin.vmdk
10. connect speed-thin.vmdk to VM (edit VM properties->add hard disk-> use existing…), start VM, boot from rescue CD:

– vi /etc/network/interfaces

– vi /etc/apt/sources.list
– apt-get update
– apt-get install linux-image-2.6-686 grub-pc
– add in /etc/inittab
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
– echo “/dev/sda1 / ext3 defaults,errors=remount-ro 0 1” > /etc/fstab
– update-grub

11. boot VM normally