Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Using Distrobuilder to Create a LXD Image

While base LXD images are ideal for the majority of LXD use cases, there are times when we'll want to roll a container image from scratch to precisely suite our needs. For this, we can use Distrobuilder, which lets us configure LXC and LXD images using YAML.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Published
Clock icon Apr 03, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Copy the Base Image Configuration

    Create a new buster directory under the existing images directory in the cloud_user's home directory:

    mkdir images/buster
    

    Copy the existing images/eoan/eoan.yaml file to the new directory to work from:

    cp images/eoan/eoan.yaml images/buster/buster.yaml
    cd images/buster
    
  2. Challenge

    Update the Architecture

    Open the buster.yaml file and update the image section to reflect Debian 10 (Buster):

    vim buster.yaml
    
    image:
     distribution: debian
     release: buster
     description: |-
       Debian {{ image.release }}
     architecture: x86_64
    
  3. Challenge

    Update the Source

    Update the source section to reflect Debian's download servers and keys:

    source:
      downloader: debootstrap
      url: http://deb.debian.org/debian
      keyserver: hkp://keyserver.ubuntu.com:80
      keys:
        - 0x126C0D24BD8A2942CC7DF8AC7638D0442B90D010
        - 0xA1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553
        - 0x6D33866EDD8FFA41C0143AEDDCC9EFBF77E11517
        - 0x80D15823B7FD1561F9F7BCDDDC30D7C23CBBABEE
    
  4. Challenge

    Remove netplan and Any Ubuntu References

    For the next two sections, we want to eliminate any references to Ubuntu, and also fully remove the netplan portion of the configuration:

    targets:
      lxc:
        create-message: |-
          You just created an {{ image.description }} container.
    
          To enable SSH, run: apt install openssh-server
          No default root or user password are set by LXC.
    
        config:
          - type: all
            before: 5
            content: |-
              lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.common.conf
    
          - type: user
            before: 5
            content: |-
              lxc.include = LXC_TEMPLATE_CONFIG/ubuntu.userns.conf
    
          - type: all
            after: 4
            content: |-
              lxc.include = LXC_TEMPLATE_CONFIG/common.conf
    
          - type: user
            after: 4
            content: |-
              lxc.include = LXC_TEMPLATE_CONFIG/userns.conf
    
          - type: all
            content: |-
              lxc.arch = {{ image.architecture_personality }}
    
    files:
     - path: /etc/hostname
       generator: hostname
    
     - path: /etc/hosts
       generator: hosts
    
     - path: /etc/resolvconf/resolv.conf.d/original
       generator: remove
    
     - path: /etc/resolvconf/resolv.conf.d/tail
       generator: remove
    
     - path: /etc/machine-id
       generator: remove
    
     - path: /etc/network/interfaces
       generator: dump
       content: |-
         # This file describes the network interfaces available on your system
         # and how to activate them. For more information, see interfaces(5).
    
         # The loopback network interface
         auto lo
         iface lo inet loopback
    
         auto eth0
         iface eth0 inet dhcp
    
     - path: /etc/init/lxc-tty.conf
       generator: upstart-tty
       releases:
        - trusty
    
     - name: meta-data
       generator: cloud-init
       variants:
        - cloud
    
     - name: network-config
       generator: cloud-init
       variants:
        - cloud
    
     - name: user-data
       generator: cloud-init
       variants:
        - cloud
    
     - name: vendor-data
       generator: cloud-init
       variants:
        - cloud
    
  5. Challenge

    Update the packages Section

    Update the packages section of the configuration so that it uses the appropriate Debian repositories and installs the correct packages:

    packages:
      manager: apt
      update: true
      cleanup: true
    
      repositories:
        - name: sources.list
          url: |-
            deb http://deb.debian.org/debian {{ image.release }} main
            deb http://security.debian.org/debian-security {{ image.release }}/updates main
    
      sets:
        - packages:
          - dialog
          - ifupdown
          - init
          - iproute2
          - isc-dhcp-client
          - locales
          - netbase
          - net-tools
          - openssh-client
          - vim
          action: install
    
        - packages:
          - cloud-init
          action: install
          variants:
           - cloud
    
  6. Challenge

    Update the actions Section

    Remove any Ubuntu-specific commands from the actions section of the file:

    actions:
      - trigger: post-packages
        action: |-
          #!/bin/sh
          set -eux
    
          # Cleanup underlying /run
          mount -o bind / /mnt
          rm -rf /mnt/run/*
          umount /mnt
    
          # Cleanup temporary shadow paths
          rm /etc/*-
    
  7. Challenge

    Create the Image

    Use Distrobuilder to generate a packaged image:

    sudo distrobuilder build-lxd buster.yaml
    

    Add the image:

    sudo lxc image import lxd.tar.xz rootfs.squashfs --alias buster
    
  8. Challenge

    Test the Image

    Create a container based on the new image:

    sudo lxc launch buster buster
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans