Linux – How to build a custom LXD image from install ISO

containerslinuxlxcUbuntuvirtualization

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.

Best Answer

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").