How do I preload images onto LXD?

Hello!

I’m trying to see if I could pre-download some images for LXD before it would be used, to speed up the launching of bootstrapping processes like juju.

I’ve tried looking into the documentation but I couldn’t quite find a cli reference to do so (or I couldn’t figure out the command to get it working).

I’ve tried:

  • lxc image import juju/ubuntu@22.04/amd64 ubuntu
  • lxc image import https://images.linuxcontainers.org/images/ubuntu/jammy/amd64/cloud/20240718_07%3A42/meta.tar.xz https://images.linuxcontainers.org/images/ubuntu/jammy/amd64/cloud/20240718_07%3A42/rootfs.tar.xz

and a few more commands based on my interpretation of the documentation.

  1. May I know what the correct command to fetch the images might be?
  2. Would there be a way to import the images beforehand without going through the CLI/LXD launch? (as in can I pre-fetch the images in chroot environment by downloading the tarballs from source?)
1 Like

Hi, you can download any image from the server into LXD on a specific remote using lxc image copy command.

Copy container image:

lxc image copy images:alpine/edge local:

Copy VM image:

lxc image copy images:alpine/edge local: --vm

The image copy command also supports copying images into specific project, managing aliases etc.

lxc image copy --help

Docs: https://documentation.ubuntu.com/lxd/en/latest/howto/images_copy/#copy-an-image-from-a-remote

Just to clarify the difference between the image import and image copy.
The image import command is used for importing the local image from metadata tarball and rootfs / raw disk. For example, when an image is created using lxd-imagebuilder.
The image copy command is used for copying images between servers.

2 Likes

Also just as an aside images.linuxcontainers.org is no longer affiliated with the LXD project and the server is no longer accessible for LXD users.

1 Like

I’ve just tried it and it works :tada: , thank you!

As of being able to pre-download the images into the chroot environment, would it be something that’d be possible? I’m asking since the image has to be uploaded to the database for it to work. Also, I’ve done a snapshot testing of lxc bootstrapped with Juju, launching a VM with the snapshot image (raw) with network changes. The juju controller remains bootstrapped as expected.

If I copy over the files from snap directories, would this be able to be picked up by the snap/lxd daemon when I boot the image?

Another thing I’ve noticed is that the Juju ubuntu image juju/ubuntu@22.04/amd64 (fingerprint 82b997ec581b) differs to ubuntu:22.04.

Output of juju/ubuntu@22.04

lxc image show  82b997ec581b
auto_update: false
properties:
  architecture: amd64
  description: ubuntu 22.04 LTS amd64 (release) (20240701)
  label: release
  os: ubuntu
  release: jammy
  serial: "20240701"
  type: squashfs
  version: "22.04"
public: false
expires_at: 2027-06-01T00:00:00Z
profiles:
- default

Output of ubuntu:22.04

lxc image show a9585abb92b2
auto_update: true
properties:
  architecture: amd64
  description: ubuntu 22.04 LTS amd64 (release) (20240716)
  label: release
  os: ubuntu
  release: jammy
  serial: "20240716"
  type: disk-kvm.img
  version: "22.04"
public: false
expires_at: 2027-06-01T00:00:00Z
profiles:
- default

I’ve tried different combinations of the properties, e.g. lxc image copy ubuntu:22.04-squashfs, lxc image copy ubuntu:22.04-20240716-squashfs, lxc image copy ubuntu:22.04-server-cloudimg-amd64.squashfs.

Would you know if I could target the one Juju downloads without defining the fingerprint?

The first fingerprint (82b997ec581b) is for a container image released on 2024.07.01.
The second one ( a9585abb92b2) is for a virtual machine released on 2024.07.16.

When referencing images by alias, LXD will download the latest version (those released on 2024.07.16 in this case). To get an older version of a specific image, a fingerprint needs to be provided.

lxc image copy ubuntu:22.04 local: → Latest container image released on 2024.07.16 with fingerprint e728500de9fa (in time of writing)

lxc image copy ubuntu:82b997ec581b local: → Container image released on 2024.07.01 with fingerprint 82b997ec581b

3 Likes

lxc image copy ubuntu:jammy local: --copy-aliases will copy the aliases too, which is useful.

4 Likes