Set up a Ubuntu based workstation | Step 3: VM Guest Installation and Configuration
This article is the third tutorial of a series on how to set up a multi-purpose Ubuntu based workstation. In the previous article, we have installed and configured KVM/QEMU on the host machine. In this article, we will install and configure a VM guest as the main development environment.
OS Installation
OS installation on the VM guest is similar to that on a physical machine, and the process is mostly self-explanatory. The differences are that:
- you need to create a virtual machine first
- you do NOT need to create a bootable USB flash drive, just use the downloaded ISO image directly.
In this article, we use *Virtual Machine Manager* (`virt-manager`) to create an Ubuntu 24.04 LTS VM guest.
Create a new VM guest
- Open *Virtual Machine Manager* and click on "File > New Virtual Machine" to start the VM creation wizard.
- Select "Local install media (ISO image or CDROM)" and click "Forward"
- Click "Browse" and select the downloaded Ubuntu 24.04 LTS ISO image (you may need to put the ISO in the default location `/var/lib/libvirt/images` in advance), then click "Forward".
- Allocate appropriate resources for the VM (e.g. 16 CPU cores, 32 GB RAM, 128 GB disk space), and click "Forward"
- Choose "Bridge Device" for network configuration
- Select "Customize configuration before install"
- In the customization window, click on "Overview" and change the firmware to "UEFI" instead of "BIOS", and click "Apply"
- In the customization window, click on "Video Virtio" and disable "3D Acceleration", and click "Apply"
- Click "Begin Installation" to start the OS installation process, which is the same as installing Ubuntu on a physical machine.
Install Ubuntu 24.04 LTS on the VM guest
Follow the on-screen instructions to complete the installation process. Note, since the VM is using vda storage, the disk will be named as `/dev/vda` instead of `/dev/sda` during the installation process, and you do not need LVM partitioning, just use the entire disk for installation. After the installation is complete, you can log in to the VM guest and perform basic settings.
Basic Settings
Set up SSH server
sudo apt install -y openssh-server sudo systemctl enable ssh sudo systemctl start ssh # one can check the status by # `sudo systemctl status ssh`
Configure SSH/GPG forwarding
@see: https://github.com/madpang/pd-imagine "Ticket 2" in tickets.txt
Install tmux
I personally prefer using `tmux` as the terminal multiplexer, and it is also very useful for remote development. Install `tmux` with the following command:
sudo apt install -y tmux
And here is a minimal `~/.tmux.conf` configuration file that I use:
# @brief: a tmux configuration for a better terminal experience # @details: copy this file to $HOME/.tmux.conf # @note: prevent tmux from creating new *log-in* sessions set -g default-command 'exec bash' # @note: this is equivalent to set the TERM environment variable # set -g default-terminal "tmux-256color" # set true color support # set -ga terminal-overrides ',*:Tc' # modify the escape key unbind C-b set-option -g prefix ` bind ` send-prefix # make tmux behaves more like screen unbind % bind | split-window -h unbind '"' bind - split-window -v unbind w bind '"' choose-window unbind x bind x confirm-before -p "kill-window #W? (y/n)" kill-window unbind & bind k confirm-before -p "kill-pane #P? (y/n)" kill-pane unbind , bind A command-prompt -I "#W" "rename-window '%%'" # set Emacs mode set-option -g mode-keys emacs # set status bar set -g status-position top set -g status-style bg="#009193",fg="#D6D6D6" # set larger history set-option -g history-limit 8192
Extra Notes
Disable Wayland
Although Wayland is the current rising star in the Linux desktop world, X11 is still the preferred choice for a computing workstation, especially for working with OpenCV and Nvidia drivers. To disable Wayland, edit the GDM configuration file `/etc/gdm3/custom.conf` and uncomment the relevant line:
# GDM configuration storage # # See /usr/share/gdm/gdm.schemas for a list of available options. [daemon] WaylandEnable=false # ...
Install Nvidia driver
To use the Nvidia GPU in the VM guest for development, you first need to attach the GPU to the VM—you can use *Virtual Machine Manager*:
- Click on "View > Details" in the VM's window
- Go to "Add Hardware" > "PCI Host Device"
- Select the GPU (both VGA and audio devices) from the list
- Start the VM, and install the appropriate GPU drivers inside the VM for optimal performance
Enable RDP
Remote Desktop Protocol (RDP) is a valuable supplementary to SSH for remote access, allowing you to access the VM's graphical desktop environment remotely.
Ubuntu 24.04 LTS has built-in support for RDP, and it is by default accessed at port 3389. To enable RDP, go to "Settings > System > Remote Desktop > Remote Login", turn on the switch, and set the login user name and password (note, the password you set here is for RDP connection, and it is different from the session login password). Then, you can use any RDP client (e.g. Microsoft Remote Desktop) to connect to the VM guest using its IP address.
After you connect to the VM guest through RDP, you can disable the *screen-off* in "Settings > Power" by setting "Power Saving > Screen Blank" to "Never".
See [1].
Setup Avahi
With `avahi-daemon` installed and running, you can access the VM guest using its hostname (e.g. `pd-vm-u24.local`) instead of its IP address, which is more convenient. One a *Desktop* Ubuntu installation, `avahi-daemon` is usually installed and enabled by default. But for a *Server* installation, you need to install and enable it manually:
sudo apt install -y avahi-daemon sudo systemctl enable avahi-daemon sudo systemctl start avahi-daemon
Create a snapshot of the clean installation
After the installation is complete, it is recommended to create a snapshot of the clean installation state, so that you can easily revert to this state if needed in the future. Use the following command to create a snapshot:
virsh snapshot-create-as --domain <vm-name> --name "snapshot1" --description "Clean installation"
Replace `<vm_name>` with the name of your VM guest (e.g. `pd-vm-u24`). You can list all snapshots of a VM with the following command:
virsh snapshot-list <vm_name>
And you can revert to a snapshot with the following command:
virsh snapshot-revert <vm_name> snapshot1
Reference
- [Install and configure xrdp to use Remote Desktop with Ubuntu](https://docs.azure.cn/en-us/virtual-machines/linux/use-remote-desktop?tabs=azure-cli)