Creating a VM from ISO

How do i create a vm from an ISO? I’ve created a container from scratch, but lxd wants a vm specific image before i can import.

Is it possible to use something created in virt-manager to an lxd vm image?

The main idea is explained with this video by @stgraber :

The demo is done with Windows 11, but I guess it should be the same thing for other OS.

1 Like

I’m not sure what to make of this invocation:

distrobuilder pack-lxd <filename|-> <source-dir> [ target dir ] [ --type=TYPE ] [ --compression=COMPRESSION ] [ --import-into-lxd] [flags]

and getting Error: accepts between 2 and 3 arg(s) . This would really benefit from a straightforward tutorial.

Are you trying to install Windows? If not then you shouldn’t need to use distrobuilder.

I’m trying to create a vm from an ISO of a linux distribution. I’ve tried the debootstrap method to create the container, and that was fine, so i’m trying to create the vm version. It does seem like distrobuilder is the only way to get a vm into lxd, though i’d have thought a lxc image would be better.

It’s slightly opaque in that the distrobuilder error messages or the --help doesn’t intuitively suggest what to do.

Oh and btw the yaml file in the distrobuilder github source examples for ubuntu show these 2 keys 0x790B ( 2012 ) and 0xf6ecb ( 2018 ). Looking at some of the keys i’ve got, there’s a 0x8439 ( 2012 ). Do you know if 0x8439 is a valid key?

I’m a bit confused by this comment:

That isn’t true. You can create an empty VM (using lxc init <instance> --vm --empty) and then boot off an ISO file (by adding a disk device to the VM) and install an OS that way.
Or you can use one of the provided VM images from lxc image ls images:.

For Windows you need to repack the iso file using distrobuilder, before using it to boot the VM from.
But for Linux ISOs this isn’t needed.

The video linked to earlier shows the Windows ISO repack, but from this point on the the tutorial shows how to create an empty VM and boot from the ISO, which isn’t Windows specific.

My mistake i didn’t watch the video tutorial. It’s usually faster as text. Right now i’ve altered a yaml file that distrobuilder can use to configure, but the gpg invocation distrobuilder uses doesn’t seem to take the http-proxy option.

If you’re happy to, you could create a tutorial post on this forum and we can move it to the Tutorials section.

I’m still confused why you’re trying to use distrobuilder, as you’re original post asked about creating a VM from an ISO. To be clear don’t need distrobuilder when creating a Linux VM from an ISO.

Once the VM is created from the ISO you can convert it to a LXD image using the lxc publish command.

To recap, if not using distrobuilder, then using lxc init to create an empty vm and attaching an iso to boot to the install process is a method of creating a VM.

I’m using distrobuilder because that’s the method that first popped up during a search. I’ve got a debootstrap rootfs from creating a container, I thought the distrobuilder might take care of filesystem partitioning, grub, etc.

Is there a way to convert virt-manager kvm based virtual machines to lxd vms?

Yes thats right. You can then create an image from the resulting VM using lxc publish, which allows you to create more VMs from the image without repeating the installation process again.

Is there a way to convert virt-manager kvm based virtual machines to lxd vms?

Not that I know of.

Since both of Libvirt (virt-manager is the frontend GUI for Libvirt) and LXD are using KVM hypervisor for virtual machines, I think importing the QCOW2 disk image from the Libvirt host into LXD should be fine. I never tried by myself but I think there is some solutions on this forum.

The only problem I see for this import is that the VM should be in UEFI mode + support some virtio devices (this shouldn’t be a problem at all for the vast majority of Linux distribution)

I’ve tried using distrobuilder to build a vm image. One of the hurdles to it was getting the gpg verification process working for distrobuilder. distrobuilder uses gpg to do key verification, but the host was behind a proxy, and gpg couldn’t access any keyservers to download the keys to verify the packages. It appears that gpg has a longstanding issue with saying the server indicated a failure, which I’d assumed to mean the keyserver has indicated a failure, when it’s really saying dirmngr has failed in retrieving the keys.

gpg uses an intermediary, dirmngr, to retrieve keys. But there are some quirks to using dirmngr. Firstly the dirmngr requires a dns reply to start connecting to the keyserver. Even using the http-proxy option, a dns reply to the keyserver dnsname is necessary. So adding an entry in the /etc/hosts file can help solve this. The other bit is if gpg --homedir is specified, then dirmngr.conf in the $HOME/.gnupg directory is ignored. This is the case with distrobuilder, so edit the source/utils.go to include a hardcoded keyserver-options http-proxy=<proxy name> and recompile distrobuilder. Probably if the dirmngr.conf from $HOME/.gnupg was copied to the created temp directory for homedir, then this wouldn’t happen.

In any case, after the distrobuilder created the qcow2 image and the meta tarfile, I did an lxc image import . But, on launching an instance with this image, the boot sequence stops at an initramfs prompt.

Instead, I finally decided not to use distrobuilder and went with the more straightforward create an empty vm, attach the ISO and install from there, which went swimmingly well.