Cloning a physical Linux system into a Proxmox VM
Working on replacing my failing server hardware with a new server running Proxmox. Finally realized I could just clone the whole OS off the old system rather than laboriously rebuild every service in a new way as containers on the new server. Clone first, then migrate later. Easy right?
Actually not too hard. The Proxmox wiki has several ways to do what they call “Physical-to-Virtual”, the primary one being “use Clonezilla to clone the entire disk into a KVM on Proxmox”. That’s what I ended up doing but it took about eight tries.
First, though, a minor complaint. It should totally be possible to move a Linux system solely by copying the files with rsync, not the physical disk block by block. I know this can work. But in practice the challenge is making it bootable. I think the modern way to do this is to install Grub in a second UEFI partition, then configure / use it to invoke the kernel on your main system. But the details of that are fiddly and opaque. So I cloned the disc.
The instructions on the wiki more or less worked. I wasted time on a few tries trying to migrate to a smaller virtual disk on the new server: the old server had 20 GB of data on a 256 GB partition. Proxmox has various options that look like this should work but I never could make it work, made doubly exciting by the way the clone tool doesn’t even check if you have space on the receiving disk for what you are cloning. (It worked for 15% and then failed on a seek error, lol.) Anyway, here’s my detailed notes during the process:
- Did a quick cleanup on the old server of disk usage, removing old log files etc to get the size down.
- Used Clonezilla to back up the whole disk to a USB drive as a safety measured.
- Booted Clonezilla remote source on the old server per these instructions.
- Booted Clonezilla remote destination on the new server
- Tried cloning to smaller partition. First time failed immediately (with no resizing options) without a clear error. Second time I told it to resize partitions proportionally; that failed a couple minutes in on a seek error, presumably trying to write past the end of the new smaller partition.
- Fortunately Clonezilla is fairly quick. It’s smart about not cloning unused space, also uses zstd. My copy operated at a nominal 12GB/minute (over gigabit ethernet from SSD to SSD).
- Finally gave up and allocated a destination partition bigger than the source. Clone succeeded but it didn’t boot; hung with 1 core at 100%.
- Searched the net for advice, found my way to this thread which suggests using an EFI BIOS in the VM instead of the default legacy Seasonic BIOS.
- First time cloning to EFI BIOS failed with a bit error on the copy. (Did I mention the old hardware is failing?) Filezilla detected the error, then ignored and made a valiant effort to recover from it. The resulting image was incomplete and did not boot.
- Cloned a second time and it worked! The new VM successfully booted to my Linux partition.
- systemd hung because fstab was trying to mount a hard drive on the old server that didn’t exist in the VM. Used rescue shell to remove those entries from fstab.
- Reboot did better, but got stuck getting network configuration up.
- Used a rescue shell to edit /etc/netplan/10-nelson.yaml to rename the ethernet device. (Use “ens18” instead of old “eno1”.)
- Reboot, comes up, but now no networking. Realize I’d left the old system running on the same IP. Ooops.
- Turn off old system, reboot VM and it works! I have successfully cloned the old server.
apt install qemu-guest-agent. Not strictly necessary but helpful. Despite what the wiki says you can’t start this with systemctl in Ubuntu 23.04. It seems to start automatically somehow if you’ve enabled it in the Proxmox host options and reboot.
Clonezilla does work, and it is free. But oof is it old fashioned and clunky. I could see it totally being worth paying money for a nicer system cloning tool if you did this more than once every few years.
Boy does the BIOS make things complicated. I sort of understood the old legacy boot process but UEFI and GRUB are complex enough they make me nervous. I have zero motivation to sit down and really learn them.