Skip to main content

Linux

This page provides introduction to linux.

Overview

Linux is an open-source, Unix-like operating system kernel that serves as the foundation for various operating systems, powering servers, desktops, mobile devices, and embedded systems.

Linux Internals

Below section talks about some of the linux internals:

Linux Kernel

The kernel is part of the linux operating system that has control over everything. It provides access to hardware by using kernel modules(drivers). It also provides basic services to all other parts of the operating system.

Root User

  • The user with UID 00 has all capabilities.
  • In /etc/passwd, UID 00 is assigned to the root user.
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
... # output is trimmed
  • Even after removing /etc/passwd, the system UID 00 still exists and there are no limitations for this UID.

Drivers

  • Harware support is offered by drivers.
  • In Linux drivers are presented as kernel modules and loaded on demand in most cases.
  • Most device nodes are represented by files in /dev, which present a user space interface to drivers.

Devices

  • Many devices only send bytes to peripheral on the computer, or receive byte from the peripheral, such devices work like pipes and for that reason works well as chacter devices.
  • Other devices works more like file i.e. writing to a location and then reading from same location, such devices are represented by block devices.
  • Network devices are more complex as they work with packets, instead of streams of bytes. These devices are controlled by ioctl() system call.
  • Video adapator also don't have device nodes; kernels writes directly to memory of the video adapter as this is fast.

Glibc

  • Glibc is GNU C library.
  • You will find it as dependency for all the program files on Linux.
ldd $(which ls)
# o/p:
# linux-vdso.so.1 (0x00007ffced7b8000)
# libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f0329208000)

# this is GNU C dependency
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0328ff6000)

# libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f0328f5c000)
# /lib64/ld-linux-x86-64.so.2 (0x00007f032925e000)
  • It works on all the common hardware platforms.

Shell

  • Bash is standard shell on linux
  • Shell intereprets commands that the user types and passes them to operating system.

File Descriptors

  • In Linux, everything is a file, that means linux communication happens through files.
  • File descriptors are numbers used by process processes to keep a list of open files.
  • All processes have at least 33 file descriptors:
    • 00: STDIN, refers to the standard input device.
    • 11: STDOUT, refers to the standard output device.
    • 22: STDERR, refers to standard error devices.

Linux Boot Procedure

Below diagram show the linux boot procedure:

linux-1.svg

Firmware

  • Basic Input Output System(BIOS) is legacy way of booting.
  • Unified Extensible Firmware Interface(UEFI) was introduced in late 20002000.
  • A main advantage of UEFI is capable of booting from disk bigger than 22TB with GUID Partition Table(GPT).
  • UEFI can be configured with secure boot which can prevent loading an operating system that is not signed with known digital signature.

Bootloader

  • Through the firmware, the bootloader is activated.
  • Purpose of the bootloader is to load the Linux Kernel and related initramfs.
  • GRUB22 is common bootloader on linux.
  • Uboot is used on embedded linux.

Initramfs

  • To keep the kernel file small, on installation an initramfs(AKA initrd) that contains all essential kernel module is generated.
  • initramfs is also responsible for loading root filesystem.

Service Managers

  • The service manager takes care of loading everything after the kernel and initrd have been loaded, and the root system has been mounted.
  • It initializes remaining hardware devices, mounts filesystem and starts services.
  • systemd is most common service manager used on all the leading linux distribution.
  • Minimized linux distribution don't use systemd.

Early Boot Shell

  • Use systemd.unit=emergency.target or systemd.unit=rescue.target as a GRUB kernel startup parameter to enter systemd troubleshooting mode.
  • Use rd.break or init=/bin/bash as GRUB kernel startup parameter to enter a troubleshooting environment before systemd is started.
  • Enable debug-shell.service and access through /dev/tty9 while booting.

Booting Cloud Linux Instances

  • When used in cloud, cloud based boot loaders are standards.
  • There is no BIOS/UEFI in the cloud, and it's the cloud that provides the kernel from boot image.
  • Also, no GRUB22 is involved.