Friday, September 3, 2021

Migrating TrueNAS / FreeNAS Virtual Machines to Proxmox

Purpose : I'm migrating from TrueNAS Core to TrueNAS Scale and underlying OS has change from FreeBSD to Debian. This means they've changed from using the FreeBSD Bhyve Hypervisor to Debian with KVM. 

I want to migrate to the new system with as little downtime as possible, I host a couple of things locally which I don't want to be down to long.

Pre-Req

We use a program called qemu-img to conver the raw VM disk images to qcow2. On my TrueNAS install the external sources were disable and local were enabled. To install the program I enabled the external and disable local temporarily 
  1. SSH to TrueNAS server
    1. nano /usr/local/etc/pkg/repos/local.conf 
      1. change enabled: no
    2. nano nano /usr/local/etc/pkg/repos/FreeBSD.conf
      1. change enabled: yes
    3. pkg install qemu-utils
    4. If it asks you to update your pkg package say no
    5. Remember to change back the sources to the original when qemu-utils have been installed.

Exporting VM from TrueNAS 12

  • SSH to your TrueNAS Server
  • change to /dev/zvol
  • change to your folder where the VMs are stored. As an example mine is /dev/zvol/SSD-Data
  • ls the directory to get the vm names, as an example i have openproject
  • run qemu-img convert -f raw -O qcow2 openproject /mnt/SSD-Data/openproject.qcow2
NOTE: you will need to output your qcow2 file to the /mnt/<folder> or else it'll fail if you try to store in /dev/zvol/<folder>

Importing VM to Proxmox


Copy file to Proxmox

  • SSH into proxmox 
  • create folder /root/vm.import
  • Copy the exported qcow2 file to the proxmox server /root/vm.import directory
For the copying I used WINSCP program to copy the file locally and then uploaded to the proxmox server

Build destination VM 

There needs to be a Virtual Machine created before importing so you can get the VM ID number.
Create a VM with the required specs
NOTE: For my TrueNAS VM's I need to create a VM with BIOS of OVMF (UEFI) since that's how they were built on the TrueNAS Server.

Once the server is build you can remove the hard disk which was created with it. 

Importing VM Disk

  • SSH to proxmox
  • change to /root/vm.import
    • run qm importdisk <vm id> <diskname> <proxmox storage>
    • example qm importdisk 104 openproject.qcow2 QNAP
      • QNAP is the storage name on proxmox
      • 104 is the VM ID of the new VM i created
  • When the transfer is 100% and successful you can continue.
  • remember the name of the file: i.e. QNAP:104/vm-104-disk-0.raw

Attaching the VM Disk

  • SSH into proxmox
  • type qm set <vm id> --scsi0 <vm image name>
    • example : qm set 104 --scsi0 QNAP:104/vm-104-disk-0.raw
NOTE:If you get an error with booting the machine you may need to change the boot device like I did.

Changing Boot Order

  • SSH to proxmox
  • cd etc/pve/qemu-server
  • nano <server id>.conf
    • example nano 104.conf
  • change boot: order=ide2;net0 to boot: order=scsi0
  • save file
  • start virtual machine

Updating Network

Depending on your virtual machine you may need to change the network.
Im using ubuntu 18 and 20 and the network adapter has changed from enp0s4 to ens18
  • ssh into virtual machine
  • find new network name
    • type dmesg | grep eth
    • this will show what the network has changed to. 
      • example virtio_net virtio2 ens18: renamed from eth0
  • nano /etc/netplan/<filename>.yaml
    • example : sudo nano /etc/netplan/50-cloud-init.yaml
  • change the ethernet name from the old to the new 
    • example change enp0s4 to ens18
    • save and exit
  • Make sure the old system is powered off then....
  • type sudo netplan apply

REFERENCES :