Lxc publish doesn't produce bootable image

Hi! I have an issue with the command lxc publish img_name. When I manually created a VM image from iso file, set partitioning to GPT, created two partitions one EFI System, one for rootfs, installed system, and finally ran LXD image everything works fine:

However, when I decide to save the LXD image for further use, the command lxc publish slackware64-14-2-vm --alias slackware64-14-2-vm leaves me with an unbootable image. When I decided to export an image, I was left with metadata.yml and rootfs.img. I noticed that I can’t boot system from generated rootfs.img file by lxc image export vm_image using command qemu-system-x86_64 -bios /usr/share/edk2-ovmf/OVMF_CODE.fd -hda rootfs.img -m 1G:

I tried to press alt+f1-f8 but it seems like the image generated by lxc publish is unbootable.

Could you show efibootmgr -v and find /boot/efi on the system prior to publishing?

My suspicion is that your distribution doesn’t use the bootx64.efi filename which is picked up on boot but instead relies on specific UEFI NVRAM boot entries which are system specific and can be reset as part of publishing or copying the instance.

I would be grateful if you could help me also solve this problem:

$ lxc exec slackware64-14-2-vm -- /bin/bash                                                                                                                          
Error: Failed to connect to lxd-agent

Do I need to install lxd on the target vm?

Okay, so indeed your bootloader isn’t putting a bootx64.efi entry which then means that when creating a new VM from the image through LXD or directly through QEMU, the firmware won’t know what to boot.

I’m not familiar with elilo but there may be some configuration you can make to have it copy itself as bootx64.efi too to avoid that problem. Alternatively, you should be able to hit ESC during boot and then chose to boot from the EFI shell.
Once in the shell, you can do something like:

  • FS0:
  • cd EFI\Slackware
  • elilo.efi

Which will then directly boot your bootloader. Once booted you can then re-run whatever install script elilo comes with to fix the configuration.

As for lxc exec, you need the LXD agent running inside the VM.
You can try either of:

  • mount -t 9p config /mnt
  • mount -t virtiofs config /mnt

If one of those succeeds, you’ll find the agent binary and some other files in /mnt.
Those are meant primarily for systemd based systems so you may need to sort out your own init script to mount the config share and start the agent on boot.