Unable to create VM from raw image file

Hello,

I am experiencing some interesting problems creating a VM from a raw img file. This is the Mikrotik Cloud Hosted Router (CHR) Image downloaded directly from Mikrotik download site. I tried following standard import procedures both from the web gui and using the migration tool, but something is failing, so here I am :smile:

The host

OS: Ubuntu 24.04 LTS
LXD: LXD 6.3 installed via snap
Volume Storage driver: ZFS

The Image

  • Image: Mikrotik CHR version 7 stable
  • Image settings: This image does not support UEFI boot and secure boot, so I add the following configurations to my LXD VM yaml:
  security.csm: 'true'
  security.secureboot: 'false'

What works

  • If I download and import CHR version 6 as a LXD VM, I can get a VM running, no problem. However my NICs are then not found within the OS because CHR6 does not support virtio drivers.
  • If I download and import CHR version 6 or 7 to a QEMU-KVM hypervisor, both versions of the OS boot using legacy bios without issues.

What does not work

  • If I download and import CHR version 7 using LXD GUI, the import procedure fails with this error:

Error transferring instance data: Failed conversion on target: Failed creating instance on target: Failed to run: /snap/lxd/33085/bin/sgdisk --move-second-header /dev/zvol/lxd-pool/virtual-machines/chr.block: exit status 2 (Invalid partition data!)

  • Same error happens if I manually download the lxd-migrate tool and run it on the host.

I have a quick update on this issue.

I spoke with the folks at Mikrotik and they explained how the CHR image works. Basically it is a raw disk image with a filesystem and no GPT nor boot loader structure. and sgdisk does not like that.

I think with that info, I have a path forward. I will try and build LXD images with CHR and see if I can make it work that way.

1 Like

If you could open a GH issue please then we can explore making that sgdisk operation optional if no GPT partitions are found. Thanks

3 Likes

Sounds good, I will create a github issue. Thank you!

Edit: github issue created Unable to create VM from a raw image file that has no GPT structure · Issue #15411 · canonical/lxd · GitHub

2 Likes

I managed to work around this problem using LXD 6.3 snap on Ubuntu 24.04.
I manually created an instance and cloned the raw image directly into the VM’s block storage. I leave some instructions here in case someone faces a similar issue importing VMs in LXD.

Download the Mikrotik CHR raw disk image

From the Download page, search for Cloud Hosted Router (CHR) and download lastest stable raw image 7.18.2 https://mikrotik.com/download. Unzip the image and you should have this file: chr-7.18.2.img

wget https://download.mikrotik.com/routeros/7.18.2/chr-7.18.2.img.zip
unzip chr-7.18.2.img.zip

Create a new empty VM in LXD.

The instance needs to be empty in order to be started without an image

lxc init --empty mikrotik-chr --vm

Disable UEFI and Secure Boot

Mikrotik CHR does not support UEFI and Secure boot, so we need to disable those.

lxc config set mikrotik-chr security.secureboot false
lxc config set mikrotik-chr security.csm true

Find the ZFS block device for the VM


sudo zfs list -t volume

There should be an entry like this:

lxd-pool/virtual-machines/mikrotik-chr.block

Overwrite the VM disk with the mikrotik chr image

Now we use dd to overwrite the block device of the VM we just created.

sudo dd if=chr-7.18.2.img of=/dev/zvol/lxd-pool/virtual-machines/mikrotik-chr.block bs=4M status=progress conv=fsync

Start the new VM

lxc start mikrotik-chr

Enjoy :tada:

This worked well for me. I hope this is helpful.
Special thanks to the LXD team for writing amazing documentation!

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.