After days of struggling, i finally succeeded to make everything work on a LXD VM using any Linux ISO. That’s why i would like to help people doing it easily.
So far i tried just with Ubuntu 22.04.4 and Kde Neon.
Follow the next steps:
Create an empty VM :
lxc init VM-name --empty --vm -c limits.cpu=4 -c limits.memory=4GiB
If you are working on a LXD cluster, don’t forget to add the option “–target=node_name”
The command will look like this:
lxc init VM-name --empty --vm -c limits.cpu=4 -c limits.memory=4GiB --target node_name
Give the VM a 30 GB storage ( this is an important step cause otherwise you will face problems during the boot of ISO complaining about writing problems ):
lxc config device override VM-name root size=30GB
Make the sound work on the VM:
lxc config set VM-name raw.qemu -- "-device intel-hda -device hda-duplex"
Mount the ISO ( priority=2 is important to avoid problems during the boot ):
lxc config device add VM-name custom-device-name disk source=/home/user/pathtoiso/isoname.iso boot.priority=2
Start the machine in console mode ( don’t forget to install remote-viewer package if you didn’t before ):
lxc start VM-name --console=vga
You should now be prompted to the console and the live image should start without any problem.
Once the system is installed, remove the ISO device:
lxc config device remove VM-name custom-device-name
Stop the guest VM (better use the --force option ):
lxc stop VM-name --force
Start the VM from vga console:
lxc start VM-name --console=vga
Well, now the funny part comes, cause internet will probably not work on the guest VM because of DNS problems.
sudo nano /etc/resolv.conf
Add “nameserver 22.214.171.124” just before the others lines written by systemd resolved and save the file.
Refresh sources using
sudo apt update command and install resolvconf with
sudo apt install resolvconf.
Edit resolvconf using the command
sudo nano /etc/resolvconf/resolv.conf.d/tail and add
nameserver 126.96.36.199 to the file. Save the file.
Stop and disable systemd resolved with the commands
sudo systemctl stop systemd-resolved and
sudo systemctl disable systemd-resolved.
Remove /etc/resolv.conf with the command
sudo rm -rf /etc/resolv.conf.
Make a link to resolvconf tail file with the command
sudo ln -s /etc/resolvconf/resolv.conf.d/tail /etc/resolv.conf.
Restart resolvconf with the command
sudo service resolvconf restart
Enable the LXD agent on the VM guest:
This is an important step, otherwise the host can not communicate with the guest and “lxc push” command or “lxc exec” will not work.
To do that, just install the package on the guest VM with the command
apt install lxd-agent-loader.
Restart the VM guest machine.
Now internet should work fine and communication between host and guest should work but you will face another funny problem. Any application can communicate with internet but not the web browser.
This happens on the default browser on Ubuntu and Kde Neon. It’s a kind of mistery for me.
Anyway, there’s an easy fix: download the deb package of a web browser and push the file to the guest VM.
In my case i used Opera but i tried with Google Chrome too and everything was working.
Push the deb package from the host to the guest with this command:
lxc file push /path/to/the/deb/package VM-name/home/user
Install the package on the guest and open the browser you have just installed.
Everything should work now.
That’s all. You can then export and publish the image of the VM to install it easily as any LXD image. But this is another story.
Thank you for reading.