Post

Booting the System in Linux

Booting the System in Linux

Here’s a detailed overview of Booting the System in Linux, covering all the topics you’ve listed:


🔧 1. BIOS Boot Sequence

  • BIOS (Basic Input/Output System):

    • Initializes hardware (CPU, RAM, keyboard, disk, etc.)
    • Looks for a bootable device (like HDD, SSD, USB)
    • Loads the first sector (MBR or GPT) into memory
    • Passes control to the bootloader (GRUB/LILO)

🚀 2. Linux Boot Events Overview

  • Boot Process Stages:

    1. BIOS/UEFI initializes hardware
    2. Bootloader (e.g., GRUB) loads the kernel
    3. Kernel initializes hardware and mounts root filesystem
    4. init/systemd runs as PID 1 and starts user-space services
  • Important Utilities:

    • dmesg – Displays kernel ring buffer messages (hardware detection, drivers, errors)

      1
      
      dmesg | less
      
    • journalctl -k – Shows kernel messages (systemd)
    • lsinitrd or lsinitramfs – Lists content of initramfs/initrd (temporary root before real rootfs)
    • cat /proc/cmdline – View current kernel boot options

💻 3. Common Commands to the Boot Loader (GRUB)

At the GRUB menu:

  • Press e to edit boot entry
  • You can modify:

    • Kernel path
    • Initrd path
    • Kernel parameters

Common GRUB commands:

  • set root=(hd0,1) – Sets the root partition
  • linux /vmlinuz root=/dev/sda1 ro – Loads kernel
  • initrd /initrd.img – Loads initramfs
  • boot – Boots with the current setup

⚙️ 4. Kernel Options at Boot Time

Kernel boot parameters affect system behavior:

  • Examples:

    • single or 1 – Boots into single-user mode
    • init=/bin/bash – Skips init system and gives a root shell
    • nomodeset – Disables kernel mode setting (graphics)
    • quiet – Reduces boot messages
    • root=/dev/sda1 – Specifies root filesystem

To apply:

  1. At GRUB menu, press e
  2. Append options to the linux line
  3. Press Ctrl + X or F10 to boot

🔄 5. Init Systems: SysVinit, SystemD, Upstart

FeatureSysVinitUpstartSystemD (modern default)
PID 1 process/sbin/init/sbin/init/lib/systemd/systemd
Init files/etc/init.d/*/etc/init/*.confUnit files in /etc/systemd/system/
ParallelNoYesYes
Active distroLegacy (Debian, Slackware)Older Ubuntu (9.10–14.10)Most modern distros (Ubuntu, Arch, RHEL)

🔁 6. Changing Runlevels / Targets / Single User Mode

SysVinit (legacy)

  • Runlevels:

    • 0: Halt
    • 1: Single user
    • 3: Multi-user
    • 5: Multi-user + GUI
    • 6: Reboot
  • Commands:

    1
    2
    3
    
    init 1     # Switch to single-user mode
    runlevel   # Shows previous and current runlevel
    telinit 3  # Switch to runlevel 3
    

SystemD (modern)

  • Targets:

    • rescue.target – Single-user mode
    • multi-user.target – Non-GUI
    • graphical.target – GUI
  • Commands:

    1
    2
    3
    
    systemctl isolate rescue.target     # Switch to single-user
    systemctl get-default               # Show default target
    systemctl set-default graphical.target
    

🔚 7. Reboot & Shutdown (with User Alerts)

Commands:

1
2
3
4
5
shutdown -r now           # Reboot immediately
shutdown -h +10 "System will shut down in 10 minutes."  # Graceful halt with warning
halt                      # Immediate halt
poweroff                  # Turn off the system
reboot                    # Reboot the system

Alerting Logged-in Users:

  • wall sends messages to all terminals:

    1
    
    wall "System will reboot in 5 minutes. Please save your work."
    
  • shutdown does this automatically when scheduled:

    1
    
    shutdown -r +5 "System rebooting for maintenance."
    

This post is licensed under CC BY 4.0 by the author.