Setting Up Ubuntu
Introduction
This post is where I keep notes on configurations for Ubuntu (GNOME) and some applications for personal reference.
Controlling the boot process
The grub file controls the behavior of the GRand Unified Bootloader, which is a flexible and powerful boot loader program. The full path to the file is /etc/default/grub; use the following command to edit the file:
sudo nano /etc/default/grubThere are two settings that may be of particular interest:
GRUB_DEFAULT=0: choose Ubuntu as the default operating system.GRUB_TIMEOUT=5: boot the default system in five seconds if no keyboard input is performed during this time.
Remember to run the following command after changing the settings to update the /boot/grub/grub.cfg file:
sudo update-grubDealing with a dual-boot system time conflict
When Linux and Windows constitute a dual-boot system, there will be an issue concerning system time. The solution is to use the following command to tell Ubuntu that the hardware clock is set to ‘local’ time:
sudo timedatectl set-local-rtc 1 --adjust-system-clockNote that invoking timedatectl set-local-rtc 1 will also synchronize the RTC (i.e., real-time clock, which stores hardware time) from the system clock (which stores system time), unless --adjust-system-clock is passed.
The following command can be used to update system time, but note that the program is no longer installed on Ubuntu by default (install it with sudo apt install ntpsec-ntpdate).
sudo ntpdate pool.ntp.orgEnvironment variables
Set LANGUAGE=en to ensure various messages (e.g., man pages and help info for commands) are shown in English:
echo "export LANGUAGE=en" >> ~/.profileAuto mount a partition on boot
Use the lsblk command to find out the UUID of a partition; example:
lsblk -o NAME,SIZE,FSTYPE,LABEL,UUID,MOUNTPOINT
# NAME SIZE FSTYPE LABEL UUID MOUNTPOINT
# sdb 447.1G ntfs data 32FBCAAA07932A36
# └─sdb1 447.1G ntfs newvol D0BE3DB6BE3D95C7 Use the id command to find out user and group IDs; example:
id
# userid=1000(username) groupid=1000(username) group=1000(username)Edit the /etc/fstab file to auto mount a partition (e.g., to /data) on boot. Note that you should specify the UUID of a partition, not that of a disk. In the given example, it should be D0BE3DB6BE3D95C7 (sdb1), not 32FBCAAA07932A36 (sdb). An example entry could be:
UUID="D0BE3DB6BE3D95C7" /data ntfs uid=1000,gid=1000,umask=0077
Optionally create a swap file (if swap file or patition is not configured) and auto mount:
sudo swapon --show # check first
sudo fallocate -l 4G /swapfile # 1-2x the size of RAM
sudo chmod 600 /swapfile # only root can read/write
sudo mkswap /swapfile # format
sudo swapon /swapfile # Enable
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab # auto mount
sudo reboot
sudo swapon --show # verifyInput method
Install fcitx5-rime and make it autostart on boot:
sudo apt install fcitx5-rime
sudo cp /usr/share/applications/org.fcitx.Fcitx5.desktop /etc/xdg/autostart/ # system-wide, or user-specific: ~/.config/autostartInstall and configure a GNOME shell extension (GNOME does not support Wayland’s input-method protocol, which is required by fcitx5’s Wayland frontend):
sudo apt install gnome-shell-extension-manager
extension-manager # search for "Input Method Panel" (which is based on KDE's kimpanel protocol) then install
sudo tee -a /etc/environment <<'EOF'
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
EOFInstall rime-ice:
mv ~/.local/share/fcitx5/rime ~/.local/share/fcitx5/rime.orig # remove and backup
mkdir -p ~/.local/share/fcitx5/rime
curl -L -o /tmp/full.zip https://github.com/iDvel/rime-ice/releases/latest/download/full.zip # or: https://mirror.nju.edu.cn/github-release/iDvel/rime-ice/LatestRelease/full.zip
unzip /tmp/full.zip -d ~/.local/share/fcitx5/rime/
rime_deployer --build ~/.local/share/fcitx5/rimeConfigure rime-ice:
cat > ~/.local/share/fcitx5/rime/default.custom.yaml <<'EOF'
patch:
menu/page_size: 9
# release left and right brackets from existing shortcuts
key_binder/select_first_character: ""
key_binder/select_last_character: ""
# add left and right brackets as new shortcuts
key_binder/bindings/+:
- { when: has_menu, accept: bracketleft, send: Page_Up }
- { when: has_menu, accept: bracketright, send: Page_Down }
EOFThen right-click the input method tray icon, and click “Reload Configuration”.
Applications
To install some frequently used applications:
sudo apt update
sudo apt install curl aria2 filezilla \
ffmpeg imagemagick gimp vlc obs-studio kdenlive inkscape \
git gh meld \
sqlite3 postgresql-client mysql-client \
podman \
keepassxc \
tree netstat \
virtualbox virtualbox-ext-pack
mkdir -p ~/.local/bin/
curl -L -o ~/.local/bin/yt-dlp https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp && chmod u+x ~/.local/bin/yt-dlpMore detailed installation/setup guides for some other software are listed below:
- Git
- Proxy
- R:
- Python
- Go
- TypeScript
- Zotero
- VirtualBox - VPN
- Thunderbird - accounts
- Firefox - bookmarks
File templates
Save the following templates to ~/Templates/ (in English locale) or ~/模板/ (in Chinese locale):
Cron jobs
Save the following scripts to ~/.local/bin/ and make them executable (chmod u+x ~/.local/bin/*):
Use crontab -e to add the following entries:
# move expired files/directories from /data/tmp/ to trash
0 */2 * * * ${HOME}/.local/bin/cleanup.py --expiration-time 1209600 directory --directory /data/tmp/ >> ${HOME}/cleanup.log 2>&1
# delete expired files/directories from trash
0 */2 * * * export XDG_RUNTIME_DIR=/run/user/$(id -u); ${HOME}/.local/bin/cleanup.py --expiration-time 2419200 trash >> ${HOME}/cleanup.log 2>&1Note that by default, crons job are executed with a very limited set of environment variables. Therefore, it is necessary to declare variables (either right before the command, or at the top of crontab file) before executing a command that requires them. Also note that cron sees the percentage sign (i.e., %) as a special character, and therefore it should be escaped with a leading backslash (i.e., \%) when included in a command.
Disable tray icon blinking
To disable tray icon (in the top bar) blinking, open /usr/share/gnome-shell/extensions/[email protected]/appIndicator.js and change MAX_UPDATE_FREQUENCY to a large value (e.g., 86400000).
Appendix: VirtualBox configurations
The following error may occur with a fresh installation of VirtualBox on Ubuntu:
VirtualBox can't operate in VMX root mode. Please disable the KVM kernel extension, recompile your kernel and reboot (VERR_VMX_IN_VMX_ROOT_MODE).
The reason is that recent versions of Ubuntu load KVM by default, and it conflicts with VirtualBox. The solution is to just disable KVM temporarily (until next reboot):
# for intel cpu
sudo modprobe -r kvm_intel
# for amd cpu
sudo modprobe -r kvm_amdOr disable it permanently by adding a line in /etc/modprobe.d/blacklist.conf:
# for intel cpu
blacklist kvm_intel
# for amd cpu
blacklist kvm_amd
Appendix: Create a bootable USB drive with Ventoy
Follow these steps:
- Download the installation package, like ventoy-x.x.xx-linux.tar.gz ( link ) and decompress it.
- Insert a USB drive, then run
lsblk -pand find out the whole disk device path (e.g.,/dev/sda) (not the partition device path, e.g.,/dev/sda1). - Run
sudo bash Ventoy2Disk.sh { -i | -I | -u } /dev/XXXto install, force install, or update Ventoy on the USB drive. Note that the USB drive will be formatted and all the data will be lost after install or force install. - Copy iso files to the USB drive.