How to build a custom LXD image from install ISO
Stéphane Graber described the procedure for creating images for LXD 2.0 and above from scratch in the article LXD 2.0: Image management (section "Manually building an image"):
Manually building an image
Building your own image is also pretty simple.
- Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using
debootstrap
.- Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).
- Make a tarball of that container filesystem, optionally compress it.
- Write a new
metadata.yaml
file based on the one described above.- Create another tarball containing that
metadata.yaml
file.Import those two tarballs as a LXD image with:
lxc image import <metadata tarball> <rootfs tarball> --alias some-name
You will probably need to go through this a few times before everything works, tweaking things here and there, possibly adding some templates and properties.
The file metadata.yaml
must contain at least the following two key/value pairs (replace i686
with the correct system architecture and 1458040200
with the timestamp in Unix epoch format (e.g. date +%s
):
architecture: "i686"
creation_date: 1458040200
Further information about the metadata.yaml
can be found in the abovementioned article (section "Image metadata").
Related videos on Youtube
John Mayer
Updated on September 18, 2022Comments
-
John Mayer over 1 year
I have an operating system installation ISO. My goal is to run the second operating system on top of the kernel of Ubuntu host running LXD. I cannot find any base image for the said operating system. Is it possible for me to build a custom lxc image to run on top of ubuntu kernel and access the shell of the second system?
Thanks in advanced.
-
iwaseatenbyagrue about 7 yearsI am not totally clear on what exactly you are trying to achieve here - could you expand on your use case a little, for example by explaining what the sequence of events should be? I am struggling a little to understand what you mean precisely by
second operating system
- on the face of it, that sounds like you need (para)virtualisation, rather than containers. For building LXC base images, have you triedlxc-create
,?Ubuntu's LXC overview gives some instructions
-
-
tink about 5 yearsAnd where do I find doco that describes ` tweaking things here and there, possibly adding some templates and properties.` ? I can't seem to find anything that tells me how to wedge my templates in there somehow.
-
Ansgar Wiechers about 5 yearsWhich part of "Further information about the
metadata.yaml
can be found in the abovementioned article (section "Image metadata")" requires further explanation? Click the link in my answer. Go to the section "Image metadata". Scroll down a bit until you get to the sub-section "Templates". Start reading. -
tink about 5 yearsHeh. Ta. I have read that page at least ten times in the last 7 days; doesn't mention anywhere how one ties templates into the tar-ball before importing it into lxd ... did more experimentation though, and figured it out eventually.
lxd
doco is notoriously errrrrhterse
,incomplete
:D -
Ansgar Wiechers about 5 yearsThe parent section of "Image metadata" ("Image formats") features a link to this little gem.