How to build a custom LXD image from install ISO

9,447

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.

  1. Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using debootstrap.
  2. Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).
  3. Make a tarball of that container filesystem, optionally compress it.
  4. Write a new metadata.yaml file based on the one described above.
  5. Create another tarball containing that metadata.yaml file.
  6. 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").

Share:
9,447

Related videos on Youtube

John Mayer
Author by

John Mayer

Updated on September 18, 2022

Comments

  • John Mayer
    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
      iwaseatenbyagrue about 7 years
      I 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 tried lxc-create,?Ubuntu's LXC overview gives some instructions
  • tink
    tink about 5 years
    And 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
    Ansgar Wiechers about 5 years
    Which 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
    tink about 5 years
    Heh. 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 errrrrh terse, incomplete :D
  • Ansgar Wiechers
    Ansgar Wiechers about 5 years
    The parent section of "Image metadata" ("Image formats") features a link to this little gem.