P2V to a smaller disk

T

topi

Guest
Recently, I had to migrate a physical machine to Proxmox (P2V), but on a smaller disk. As you can imagine I consulted the documentation http://pve.proxmox.com/wiki/Migration_of_servers_to_Proxmox_VE#How_to_migrate_from_a_physical_machine_to_a_VM.2C_on_a_smaller_partition But I was not completely satisfied with what I read, but in any case I encourage you to read the wiki before reading this post.

With a little thinking about all of that and some tests I followed another way. My idea was to use dd for the system partition (/). It's possible because in my case it's size kept the same. So only used the filesystem level copy to the partitions with a smaller size. I also noticed another way to do with CloneZilla : http://sourceforge.net/projects/clonezilla/files/clonezilla_live_doc/CloningToSmallerDrive_0.1/

It works for me, my VM is now running on Proxmox. But be extremely careful with your production machines. I can't give you any guarantee, specially if your configuration differs (size, partition type, MBR type, bootloader, OS windows ...), or there may be some mistakes in my explanation.

And obviously, I expect your comments or your experiments.

The physical machine

The machine works with SLES 11. The original disk was 2 TiB, but only 800 GiB where really used. My machine had a 50GiB /dev/sda1 partition for /, a 8GiB /dev/sda2 partition for swap, and the rest for a LVM partition /dev/sda3 for home, data ... (mostly empty).
I wanted to virtualize it into a 1 TiB disk on Proxmox.

The steps

On Proxmox
1. Create the VM on Proxmox with a 1 TiB disk size.
2. Boot the VM with a livecd. gPparted is not bad for that.
3. Create the partition /dev/sda1 50GiB. At least the same size of the original (or greater).
4. Create the partition /dev/sda2 8 GiB for swap. The size here could be adapted.
5. Create the third partition /dev/sda3 with the rest of the size. Choose to create a LVM partition or a “normal” partition as you like. Remarks here that new partition is smaller that the physical one.

On the physical machine
6. Boot you physical machine with a livecd (gParted, systemrecue …).
7. Make a dd (by example on an external disk) of the MBR (my MBR is a msdos one, not a GPT), but only the 440 first bytes (we don't want to copy the disk signature and the partition table). Here there is an explanation of why : http://forums.opensuse.org/install-...-mbr-grub-dual-boot-opensuse-11-1-win-xp.html
Code:
dd if=/dev/sda of=mbrsda bs=440 count=1
8. Make a dd (by example on an external disk) of the partitions you want to clone. In my case that was only /dev/sda1 for the system. I couldn’t use dd with /dev/sda3 because the virtualized partition will be smaller. Please consult the documentation of dd to understand how exactly it works.
Code:
dd if=/dev/sda of=ddsda1

The VM onProxmox
9. Boot you VM with a livecd (gParted, systemrecue …)
10. Restore the 440 first bytes of the MBR from the external disk.
Code:
dd if=mbrsda of=/dev/sda bs=440 count=1
11. Restore the /dev/sda1 partition
Code:
dd if=ddsda1 of=/dev/sda1
12. Mount /dev/sda1 into /mnt
Code:
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
13. Check and if necessary adapt the grub files : /mnt/sda1/etc/grub.conf, /mnt/sda1/boot/grub/device.map, /mnt/sda1/boot/grub/menu.lst
15. Mount the third partition (data one) in the hierarchy by adapting fstab
Code:
vi /mnt/sda1/etc/fstab
mount -a
14. Copy the data of /dev/sda3 from the physical machine to the virtual one. Rsync works great or fsarchive if you want. /data corresponds to the mounted partition /dev/sda3
Code:
rsync -az /data root@10.17.X.X:/data
15. Restart your VM and see if all is OK. It was the case for me.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!