Ubuntu Lightweight LXD VM

In this tutorial we revisit LXD Virtual machines by creating a LXD Ubuntu VM. We explore other LXD VM images in the LXD image repository. We discover that an Ubuntu LXD VM is very lightweight with the running image for Ubuntu 22.04 desktop requiring only 1GB of memory. The best part about LXD VM’s that you can create them very quickly since they are initiated from an image rather than having to do an installation as with a typical virtual machine.

As a review, you may also want to watch Ubuntu LXD Virtual Machine and also Ubuntu LXD VM Elevated where I discuss Ubuntu LXD virtual machines.

You can list the various LXD Images (both containers and VMs) on the LXD Repositiory.

lxc image list images: | more

To list just the LXD Virtual Machine images:

lxc image list images: | grep -i 'VIRTUAL' | more

We created an Ubuntu 22.04 Desktop LXD Virtual Machine.

lxc init images:ubuntu/22.04/desktop my-vm --vm --profile default --profile bridgeprofile -c limits.memory=4096MB -c limits.cpu=2 -c boot.autostart=true

We added sound support for the Spice Emulator for the LXD VM from my Intel host.

lxc config set my-vm raw.qemu -- "-device intel-hda -device hda-duplex"

We enlarged the size of the disk container for this virtual machine.

lxc config device override my-vm root size=50GiB

Finally, we boot up the LXD VM:

lxc start my-vm

We enter the Spice console emulator to get to the GUI.

lxc console my-vm --type=vga

Note that it logs into the “ubuntu” account at first. You should create another user account to perform the next steps and grant it sudo privilege.

sudo adduser scott
sudo usermod -aG sudo scott

You can log out of the ubuntu account and log into your new account.

The Ubuntu LXD VM has no browsers installed.
By default, Ubuntu installs Firefox as a Snap which is slow.

Here are the commands to install Firefox as an apt package instead of a snap.

If you have Firefox installed as a Snap.

sudo snap remove firefox

To install Firefox as a package, install the repository.

sudo add-apt-repository ppa:mozillateam/ppa

Change the package priority to favor the Mozilla apt package as opposed to the snap.

echo '
Package: *
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 1001
' | sudo tee /etc/apt/preferences.d/mozilla-firefox

Ensure that Firefox upgrades wlll take place through the Mozilla repository when there are new versions.

echo 'Unattended-Upgrade::Allowed-Origins:: "LP-PPA-mozillateam:${distro_codename}";' | sudo tee /etc/apt/apt.conf.d/51unattended-upgrades-firefox

Now you can install Firefox.

sudo apt install firefox

You can install the Brave Browser through the following commands:

sudo apt install apt-transport-https curl
sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg arch=amd64] https://brave-browser-apt-release.s3.brave.com/ stable main"|sudo tee /etc/apt/sources.list.d/brave-browser-release.list
sudo apt update
sudo apt install brave-browser
brave-browser --version

By default, the LXD VM will not install network manager which means that the Gnome settings GUI will not allow you to control the network settings from the GUI. To change this:

snap install network-manager network-manager 

Reboot the system after installing the Network Manager Snap and you should see that the Gnome settings can now control the network properly.

RDP is much easier and a better way to connect to your Ubuntu GUI desktop over the network as opposed to using VNC or Spice. To install and configure the RDP server on your Ubuntu desktop:

wget https://c-nergy.be/downloads/xRDP/xrdp-installer-1.4.zip
unzip xrdp-installer-1.4.zip
bash xrdp-installer-1.4.sh -s

The “-s” option in the script above adds support for sound over RDP. You will have to reboot the LXD Virtual Machine if you chose the sound option.

Sometimes, you may see that no sound devices show up despite the above. If this occurs, follow the steps in my video Ubuntu LXD VM Elevated.