LXD is a great hypervisor to manage system containers, and pretty much anything you can use a virtual machine for you can use a system container instead. However, LXD is also able to manage virtual machines, and has been able to do so for more than a year now.
While virtual machines have been a part of LXD for quite a while, using them has been a bit challenging. Much of that has since been sorted out, and using virtual machines under LXD is now as easy to do as using system containers.
This page is pretty much my 'cheat sheet' for LXD virtual machines, where I can keep information and notes for future reference.
$ lxc launch images:ubuntu/focal --vm u2004v
$ lxc launch images:ubuntu/focal --vm u2004v --console
$ lxc launch images:ubuntu/focal --vm u2004v --console=vga
$ lxd exec u2004v bash
$ lxc launch images:ubuntu/focal --vm --profile bridged u2004v
$ lxc launch images:ubuntu/focal --vm -c limits.cpu=2 -c limits.memory=4GiB u2004v
$ lxc console u2004v
$ lxc console u2004v --type=vga
$ lxc init --vm --empty -c limits.cpu=2 -c limits.memory=4GiB -c security.secureboot=false u2004v
$ lxc config device override u2004v root size=20GiB
$ lxc config device add u2004v iso disk source=/files.lan/ISOs/ubuntu-20.04-legacy-server-amd64.iso boot.priority=10
$ lxc start u2004v --console=vga
- perform the vm installation, as per normal
- after the install, when prompted to remove cd;
$ lxc stop -f u2004v
$ lxc config device remove u2004v iso
$ lxc start u2004v
Ref: https://discuss.linuxcontainers.org/t/cannot-change-vm-root-disk-size/8727/5
$ lxc init --vm images:ubuntu/focal u2004v
$ lxc config device override u2004v root size=20GiB
# growpart /dev/sda 2
# resize2fs /dev/sda2
lxc config device add u2004v eth1 nic name=eth1 nictype=bridged parent=lxdbr0
$ lxc storage volume create default u2004v-sdb size=100GiB --type=block
$ lxc config device add u2004v u2004v-sdb disk pool=default source=u2004v-sdb
Please note that the new disk won't be deleted if you delete the VM. In this case you need to delete the disk manually after deletion of the VM.
$ lxc storage volume delete default u2004v-sdb
....................
(created: 2021-09-26, last modified: 2022-01-25 at 09:16:02)