How to list VM images in LXD (Linux Containers)

I am using LXD (“Linux Container”) a container “hypervisor” on Ubuntu Linux serer. How do I list all available VM images for installation in the LXD image store? Is it possible to list lxd images using lxc command line?

lxd is a system-wide daemon and lxd is a command line client to talk with the lxd daemon. So, you need to use the lxc command to list images in the LXD store. This page shows how to list VM images in LXD using the lxc.

ADVERTISEMENTS

How to list VM images in LXD

The syntax is:
lxc image list images:
Sample outputs:

Fig.01: Listing all VM images

Fig.01: Listing all VM images

You can use the grep command or more command as follows:
lxc image list images: | more
lxc image list images: | grep -i 'debian'
lxc image list images: | grep -i 'opensuse'

Sample outputs:
Fig.02: Using the grep command to filter out images

Fig.02: Using the grep command to filter out images

You can apply filter as follows to just show alpine Linux vm images:
lxc image list images: 'alpine'
lxc image list images: 'opensuse'

Fig.03: Using filters

Fig.03: Using filters

You can now create a VM as follows:
lxc launch images:alpine/3.8/amd64 alpine-www
lxc launch images:centos/7/amd64 cenots-db
lxc launch images:opensuse/15.0/amd64 opensuse-15
lxc list

How do I get a list of Linux distros?

Run the following combination of grep command/egrep command, awk command and sed command:

lxc image list images: |\
awk -F'|' '{ print $2}' |\
sed '/^[[:space:]]*$/d' |\
awk -F'/' '{ print $1"/"$2 }' | sort | uniq | egrep -v 'more|ALIAS'

Sample outputs:

 alpine/3.10
 alpine/3.7
 alpine/3.8
 alpine/3.9
 alpine/edge
 alt/Sisyphus
 alt/p8
 alt/p9
 apertis/17.12
 apertis/18.03
 apertis/18.06
 apertis/18.09
 apertis/18.12
 centos/6
 centos/7
 centos/8
 debian/10
 debian/8
 debian/9
 debian/bullseye
 debian/sid
 devuan/ascii
 fedora/29
 fedora/30
 fedora/31
 funtoo/1.3
 gentoo/cloud
 kali/cloud
 mint/sarah
 mint/serena
 mint/sonya
 mint/sylvia
 mint/tara
 mint/tessa
 mint/tina
 opensuse/15.0
 opensuse/15.1
 opensuse/tumbleweed
 oracle/6
 oracle/7
 oracle/8
 plamo/6.x
 ubuntu-core/16
 ubuntu/14.04
 ubuntu/16.04
 ubuntu/18.04
 ubuntu/18.10
 ubuntu/disco
 ubuntu/eoan
 ubuntu/focal
 voidlinux/musl

Getting help on image option

Type the following command:
lxc image help
Sample outputs:

Description:
  Manage images
 
  In LXD containers are created from images. Those images were themselves
  either generated from an existing container or downloaded from an image
  server.
 
  When using remote images, LXD will automatically cache images for you
  and remove them upon expiration.
 
  The image unique identifier is the hash (sha-256) of its representation
  as a compressed tarball (or for split images, the concatenation of the
  metadata and rootfs tarballs).
 
  Images can be referenced by their full hash, shortest unique partial
  hash or alias name (if one is set).
 
Usage:
  lxc image [command]
 
Available Commands:
  alias       Manage image aliases
  copy        Copy images between servers
  delete      Delete images
  edit        Edit image properties
  export      Export and download images
  import      Import images into the image store
  info        Show useful information about images
  list        List images
  refresh     Refresh images
  show        Show image properties
 
Global Flags:
      --debug            Show all debug messages
      --force-local      Force using the local unix socket
  -h, --help             Print help
      --project string   Override the source project
  -q, --quiet            Don't show progress information
  -v, --verbose          Show all information messages
      --version          Print version number
 
Use "lxc image [command] --help" for more information about a command.

See lxd documents here for more info.

This entry is 4 of 19 in the LXD Tutorial series. Keep reading the rest of the series:
  1. Install LXD container hypervisor on Ubuntu 16.04 LTS
  2. How to install and setup LXC (Linux Container) on Fedora Linux 26
  3. Set up LXD container under KVM or Xen virtual machine
  4. List VM images in LXD (Linux Containers)
  5. Upgrade LXD containers powered by Ubuntu/Debian or CentOS Linux
  6. Auto start LXD containers at boot time in Linux
  7. Command to rename LXD / LXC container
  8. Run commands on Linux Container (LXD) instance at provision launch time
  9. Use LXD (Linux containers) in a shell script to create VM when the cloud instance launches
  10. Move/migrate LXD VM to another host on Linux
  11. Fedora install and set up LXD
  12. CentOS 7.x install and set up LXD server
  13. Install LXD pure-container hypervisor on Ubuntu 18.04 LTS
  14. Create snapshots with lxc command for LXD
  15. Set up and install LXD on CentOS/RHEL 8
  16. Ubuntu 20.04 LTS install and set up LXD
  17. Full backup and restore LXD containers
  18. Disable firewall and NAT rules on the LXD bridge
  19. Delete or remove LXD container using the lxc

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
2 comments… add one
  • Casper May 28, 2017 @ 16:49

    I’m running lxc on a Centos7, and have for sometime now been trying to find a way to get ‘lxc’ – does anyone know where I can find the source.

    • 🐧 Vivek Gite May 28, 2017 @ 17:15

      I am sorry, but your question is not clear to me. Can you be more specific?

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.