What are LXD Virtual Machines?

In several of my tutorials I cover LXD containers and their associated networking options. In the last video entitled “LXD Containers 101” I showed how to create a LXD container and bridge it to the main LAN.

Sometimes LXD containers lack the ability to access certain features of the OS such as specific usage of cgroups or control of systemctl. Also, a LXD container shares the kernel of the host OS. If you need a feature that is not in the kernel or requires a low level feature, sometimes VMs are the only alternative.

LXD VMs are virtual machines which use images from the LXD container library and have all the advantages of using profiles from the “lxc cli”. LXD VMs are a great alternative to creating a VM in VirtualBox or QEMU. LXD VMs use the Linux Kernel Virtual Machine (KVM) features found in QEMU with the advantages of a leaner VM creation and configuration process.

From the last video, we launched a LXD Container on the main LAN using a bridge:

lxc launch ubuntu:20.04 test --profile default --profile bridgeprofile -c boot.autostart=true

In this video we created a LXD VM first with a cloud init file on the LXD internal network:

lxc init ubuntu:18.04 vm-test --vm
(
cat << EOF
#cloud-config
apt_mirror: http://us.archive.ubuntu.com/ubuntu/
ssh_pwauth: yes
users:
  - name: ubuntu
    passwd: "\$6\$s.wXDkoGmU5md\$d.vxMQSvtcs1I7wUG4SLgUhmarY7BR.5lusJq1D9U9EnHK2LJx18x90ipsg0g3Jcomfp0EoGAZYfgvT22qGFl/"
    lock_passwd: false
    groups: lxd
    shell: /bin/bash
    sudo: ALL=(ALL) NOPASSWD:ALL
EOF
) | lxc config set vm-test user.user-data -
lxc config device add vm-test config disk source=cloud-init:config
lxc start vm-test

This approach had the advantage of providing an ubuntu username with the ubuntu password, allowing that password to be changed, adding the account to the LXD group so that the LXD VM can even nest its own LXD within it, and allowing sudo access without a password from the Ubuntu account for initial configuration.

We also learned the command to access the console and watch the vm boot up:

lxc console vm-test

To exit the console, you do a CTRL-A q

Then, I demonstrated that the cloud-init file no longer seems to be a requirement with Ubuntu LXD VM’s by creating another LXD VM:

lxc launch ubuntu:20.04 vm-test2 --profile default --profile bridgeprofile -c boot.autostart=true --vm

This LXD VM is bridged to the MAIN LAN and uses the host Ethernet device via the bridge we created in “LXD Containers 101”.