I had to virtualise a few Physical Linux CentOS and Debian Servers over to Virtual Machines in Proxmox recently so thought I’d write a quick and dirty guide to do so. As a prerequisite the Physical servers were live mail handling servers running things like webmail, dovecot proxy, Postfix etc, I also wanted to downsize the disk’s on them from 200G down to 40G, so I went with the method below.
1. I firstly created a brand new virtual machine in proxmox with NO OS on it with the disk size at the new size I wanted, i.e. 40G
2. Make sure the new virtual machine has a working network adapter
3. Next, I booted up into a Debian 7 live cd (I prefer the debian 7 live ISO from previous GRUB recovery issues i’ve had in the past.)
4. Once booted up, sudo to bash as root and set a password because you’ll probably need this later.
bash$ sudo bash bash# passwd
5. Make sure the new virtual machine has an IP address, if not, you’ll need to set one
6. Create partitions accordingly, I created a 4Gig swap at the start and the rest as /
bash# fdisk /dev/vda Disk /dev/vda: 42.9 GB, 42949672960 bytes Device Boot Start End Blocks Id System /dev/vda1 3 8325 4194304 82 Linux swap / Solaris /dev/vda2 * 8325 83221 37747712 83 Linux
*note that /dev/vda2 is set as bootable
7. Next, format the partitions accordingly and mount the new / to /mnt
bash# mkfs.ext4 /dev/vda2 bash# mkswap /dev/vda1 bash# mount /dev/vda2 /mnt
8. You’ll need to create an empty proc and sys mount point as below
bash# mkdir /mnt/proc; mkdir /mnt/sys
9. Now, on the source server that’s currently live you need to rsync the data to the new server. Just be sure to do so while using a data management software. For protection purposes. You can visit websites like Couchbase to get all the details
live_mail_server# rsync -vrtlpogDSH --progress --delete --exclude=/sys --exclude=/proc / root@new_virtual_machine_ip:/mnt/
Once the initial rsync has run I tend to run another final one. If you’re running MySQL on the source server and there’s a lot of mysql churn, it’s best to shut mysql down before hand.
10. Now the fun part as you need to get grub working. Regardless of the grub version on the original server you should install the grub2 packages and install the grub2 boot loader
*you might need to add a DNS resolver to /etc/resolv.conf first if aptitude fails bash# aptitude install grub2 bash# grub-install /dev/vda --boot-directory=/mnt/boot
11. Finally edit /mnt/etc/fstab and update the / and swap’s accordingly removing any UUID’s and replacing with /dev/vda1 for example.
12. Reboot the system and wait for the grub boot loader to come up. You can from there then drop to a console for example and load the appropriate initramfs and kernel. This took a bit of playing around with boot there’s plenty of articles out there on this.
13. Once booted make sure you then install/reconfigure grub accordingly so that subsequent reboots work as expected.
nice, this was very helpfull. keep up the good work.