#
Ubuntu extras
#
Shared folders
Say you want to use a shared folder in your host (or a drive, whatever works) the same way WSL2 works with your host drive. This can be achieved the same way by following these steps:
First, add your user to the vboxsf
group:
sudo usermod -aG vboxsf $USER
Reboot the VM.
Now create a shared folder and take note of the Folder Name value. We are going to need this to run this script to enable symlinks in the shared folder:
"%PROGRAMFILES%\Oracle\VirtualBox\VBoxManage.exe" setextradata WSL2 VBoxInternal2/SharedFoldersEnableSymlinksCreate/Z_DRIVE 1
Notes
Note that WSL2
is the name of the VirtualBox VM we created, and Z_DRIVE
is the Folder Name of the shared folder we set up. Sadly, this has to be done per VM per shared folder. The way WSL2 would do it, is to set all your drives up as shared folders and mount them in /mnt/z
(following this example of a Z:\
drive as shared folder).
#
Launch GUI apps
To have an X environment that just worksâ„¢, I recommend to install sddm
as the login manager as it allows for autologin, so once you fire up the VM it'll boot right into X ready for work. You also need a DE/WM. I recommend Openbox
because I'm used to it, it's lightweight and for development you don't really need a full-fledged desktop if you're just testing apps or just running a few. You could also run a full DE/WM this way, no need to juggle or mess with X servers and their slowness - VirtualBox does it all for you!
To follow the recommended method, just run this:
sudo apt install -y sddm
sudo apt install -y --no-install-recommends openbox python3-xdg xterm
Then edit /etc/sddm.conf
and add your username:
[Autologin]
User=user
Session=openbox
And that's it! Once your VM boots, it'll boot straight to X. The screen will be black, but your mouse cursor will show. Right-click anywhere to open a menu (that's how Openbox
works) and launch apps from there.
#
Debug GUI apps
If you want to use VSCode or other environments to debug apps right inside the VM (Without using X11 forwarding - which is what you can mostly find out on the net), just edit /etc/bash.bashrc
and add the following line at the end:
export DISPLAY=:0.0
Now you can reboot, and when you open VSCode and connect to the VM and launch a GUI app (say, your app launches Google Chrome, or runs xdotool
or something), it'll run inside the VM, YAY!
Note
If you want your apps to connect to a local X server (say, VcXsrv) just configure it to accept connections from any host and change the DISPLAY
variable above with the host's NAT IP. In VirtualBox, it's usually 10.0.2.2
, so it would be: DISPLAY=10.0.2.2:0
. Another option would be to skip editing /etc/bash.bashrc
altogether and use classic X11 forwarding instead through VSCode's Remote-SSH extension.
#
Final steps / Clean up
Run this to install some basic, useful utilities and clean up cache and free up some space:
sudo apt remove --purge multipath-tools
apps=(
bash-completion
dnsutils
net-tools
iputils-ping
htop
psmisc
)
sudo apt install -y "${apps[@]}"
sudo apt clean
sudo apt autoremove -y
sudo apt autoclean
sudo rm -rf /var/lib/apt/lists/*
Once done, shut down the VM and then use CloneVDI to clone the existing VDI, keeping the same UUID and compact while cloning. This will save up some space and you can end up with a 3.5 - 3.7 GB file once finished.
You're done!