Create a container from a local VM image


I created a VM with this command:
lxc launch images:ubuntu/21.10/desktop ubuntu2110 --vm -c limits.cpu=4 -c limits.memory=4GiB --console=vga

Then I created an alias for that:
lxc image alias create local:ubuntu-21-10 71ba5f5629fe

And tried to create a container from it:
lxc launch local:ubuntu-21-10 ubuntu-21-10-container

But the type for that is VIRTUAL-MACHINE :confused:

Is there a way to create it as a container?
I imagine a VM uses much more space than a container, right?

Yes, create a container without the --vm and then create an alias for the container image that is downloaded. You cannot create containers from VM images.

That’s sad. :frowning:

Do you think it’s something that could be implemented?
I thought there would be a flag for that.

I would not like to have to download gigabytes again :slight_smile:

Is the other way possible, ie, create VM from local containers?

The two are pretty different. To turn a VM image into a container, we’d need to map that virtual disk, extract the main partition and then strip a whole bunch of packages from it. All of that is problematic as mapping and mounting partitions can exploit kernel bugs leading to a complete compromise of the host system. Some of that could be worked around using libguestfs but that’s really quite slow and would leave us with the next problem of knowing what to remove and how as that will depend on the exact OS and version in the image.

The other way around is safer as we wouldn’t need to deal with a binary disk image but the rest of the issue would somewhat remain in that we’d need to figure out what to add to turn a container into a VM image, then generate a virtual disk, partition table, format the partitions, copy the data, setup a bootloader, …

LXD in general is trying to be completely agnostic of what’s going on in the instance, so having to add a lot of logic that’s OS/distro specific would go quite counter to our design goals and would massively complexify things and make them much more brittle (a simple thing like a distro changing package name in a specific version would break it).

1 Like