Bobcares

LXD Debian Image | How to create

by | Mar 18, 2024

Learn how to create a custom LXD Debian Image. Our LXC/LXD Support team is here to help you with your questions and concerns.

How to create Custom LXD Debian Image

Today, we are going to create a custom LXD image based on a basic Debian installation. This works for local use or publishing.

 

How to create Custom LXD Debian Image

  1. To begin with, we have to install debootstrap.
    sudo apt install debootstrapCopy Code

    This will let us create a minimal Debian system in a specified directory.

  2. If LXD is not already installed and configured, we have to install updates on Debian box as seen here:
    $ sudo apt update
    $ sudo apt upgradeCopy Code
  3. Then, it is time to create a minimal Debian installation in a specified directory.

    For instance, to install Debian Sid (unstable) in a temporary directory:

    mkdir /tmp/sid-lxd
    sudo debootstrap sid /tmp/sid-lxdCopy Code

    At this point, we have to enter the created chroot environment to make changes. This will make our container different. For example, to preconfigure the repository for Node.js:

    sudo chroot /tmp/sid-lxd
    wget -qO- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
    echo 'deb https://deb.nodesource.com/node_8.x sid main' > /etc/apt/sources.list.d/nodesource.list
    echo 'deb-src https://deb.nodesource.com/node_8.x sid main' >> /etc/apt/sources.list.d/nodesource.list
    exit
    Copy Code
  4. Then, we have to create a compressed tarball of the root directory of our newly installed system:
    sudo tar -cvzf rootfs.tar.gz -C /tmp/sid-lxdCopy Code
  5. Now, it is time to create a metadata.yaml file. It contains information like image creation date, architecture, name, and description. In order to create an LXD image, we need a metadata.yaml file.

    For example:

    architecture: "x86_64"
    creation_date: 1458040200
    properties:
    architecture: "x86_64"
    description: "Debian Unstable (sid) with preconfigured Node.js repository (20171227)"
    os: "debian"
    release: "sid"
    Copy Code
  6. After the metadata file creation, we have to create a tarball with the metadata file:
    tar -cvzf metadata.tar.gz metadata.yamlCopy Code
  7. Then, import the two tarballs as LXD images:
    lxc image import metadata.tar.gz rootfs.tar.gz --alias sid-nodejsCopy Code
  8. Then, we can create a new container from this image:
    lxc launch sid-nodejs tutorial
    lxc exec tutorial bash
    Copy Code
  9. Next, verify if the container uses the Node.js repository with this command:
    sudo apt update && apt-cache show nodejsCopy Code
  10. Then, configure the LXD daemon to listen to the network and tag the image as public:
    lxc config set core.https_address "[::]:8443"Copy Code

    Other users can now add our server as a public image server and create containers from our image.

  11. Additionally, we can make our LXD image available for server users, by modifying the public parameter:
    lxc image edit sid-nodejsCopy Code

    Here, change `false` to `true` in the last line, save the file, and we have shared our LXD image!

    Furthermore, we can see all available Debian OS templates by running:

    lxc image list images: debianCopy Code

    We can easily create a container with Debian 10 OS as seen here:

    lxc launch images:debian/10 my-debianCopy Code

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to create a custom LXD Debian Image.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Speed issues driving customers away?
We’ve got your back!