Migrating to Proxmox

I have a machine that runs Ubuntu. I want that OS to be running as a VM in Proxmox on the same machine with minimal downtime and without knowing that this process will work without problems. Here is my story.

This is not a guide. Don't expect to follow step by step. Read the whole thing first, then decide if any of it is right for you.

Part 1: Replicate

NB: Part 1 is entirely redundant. It's what I did, but don't do it.

Step 1: Procure a temporary machine

Borrow it from a mate. Shoutout to Nathan. Alternatively, use anything you can, even if it's a bit old. Keep in mind that the hard drive will be wiped though.

Step 2: Boot both machines with Ubuntu Live USBs

But I want to use the same USB, so I boot "to RAM" using the toram flag in the bootloader. More details here. If you don't have an Ubuntu Live USB, use Rufus or Etcher and get the ISO from here.

Step 3: Enable SSH

  1. Install OpenSSH on both (https://ubuntu.com/server/docs/service-openssh)
  2. Enable passwordless sudo on both (https://serverfault.com/questions/160581/how-to-setup-passwordless-sudo-on-linux)
  3. Set passwords for ubuntu account on both (https://www.cyberciti.biz/faq/change-a-user-password-in-ubuntu-linux-using-passwd/)
  4. Generate SSH key on main machine without a passphrase (https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key)
  5. Copy SSH public key to ubuntu@temp-machine using ssh-copy-id (https://www.ssh.com/academy/ssh/copy-id)
  6. Confirm that ubuntu@main-machine can connect to ubuntu@temp-machine using the passkey and no password

Step 4: Prepare disk for copy

On the temporary machine, ensure a disk is prepared with enough space to receive the incoming clone data. Delete all partitions.

Step 5: Install dc3dd

First you must enable the universe: sudo add-apt-repository universe

Then install dc3dd: sudo apt install dc3dd

Step 5: The Magic

dc3dd if=/dev/sda | gzip | ssh ubuntu@temp-machine "gzip -d | dd of=/dev/sda"

To finetune, look into dc3dd parameters as well as gzip paramaters. They have been ignored here to keep it simple. This will take an hour per 100GB without tuning.

Step 6: Reboot temporary machine and turn off main machine

That should be it. If the temporary machine doesn't work as a direct clone of the main machine, you've lost nothing and can try again.

Part 2: Imaging

You've got your system working on the temporary machine.

Step 0: Oh no, that was a waste of time

At this point I realised I hadn't achieved anything useful because I had plans to load up the system first in VirtualBox, then in Proxmox as a VM on the temporary machine, then finally in Proxmox on the main machine.

Part 1 was entirely redundant.

Step 1: Clonezilla Live USB

Install Clonezilla (stable) to a USB.

Step 2: Boot temporary machine from Clonezilla USB

However it works on your BIOS. I mash DEL on boot until the UEFI BIOS shows and then click Boot Menu.

Step 3: Find somewhere to store the image and plug it in

I set up an ext4 partition ona portable hard drive for this, sized to greater than the size of the installation I'll be storing. The image will be compressed though, so my 100GB installation was less than 50GB on the removable disk and the 200GB partition was larger than it needed to be.

Step 4: Follow the docs

Here's the page you want. I know, not sexy, but the Clonezilla docs do come with pictures. The partition you choose as the image repository is the one you just prepared. I chose -z9p and "Yes, check the saved image". Then say yes twice to the y/n prompts.

Part 3: VM Verification

At this point I have an image and I want to see if I can restore it somewhere else. I have two options: install Proxmox on the temporary machine and load it into that, or start smaller and load it up on in a VM within Windows. I chose the latter. I've used VirtualBox a fair bit and VMWare a lot less so I opted to use VirtualBox.

Step 1: Create a new VM

Important settings: a disk with 120GB of space, a few cores of CPU, a few GB of RAM, and the Clonezilla ISO loaded into the virtual disk drive.

Step 2: Plug in the removable storage and attach it to the VM

VM Settings > USB > USB Device Filters, then add a filter for the relevant device. Mine was Seagate Expansion HDD [0001].

Step 3: Boot up and follow the docs

Here's the page you want. Basically the same process but choose restoredisk instead of savedisk.

Step 4: Reboot and voila!

That's it, your system is loaded in a VM.

Part 4: Proxmox

I know the cloned image is good. Now I want to experiment with Proxmox setup before installing for real on the main machine, so I'll install it on the temporary machine first.

Step 1: Burn a Proxmox Live USB

Same as above, but with a Proxmox ISO.

Step 2: Install Proxmox

Boot the temporary machine using the Proxmox USB. Follow the installation process.

Don't expect it to work with wifi, just set it up on ethernet. Trust me. Run cables if you must.

Step 3: New VM who dis

First access the local (pve) section within pve within Datacenter. Open the ISO Images section and upload the Clonezilla ISO to it.

Make a new VM. It will need an ID number and 100 seems fine. Give it a name too. In the OS tab tell it to use the Clonezilla ISO image. in the System tab change the BIOS from SeaBIOS to OVMF (UEFI). A new drive will be suggested for you, scsi0, which is great but it needs more than 32GB so increase that. CPU settings matter too, 1 core will be very slow. I chose 4 cores and didn't touch the other settings because I haven't read about them yet. Likewise with memory, more than 2GB, I went with 10. Start it up!

Step 4: Access the VM

Navigate to the Console section of the VM's interface. This is your screen. Your keyboard and mouse work here. Magic. Modern web browsers really can do anything.

Step 5: Give the VM access to the removable storage

I learned from this post. Find the device with lshw, then find that in /dev/disk/by-id/. The main command, for reference:

qm set 100 -scsi5 /dev/disk/by-id/ata-xxxxxxxxx-xxxxx_xxx

Step 6: Same as Part 3 Step 3

Boot the VM and use Clonezilla to restore the image from the removable storage onto the virtual disk.

Step 7: Reboot and voila!

Your VM now lives within Proxmox. Very cool. Nice work.

Part 5: Permanent

The only thing left to do is to move the VM onto the main machine to live there permanently. Until now we've been avoiding making any changes to the main machine but I feel safe in making irreversible changes since I have verified that my system has been imaged properly by restoring it twice.

Step 1: Install Proxmox for real this time

Repeat step 2 of part 4, this time on the main machine.

Step 2: Migrate the VM from temporary Proxmox to permanent Proxmox

There's a whole process to go through here. I started with this thread.

On the main machine, find the Permissions section in Datacenter and add a new API Token. Assign it to the root user and make sure Privilege separation is unticked. Give the token an ID, such as migration. Copy the token somewhere safe, you'll need this soon.

SSH into the main machine:

ssh root@whatever_IP_address_you_set_it_up_with

Set up a temporary variable using your token. In this example, migration is the token ID - make sure this matches yours:

export APITOKEN='PVEAPIToken=root@pam!migration=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'

Also export that IP address from before:

export HOSTNAME='192.168...'

The command then looks like this:

qm remote-migrate 100 100 apitoken=${APITOKEN},host=${HOSTNAME} --target-bridge vmbr0 --target-storage local-lvm

If, like me, you get a response about a fingerprint not being verified, do the following:

First, copy the fingerprint into a variable:

export FINGERPRINT='36:8E:76:D0...'

Then include it in the migration command:

qm remote-migrate 100 100 apitoken=${APITOKEN},host=${HOSTNAME},fingerprint=${FINGERPRINT} --target-bridge vmbr0 --target-storage local-lvm

Running this process took a while for me. I could see in the temporary Proxmox a status of "config locked (migrate)" on the VM and also a new VM appeared in the permanent Proxmox with status "config locked (create)".

There is a way to track the progress of the migration: on the main machine, view the local-lvm store Summary for the Usage graph. I can see that the usage is 88GB on the temporary Proxmox local-lvm store so I expect the process will complete at a similar number.

Part 6: Epilogue

The migration worked. The new VM on the permanent host has no status but the old one seems to have retained the lock. That doesn't matter to me, I'll be deleting it now anyway.

If you skip parts 1 and 3 and the redundant bits in part 4, you're left with a process that isn't too complicated or time consuming.