Logo

* Most of the material is taken from this online course.

Linux systems store their important files according to a standard layout called the Filesystem Hierarchy Standard (FHS). The original source documents can be found here.

The Boot Process


When an x86-based GNU/Linux system is powered on, the Basic Input/Output System (BIOS) initializes the hardware, including the screen and keyboard, and tests the main memory. This process is also called POST (Power On Self Test). The BIOS software is stored on a ROM chip on the motherboard. After this, the remainder of the boot process is completely controlled by the operating system. Once the POST is completed, the system control passes from the BIOS to the boot loader.

The boot loader is usually stored on one of the hard disks in the system, either in the boot sector (for traditional BIOS/MBR systems) or the EFI partition (for more recent (Unified) Extensible Firmware Interface or EFI/UEFI systems). Up to this stage, the machine does not access any mass storage media. Thereafter, information on the date, time, and the most important peripherals are loaded from the CMOS values. For systems using the BIOS/MBR method, the boot loader resides at the first sector of the hard disk also known as the Master Boot Record (MBR). The size of the MBR is just 512 bytes. In this stage, the boot loader examines the partition table and finds a bootable partition. Once it finds a bootable partition, it then searches for the second stage boot loader e.g, GRUB or ISOLINUX, and loads it into RAM.
For systems using the EFI/UEFI method, UEFI firmware reads its Boot Manager data to determine which UEFI application is to be launched and from where (i.e., from which disk and partition the EFI partition can be found). The firmware then launches the UEFI application, for example GRUB, as defined in the boot entry in the firmware's boot manager.
The second stage boot loader resides under /boot. A screen is displayed which allows us to choose which OS to boot. After choosing the OS, the boot loader loads the kernel of the selected OS (and an initial RAM–based file system (initramfs) which contains some critical files and device drivers needed to start the system) into RAM and passes control to it.

Kernels are almost always compressed, so its first job is to uncompress itself. After this, it will check and analyze the system hardware and initialize any hardware device drivers built into the kernel. It immediately initializes and configures the computer’s memory and also configures all the hardware attached to the system. This includes all processors, I/O subsystems, storage devices, etc. The kernel also loads some necessary user space applications.

The initramfs filesystem image contains programs and binary files that perform all actions needed to mount the proper root filesystem, like providing kernel functionality for the needed filesystem. After the root filesystem has been found, it is checked for errors and mounted.

The mount program instructs the operating system that a filesystem is ready for use, and associates it with a particular point in the overall hierarchy of the filesystem (the mount point). If this is successful, the initramfs is cleared from RAM and the init program on the root filesystem (/sbin/init) is executed.

init handles the mounting and pivoting over to the final real root filesystem. Besides starting the system, init is responsible for keeping the system running and for shutting it down cleanly. It acts as the "manager of last resort" for all non-kernel processes, cleaning up after them when necessary, and restarts user login services as needed when users log in and out. Most processes on the system trace their origin ultimately to init; the exceptions are kernel processes, started by the kernel directly for managing internal operating system details.

Near the end of the boot process, init starts a number of text-mode login prompts (done by a program called getty). These enable you to type your username, followed by your password, and to eventually get a command shell. Usually, the default command shell is bash (the GNU Bourne Again Shell).

After the login most distributions start six text terminals and one graphics terminal. These are called virtual terminals (VT) because although there can be multiple active terminals, only one terminal remains visible at a time. If the graphical environment is also started, switching to a text console requires pressing CTRL+ALT+ the appropriate function key, otherwise CTRL is not needed. Ubuntu uses VT 7, but CentOS/RHEL and openSUSE use VT 1 for the graphical display. You may need to run the startx command in order to start or restart your graphical desktop after you have been in pure text mode.

Package Management Systems

There are two broad families of package managers: those based on Debian and those which use RPM as their low-level package manager. Both package management systems provide two tool levels: a low-level tool (such as dpkg or rpm), takes care of the details of unpacking individual packages, running scripts, getting the software installed correctly, while a high-level tool (such as apt, yum, or zypper) works with groups of packages, downloads packages from the vendor, and figures out dependencies.
The Advanced Packaging Tool (apt) is the underlying package management system that manages software on Debian-based systems. Yellowdog Updater Modified (yum) is an open-source command-line package-management utility for the Fedora family. yum has both command line and graphical user interfaces. zypper is a package management system for openSUSE that is based on RPM. zypper also allows you to manage repositories from the command line. zypper resembles yum quite closely. The basic packaging commands can be found here

