Overview
This Tutorial is on how to build a custom LXC template with a desktop environment and audio working in xrdp. This method can be used to build custom templates with or without GUI desktop. Building custom template will take less than 30 minutes, mostly for downloading new software.
Go to section:
Introduction
Installing apps and tools
Installing GUI desktop Environment
Fixing the sound output
Creating LXC template
Conclusion
References
Introduction
Creating custom templates with your favorite software and settings will save you time when deploying new containers because you don’t have to keep changing, updating and installing the same software on each new container. In the example below, after installing the desktop environment the template size was 690M.
I hope this tutorial will be useful to those that like to use graphics GUI desktop and don’t have time or hardware resource to install VMs. I spent a lot of time researching and reading other peoples posts over the internet, unfortunately, i didn’t find a clear direction, how to use LXC desktop at least to my level of understanding. See the reference section for sites that were helpful in developing this tutorial .
The only remaining problem i have is getting to sound output to work in the container after each restart. Right now i have to reset the pulseaudio in the container every time i reboot/start the container. Maybe a custom Corn job to automate this audio output restart. if someone has a better way of getting the sound to work please let me know.
Installing apps and tools
- create a container, give it 4G of storage, 2 cores, 2048 RAM, specify the IP (ex: 192.168.1.20/24), Gateway (ex: 192.168.1.1). This settings are just temporary.
- once you start the new LXC container. Log in as root and edit source list by adding the following sources:
nano /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu focal partner
deb-src http://archive.canonical.com/ubuntu focal partner
- install Firefox browser or any software you like to have in your templates (for example terminator, openssh-server…)
sudo apt-get install firefox -y
sudo apt-get install terminator -y
Installing GUI desktop Environment
- install the desktop environment: during the install you will see a pop-up screen asking which desktop you want : select lighdm.
sudo apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils
since we want to access the container through remote RDP, install XRDP
sudo apt install xrdp
- Verify xrdp installed correctly and is running:
sudo systemctl status xrdp
- once RDP is installed we need to add this code, so that desktop manager know what to use for display:
update-alternatives --set x-session-manager /usr/bin/xfce4-session
- if you wanted to use ubuntu Mate desktop environment use the following:
sudo apt install lightdm ubuntu-mate-core ubuntu-mate-desktop -y
sudo update-alternatives --set x-session-manager /usr/bin/mate-session
Fixing the sound output
First get latest download link of the script “xrd-installer-1.2” from this website:
cd /opt
wget http://c-nergy.be/downloads/xRDP/xrdp-installer-1.2.zip
unzip xrdp*
chmod +x xrdp-installer-1.2.sh
- create a new user if you don’t already have one:
adduser admin
usermod -aG sudo admin
su admin
./xrdp-installer-1.2.sh -s
- reboot container.
reboot
- After rebooting the container, you may still have a Dummy output in the Volume control and no sound output. To fix the issue restart pulseaudio server in the container by running the following command:
pulseaudio -k
After pulseaudio is restarted, the sound should start to work with xrdp sink appearing in the volume control.
Creating LXC template
- crate a backup of the new created LXC as as GZIP. first, turn off the LXC container and then do the backup from Proxmox GUI.
Pve-> select container_<i.d> —> Backup now—> compression select GZIP (good)
- once the backup is completed. Go the Shell of Proxmox: copy the new file created to the folder where Proxmox saves templates and give it a new name. Template and Backup folders depend on original Proxmox setup. in my case for example:
/Template/folder: /zfs-pool/zfs-iso-template/template/cache
/Backup/folder/file: /zfs-pool/zfs-backups/dump/vzdump-lxc-<i.d>.tar.gz
cp /backup/folder/file-<i.d>.tar.gz /template/folder/new-name.tar.gz
- That’s it! Now when you go to create a new container, you will have the new template with your custom settings preinstalled.
Conclusion
LXC uses less resources and is a good alternative to VMs for those that are primarily testing in Linux and don’t have many cores to spare. Hopefully, this tutorial will make you more efficient and save your time for more-important testing.
References:
https://github.com/neutrinolabs/xrdp
https://linuxize.com/post/how-to-install-xrdp-on-ubuntu-18-04/
https://github.com/bmullan/ciab-remote-desktop/blob/master/mk-cn1-environment.sh
https://linuxconfig.org/8-best-ubuntu-desktop-environments-18-04-bionic-beaver-linux
http://c-nergy.be/blog/?p=14888
https://www.closingtags.com/custom-lxc-container-templates-in-proxmox-5-0/
Comments
Post a Comment