Linux

Linux is a free and open source Operating System (OS). It is the dominating OS on servers nowadays.

Origin

In 1970s, the Bell labs developed an OS named Unix, and it led to a standardization called Portable Operating System Interface (POSIX) to ensure compatibility among different systems.

In 1987, an OS named Minix was developed based on Unix and gained popularity in the academic field. However, the redistribution of its code was restricted. This motivated a Finnish software developer, Linus Torvalds, to developed his own OS kernel in C, Linux, in 1991.

Linux was advertised as a free and open source software under the GNU General Public License (GPL) 2.0 license. It was free to distribute, modify, and make money out of it.

Distribution

A Linux distribution is a complete operating system built on the Linux kernel and each distribution has its own highly opinionated set of default software. Here are some famous distributions.

Bootup

The Linux kernel acts as a bridge between hardware and software. When we press the power button of a Linux machine:

File system

Linux's ext4 file system follows the Filesystem Hierarchy Standard (FHS) 3 specification and has the following structure:

Storage devices in file system

File permissions

Rings

Linux uses rings to administrate operation privileges.

GNU and shell

In 1983, Richard Stallman started the GNU project to provide binaries that make the kernel useful.

Frequently-used Bash commands

Ubuntu

Dual boot

Assume we have a computer already installed with Windows, then we can install Ubuntu along side it. Below are the steps of installation.

  1. Make a bootable USB drive.

    1. Download the latest LTS Ubuntu Desktop ISO image from the official website.
    2. Use software like Rufus to write the ISO image to an USB drive.
  2. Create a disk partition.

    1. Use Windows built-in software disk management to create an unallocated partition.
  3. Reboot from the USB drive and install Ubuntu.

    1. Restart the computer and select the USB drive for booting. Follow the prompted instructions to install the system.
    2. After the installation, reboot the computer.
    3. During the installation process, I connected it to the Internet and updated the installer when asked. I did not install any other third party software.
  4. Reconfigure boot order.

    1. When booting up the computer, if we enter the GRUB rescue terminal instead of the GRUB boot menu (which lets us select between Ubuntu and Windows), this means the Unified Extensible Firmware Interface (UEFI)/BIOS has found the GRUB bootloader, but:
      • The grub.cfg (typically /boot/grub/grub.cfg in the Ubuntu partition) was not found.
      • The Ubuntu partition was not found probably because it was moved, or not mounted properly, or not installed completely.
    2. Let's quickly recap what happens when we boot up the computer.
      1. We press the power button.
      2. The UEFI/BIOS initializes the hardware.
      3. The UEFI/BIOS loads the first bootloader in the boot order (typically the GRUB bootloader at /boot/efi/EFI/ubuntu/grubx64.efi in the Ubuntu partition).
      4. The GRUB bootloader prompts the user with the GRUB menu containing the Ubuntu and Windows boot option.
      5. The user selects a boot option and it loads the OS kernel and starts system processes.
    3. Now we can see that the first bootloader loaded is probably not the one we want.
    4. A temporary fix we can do in the rescue terminal right away is to look for the Ubuntu partition and use it for current booting.
      ls (hd0,gpt1)/boot/grub # Iterate over every (hdx,gpty) until we find an existing (hdx,gpty)/boot/grub directory. Let's say (hd1,gpt4)/boot/grub is our target directory.
      set root=(hd1,gpt4)
      set prefix=(hd1,gpt4)/boot/grub
      insmod normal # insmod = insert module
      normal
      
    5. A permanent fix is to reboot the computer, pressing the UEFI/BIOS key (F2 in Acer and Dell, F10 in HP) and rearrange the bootloader order to prioritize the one located in the Ubuntu partition.
  5. Fix secondary display white screen issue.

    1. After logging into the system, if we find the secondary display shows a white screen, it's probably because we lack the Nvidia driver. We can fix it by installing the driver.
      ubuntu-drivers devices # List recommended drivers.
      sudo apt install nvidia-driver-550
      sudo reboot # Reboot to apply the changes.
      

Package manager

Ubuntu's maintainer, Canonical, has created its own package manager called Snap to live besides the Debian's APT. Below is a comparison.

FeatureAPTSnap
SourceDebian reposSnapcraft store
Format.deb.snap
SizeSmallLarge
Install methodapt installsnap install
Install location/usr/snap (mounted via loop devices)
IsolationNo (shared system libs)Yes (sandboxed with own libs)
Dependency conflictProbableNo
SecurityCommunityCanonical
SpeedFast install & launchSlower install & launch (due to sandboxing)
DebugEasyHard
CustomizeEasyHard
Latest versionNoYes
Auto updatesNoYes (in background)

To sum up, use APT unless we need sandboxing, auto-updates, or the latest version of a software.

Set up development environment

Here are the steps I take to set up my development environment.

  1. Install Google Chrome.
    sudo apt install ./google-chrome-stable_current_amd64.deb
    
  2. Install LibreOffice.
    sudo apt install libreoffice
    
  3. Install Visual Studio Code.
    sudo apt install ./code_x.x.x_amd64.deb
    
  4. Install cURL.
    sudo apt install curl
    
  5. Install Rust.
    curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
    
  6. Install Git and configure identity and SSH keys.
    sudo apt install git
    git config –global user.email <EMAIL>
    ssh-keygen -t ed25519 -C “<COMMENT>”
    eval “$(ssh-agent -s)”
    ssh-add ~/.ssh/id_ed25519
    
  7. Install Zola.
    • Compile from source
      git clone git@github.com:getzola/zola.git
      cd zola
      cargo install –path . –locked
      
    • Or use snap package manager
      snap install --edge zola
      
  8. Install Docker.
    sudo apt install docker.io
    
  9. Install FFmpeg.
    sudo apt install ffmpeg
    
  10. Install MuseScore3.
    sudo apt install musescore3
    
  11. Install nvidia-container-toolkit.
    curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
    && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
        sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
        sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
    
    sudo apt update
    sudo apt install -y nvidia-container-toolkit
    sudo systemctl restart docker
    sudo docker run --rm --gpus all nvidia/cuda:12.2.0-base-ubuntu22.04 nvidia-smi # Verify nvidia-container-toolkit installation.
    
  12. Install python3.12-venv.
    sudo apt install python3.12-venv`
    

See also

←Previous Next→