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 SRun level 2
: Multiuser mode without networkingRun level 3
: Multiuser mode with networking (without GUI)Run level 4
: Currently undefinedRun 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
- BIOS: Basic Input/Output Setting
- It's a
firmware
interface System integrity
checks- Find out how to boot
POST
process: Power-On Self-Test started- MBR: Master Boot Record executes GRUB
- Located in the
first sector
of the disk - Bytes in size (small)
- Calls the GRUB2, so it can be loaded in the computer RAM
- GRU2B: Grand Unified Bootloader x2
- Load the linux kernel
- Config file:
/boot/grub2/grub.cfg
- Kernel: Core of the Operating System
- Load required drivers from
initrd.img
- Mounts the root filesystem
- Start the first OS process (
systemd
) - Systemd: System Daemon (PID #1)
- Start all the other required processes
- 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 editPrintMotd
PrintMotd no
# Restart sshd service
systemctl restart sshd
Recover root password
- Restart PC
- On grub, highlight the linux system and press
e
to edit it - Replace the
ro
(read only) withrw init=/sysroot/bin/sh
- Ctrl + X (The computer will restart in single user mode)
- Type
chroot /sysroot
(mount the filesystem to /sysroot) - Type
passwd root
- Type
touch /.autorelabel
- Type
exit && reboot