Profile


The original Bourne shell ran two profile files whenever a user logged on. First, a file called /etc/profile was the general profile file executed for all users. Second, if a file named .profile appeared in the user’s home directory, this contained additional commands for each user. Bash mimics this behavior when it is started as sh instead of bash.
Bash extended the principle to run several profile files depending on the circumstances. In addition, Linux distributions often customize the general profile files to run additional commands stored in other scripts.

Bash differentiates between a login session and other instances. Bash runs as a login shell when a user or program first logs in or when a login is simulated with Bash’s --login (or -l) switch. A login shell is not necessarily one that presents a user with a prompt. It only indicates that Bash is the top program in the current session, and when Bash completes its run, the login session will be over. The login_shell shell option is turned on when you are in a login shell. This option can be used to verify that you are in a login shell.
$ shopt login_shell
login_shell on

Bash runs as an interactive shell when it is started without a script or when the -i switch is used. An interactive shell presents the user with a command prompt.
The /etc/profile file contains the setup commands and environment changes common to all users. Only the superuser can edit this file.
When Bash is used as a login shell, /etc/profile is executed and then it executes the first file it finds named ~/.bash_profile, ~/.bash_login, or ~/.profile. When a session completes, Bash runs ~/.bash_logout, if it exists.
Running a new Bash non-login interactive session will not run the profile file:
$ bash
$ logout
bash: logout: not login shell: use ‘exit’

Scripts will not normally execute the login profile scripts. Bash will load a profile for scripts if the BASH_ENV environment variable contains a pathname to a file to execute. However, you should avoid using BASH_ENV. Setting the common environment for a set of scripts is usually done with the source command. BASH_ENV has no effect on interactive sessions.
You can stop the running of the login profile files by using the --noprofile switch.

Bash runs a different set of files for non-login interactive sessions. Bash looks for a customization script called ~/.bashrc and executes it instead of the login profile files. Aliased functions are only allowed in the resource files. A different resource file can be specified with the --init-file or --rcfile switch.
rc files can be suppressed with the --norc switch.

Some distributions add lines to the login profile to run the commands in ~/.bashrc as well. This is not a feature of Bash, but a change made by Linux distribution.

Environment Variables


Environment variables are simply named quantities that have specific values and are understood by the command shell, such as bash. Some of these are pre-set (built-in) by the system, and others are set by the user either at the command line or within startup and other scripts.

Commands set, env, or export show the values of currently set environment variables (set is more detailed).

By default, variables created within a script are only available to the current shell; child processes (sub-shells) will not have access to values that have been set or modified. Allowing child processes to see the values, requires use of the export command.
$export VARIABLE=value (or $VARIABLE=value; export VARIABLE)
To add a variable permanently add export VARIABLE=value to ~/.bashrc.

PATH is an ordered list of directories (the path) which is scanned to find the appropriate program or script to run. Each directory in the path is separated by colons (:). A null (empty) directory name (or ./) indicates the current directory.
To prefix the directory ~/MyDir to your path:
$ export PATH=$HOME/MyDir:$PATH  (HOME is an environment variable that represents the home (or login) directory of the user)

Prompt Statement (PS) is used to customize your prompt string in your terminal windows to display the information you want.
PS1 is the primary prompt variable which controls what your command line prompt looks like. Special characters can be included in PS1. For example
\u - User name
\h - Host name
\w - Current working directory  (\$PWD shows the full path for the home instead of ~)
They must be surrounded in quotes: export PS1='\$PWD: '  (declare -x does the same thing as export)

The environment variable SHELL points to the user's default command shell.

Text Editors


gedit is part of the GNOME desktop system and kwrite is associated with KDE (kedit and kate are also supported by KDE).
Nano is an easy-to-use text-based editor that utilizes on-screen prompts.
vi (also vim for "improved vi") and emacs are available on all Linux systems. Graphical interfaces for vi are gvim (GNOME) and kvim (KDE).

vi has three modes: Command, Insert, and Line. By default, vi starts in Command mode.
Type i to switch to Insert mode from Command mode. Press Esc to return to Command mode.
Type : to switch to the Line mode from Command mode. Press Esc to return to Command mode.
Type :x or :wq to exit vi and write out modified file.
Type :q! to quit vi even though modifications have not been saved.

emacs has only one but requires use of special keys such as Control and Escape.

Misc.


- The "init" process is responsible for implementing both restarts and shut downs. On systems using System V init, run level 0 is usually used for shutting down, and run level 6 is used to reboot the system.