Skip to content

Linux boot

System Run Level

  • 7 run levels

  • Run level 0: Shut down (or halt the system)

  • Run level 1: Single-user mode; usually aliased as s or S
  • Run level 2: Multiuser mode without networking
  • Run level 3: Multiuser mode with networking (without GUI)
  • Run level 4: Currently undefined
  • Run level 5: Multiuser mode with networking (with GUI)
  • Run level 6: Reboot the system

  • 0, 1 and 6 are the main run levels

# Tells the current run level of the session
who -r # Usually 5 (networking with gui)
# Set default run level (5 by default)
systemctl set-default "new-target"
  • Default target stored at /etc/systemd/system/default.target

Linux Boot Process

  1. BIOS: Basic Input/Output Setting
  2. It's a firmware interface
  3. System integrity checks
  4. Find out how to boot
  5. POST process: Power-On Self-Test started
  6. MBR: Master Boot Record executes GRUB
  7. Located in the first sector of the disk
  8. Bytes in size (small)
  9. Calls the GRUB2, so it can be loaded in the computer RAM
  10. GRU2B: Grand Unified Bootloader x2
  11. Load the linux kernel
  12. Config file: /boot/grub2/grub.cfg
  13. Kernel: Core of the Operating System
  14. Load required drivers from initrd.img
  15. Mounts the root filesystem
  16. Start the first OS process (systemd)
  17. Systemd: System Daemon (PID #1)
  18. Start all the other required processes
  19. Reads /etc/systemd/system/default.target to bring the system to run-level

Message of the day

  • Located at /etc/motd
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
  • Customize the message of the day
  • Create a new file for the scripts in /etc/profile.d/motd.sh
#!/bin/bash

echo -e "
Welcome to `hostname`
This system is runing `cat /etc/debian_version`
Kernel is `uname -r`
You are logged in as `whoami`
"
  • Modify the /etc/ssh/sshd_config to edit PrintMotd
PrintMotd no
# Restart sshd service
systemctl restart sshd

Recover root password

  1. Restart PC
  2. On grub, highlight the linux system and press e to edit it
  3. Replace the ro (read only) with rw init=/sysroot/bin/sh
  4. Ctrl + X (The computer will restart in single user mode)
  5. Type chroot /sysroot (mount the filesystem to /sysroot)
  6. Type passwd root
  7. Type touch /.autorelabel
  8. Type exit && reboot