Building LXC Container with kiwi-ng

25 views
Skip to first unread message

Sven Wölfel

unread,
Jan 26, 2025, 9:38:07 AMJan 26
to kiwi
Hello,
due to a change in our virtualization environment from Hyper-V to Proxmox I'm now able to experiment with LXC. As I have seen in the documentation it is possible to build Docker or OCI Images with kiwi-ng. Would this be possible with LXC as well?

My idea so far is to use the existing appliance configurations we use for our VMs, switch the ''image" type from "oem" to "tbz" and remove the kernel packages. 

This would still require to create the metadata files for LXC by hand but this should be a one time effort.

Has anybody created LXC images with kiwi-ng? Is my approach sound or am I missing some crucial detail?
All LXC related messages I could find were related to the legacy version of kiwi.

I'm thankful for any Input.

Best Regards

Sven

Marcus Schäfer

unread,
Jan 26, 2025, 1:25:19 PMJan 26
to kiwi-...@googlegroups.com
Hi,

> due to a change in our virtualization environment from Hyper-V to
> Proxmox I'm now able to experiment with LXC. As I have seen in the
> documentation it is possible to build Docker or OCI Images with
> kiwi-ng. Would this be possible with LXC as well?

At the moment kiwi supports the building of OCI compliant
containers only. Target for these containers are OCI compliant
runtimes, e.g docker, podman, ECR, etc etc and container runtimes
that support import of OCI compliant container formats e.g
containerd, k3s, kubernetes

Unfortunately nothing of this applies to LXC. afaik on Ubuntu
LXD is used as further development of the former LXC. If I
understood it correctly the LXC developers moved the project
into LXD with functionality of LXC still present. But I'm not
an expert here. When I was implementing support for OCI containers
to kiwi I was also looking into LXD/LXC but never finished
or needed them. I stored the following information in my howto
folder which actually tells you all you need.

https://discourse.ubuntu.com/t/creating-custom-lxd-images/13970

The rootfs.tar.gz tarball you can create with kiwi using the
image="tbz" type. The rest of the instructions is not implemented.

> My idea so far is to use the existing appliance configurations we use
> for our VMs, switch the ''image" type from "oem" to "tbz" and remove
> the kernel packages.

yes

> This would still require to create the metadata files for LXC by hand
> but this should be a one time effort.

right as I mentioned not implemented in kiwi

> Has anybody created LXC images with kiwi-ng? Is my approach sound or am
> I missing some crucial detail?

I don't see a reason why this procedure won't work.
It would be nice to have lxd support natively in kiwi, but
unfortunately I won't have time to do it soon. I don't think it
will be a big effort. You create a new builder class and inherit
from the tbz builder, then add the code for the metadata and
call "lxc image import" to produce the result.

As you need to run these steps anyway somehow, you could also
consider to implement it in kiwi ;) We love contributions :)

> All LXC related messages I could find were related to the legacy
> version of kiwi.

Yeah forget that, legacy LXC is not what you are looking for :-)

Regards,
Marcus
--
Public Key available via: https://keybase.io/marcus_schaefer/key.asc
keybase search marcus_schaefer
-------------------------------------------------------
Marcus Schäfer Brunnenweg 18
Tel: +49 7562 905437 D-88260 Argenbühl
Germany
-------------------------------------------------------
signature.asc

Sven Woelfel

unread,
Jan 27, 2025, 1:54:53 PMJan 27
to kiwi-...@googlegroups.com

Hi,

At the moment kiwi supports the building of OCI compliant
containers only. Target for these containers are OCI compliant
runtimes, e.g docker, podman, ECR, etc etc and container runtimes
that support import of OCI compliant container formats e.g
containerd, k3s, kubernetes

Unfortunately nothing of this applies to LXC. afaik on Ubuntu
LXD is used as further development of the former LXC. If I
understood it correctly the LXC developers moved the project
into LXD with functionality of LXC still present. But I'm not
an expert here. When I was implementing support for OCI containers
to kiwi I was also looking into LXD/LXC but never finished
or needed them. I stored the following information in my howto
folder which actually tells you all you need.

    https://discourse.ubuntu.com/t/creating-custom-lxd-images/13970

The rootfs.tar.gz tarball you can create with kiwi using the
image="tbz" type. The rest of the instructions is not implemented.

As I understood the relationship between LXC and LXD/Incus is a bit like runC and Docker. The latter just makes it easier and introduces the concept of "Container Images" with additional functionality to make it more convenient to use. Proxmox for example only uses LXC. It only needs a rootfs tarball and some additional Proxmox related configuration to set the container up (basically calling lxc manually through a pve tool wrapper).

Thanks for the link, actual low level information of LXC and LXD is scarce. I only found https://stgraber.org/2016/03/30/lxd-2-0-image-management-512/ but a complete definition of the metadata attributes is still missing. The divide between Canonical LXD and the community fork Incus makes it even more confusing. Maybe a deeper look in the man pages will shed some light on this topic.

I don't see a reason why this procedure won't work.
It would be nice to have lxd support natively in kiwi, but
unfortunately I won't have time to do it soon. I don't think it
will be a big effort. You create a new builder class and inherit
from the tbz builder, then add the code for the metadata and
call "lxc image import" to produce the result.

Are you referring to the archive builder (kiwi/builder/archive.py)? If so then this looks actually doable.

"lxc image import" is only needed on the target host that needs to run the container later. So just creating the two tarballs should be enough for kiwi.

As you need to run these steps anyway somehow, you could also
consider to implement it in kiwi ;) We love contributions :)

There are some question-marks in regard to getting the required data for the metadata from the xml config, but yeah I might give it a try. But first I wanna try if the tarballs I created are working with LXC. If this works I will setup the python environment and give it a shot.


Regards

Sven

Reply all
Reply to author
Forward
0 new messages