# Main Index: Debian Linux Magic Spells Cheat Sheet (one liners, how to, tips and tricks)
# Linux System Boot
Booting into Linux
- When you turn on a computer, the first code to be executed is the boot firmware which is tipically the UEFI (Unified Extensible Firmware Interface, since 2010), which replaced the BIOS (Basic Input-Output System, since 1981).
GNU GRUB boot loader (GNU GRand Unified Bootloader, since 1995) replaced LILO boot loader (LInux LOader, from 1992 to November 22, 2015).
GRUB if expected, loads initrd.img (an image of an Initial Run Disk, which contains the drivers needed to accept keyboard commands, display output on the screen, and mount the partition of the operating system you intend to load). In some cases, GRUB may already contain a minimum of sufficient drivers for startup.
The boot loader starts the Kernel, which acts as an interface to the software to access the hardware. It is possible to have multiple versions of the Kernel. The Kernel filename follows the format vmlinux-VERSION-PLATFORM (for example, vmlinuz-5.10.0-16-amd64), which is associated with the corresponding initrd.img (for example, initrd.img-5.10.0-15-amd64 but it could also be an initramfs.img such as initramfs-5.10.0-15-amd64.img )
The Kernel can load additional drivers through external files (kernel objects, kernel modules) which are usually found in the /lib/modules/KERNEL_VERSION / directory (and can be further nested, for example: /lib/modules/5.10 .0-17-amd64/kernel/drivers/video/backlight/ ) and have the extension .ko (Kernel Object). Some distributions use these files in a compressed format and therefore the extension is .ko.xz
The Kernel starts the initialization process (Init System). Init System launches all the services needed by the system. Being launched from the Kernel, it is the very first process to start on any Linux distribution, and it starts with root privileges.
Init can start different processes depending on the required level of execution (runlevel). For example, some runlevels may not start network services so that the machine will not be accessible remotely in case of on-site maintenance.
There are various Init Systems, the most popular is systemd, developed by RedHat (but also used by other distributions, such as Debian). There are others like Upstart or OpenRC. To see which process was launched first (ie which Init System) from the Kernel, you can use the command cat /proc/1/comm , or ps -A | awk -F' ' '$1 == "1"' that shows the process with PID No. 1)
If the system has a graphical interface, the Display Manager (Login Manager) is started. There are many different types of Display Manager, such as GDM (GNOME Display Manager), KDM (KDE Display Manager), LightDM (Light Display Manager), LXDM (LXDE Display Manager), SDDM (Simple Desktop Display Manager).
User access to the system is managed by the PAM (Pluggable Authentication Modules) which verifies whether the user has the necessary privileges to access the system and can provide other verification systems in addition to passwords (for example biometric systems).
The files with the rules are contained in the /etc/pam.d/ directory
The Desktop Environment is then launched. There are many different Desktop Environment, some of the most popular are GNOME (released on March 3, 1999), KDE (released on October 14, 1996), Xfce (released in 1996), LXDE (released in 2006), Razor-qt (released in 2010, retired on January 12, 2013), LXQt (released in 2013), Unity (released in 2010, retired on March 2015).
To find out which desktop environment is in use, you can read the dedicated environmental variable: echo $DESKTOP_SESSION (if you are in a textual environment, the variable will not be set)
The desktop environment relies on a Display Server (Window Manager) which acts as an interface between the applications and the graphic functions of the system. There are various display servers that use different communication protocols. The most popular protocol is X Windows (designed by MIT in 1984, also known by the most recent version number, X11 of September 1987) and the main display managers using this protocol are X.Org (releaesd on April 6, 2004), XFree86 (released in 1991), XQuartz (released in 2002, for Mac), Cygwin/X (released on March 7, 2013, for Windows). Other communication protocols for Display Server relatively popular on Linux are: Wayland (released on September 30, 2008, and which may replace X11, Display Servers for Wayland: Weston, Mutter, KWin, Enlightenment), Mir (for the Mir Display Server, released in 2013 and used on Ubuntu until 2017).
In the textual environment the Display Server is generally TTY (which stands for "Teletypewriter"). You can know the virtual display in use reading the dedicated environmental variable: echo $XDG_SESSION_TYPE
- BIOS loads the boot loader from the MBR (Master Boot Record) disk sector of the book disk.
- UEFI uses the partition table according to the GPT standard (GPT stands for GUID Partition Table, whereas GUID means Globally Unique IDentifier). For backward compatibility the first partition of the disk (LBA 0) starts with an MBR. This prevents old applications that only recognize MBR from overwriting the disk believing it to be empty. UEFI allows you to choose a boot loaders in .efi format from the EFI partition (which is a FAT32 partition with +boot and +esp flags).
You may use efibootmgr to clean up the EFI partition by removing boot loaders left over from old installations:
efibootmgr -v # Show all present boot loaders (BootCurrent indicates the current boot, Timeout the time after which the default boot is loaded, BootOrder is the order of priority of the boot loaders)
How to delete a boot loader:
efibootmgr -b BOOT_ID -B # BOOT_ID is the identifier of the boot loader, for example 0002, 000C. This will only delete the entry from the boot manager, not the boot loader file.
ls /boot/efi/EFI # show the folders that contain the .efi files
to delete the directory of an operating system that has already been removed:
rm -rf /boot/efi/EFI/DIRECTORY
Boot Loader Configuration File
See GNU GRUB configuration:
/boot/grub/grub.cfg replaces /boot/grub/menu.lst and it's not meant to be edited. In distros other than Debian the path could be /boot/grub/grub.conf or /etc/grub.conf
Edit LILO configuration:
Kernel version currently in use:
List Kernel images present in the system:
dpkg --list | egrep -i --color 'linux-image|linux-headers'
Counts Kernel images present in the system:
dpkg --list | egrep -i 'linux-image|linux-headers' | wc -l
List Kernels installed on the system:
dpkg --list | grep -i -E 'linux-image|linux-kernel' | grep '^ii'
Count Kernels installed in the system:
dpkg --list | grep -i -E 'linux-image|linux-kernel' | grep '^ii' | wc -l
Remove old versions of the Kernel:
apt-get --purge autoremove
runlevel # Show current runlevel
who -r | sed 's/^ *//g' # Show current runlevel and when it started
ls -d /etc/rc*.d # List directories containing corresponding runlevel scripts in distributions using System V style
ls /etc/rc.d/rc.* # List runlevel scripts in distributions using BSD style
You can check if and which Display Manager is present on the system by checking whether is present a symbolic link to the display manager file
ls -l /etc/systemd/system/display-manager.service
If the file is missing ("No such file or directory") there is no display manager (on the system there is therefore only the textual interface), otherwise the linked file is shown.
Or, you can read the file default-display-manager:
To change Display Manager, deactivate the current one and activate the new one (which must have been previously installed):
systemctl disable OLD_DISPLAY_MANAGER # For example systemctl disable sddm
systemctl enable NEW_DISPLAY_MANAGER # For example systemctl enable kdm (provided it has already been installed)
You can also use the following command, but it will open a box where you have to confirm your choice and press Enter.
dpkg-reconfigure DISPLAY_MANAGER # choose the DISPLAY_MANAGER you want to set in your system, for example: dpkg-reconfigure kdm
System users are stored in the /etc/passwd file and their passwords (shadowed) in /etc/shadow . Debian makes regular backups in /var/backups/passwd.bak and /var/backups/shadow.bak
Display Server (Window Manager)
update-alternatives --list x-window-manager # List Display Servers (Window Managers) installed on the system
echo $XDG_SESSION_TYPE # Show the Display Server currently in use.
echo $DESKTOP_SESSION shows the path and the name of the file (without the .desktop extension) containing information about the Desktop Environment to be started.
ls /usr/share/applications/ shows all launcher files for applications (which will appear in the desktop environment start menu). The files have a .desktop extension. A .desktop file contains the parameters to launch the application from the menu. The path and name of the file to be launched are indicated in the Exec parameter within the .desktop file. Application icons are placed in the section (or sections) of the menu specified under Categories.
Please DONATE to support the development of Free and Open Source Software (PayPal, Credit Card, Bitcoin, Ether)
Page issued on 25-Sep-2022 04:36 GMT