Linux Boot Sequence
BIOS/UEFI โ bootloader (GRUB2) โ kernel loads โ initramfs โ systemd (PID 1) โ targets โ login. Every stage has specific config files and failure modes. Understanding this sequence is essential for troubleshooting boot issues.
Filesystem Hierarchy Standard (FHS)
/ (root), /boot (kernel/GRUB), /etc (config), /var (variable data/logs), /home (user dirs), /usr (user binaries), /tmp (temp, cleared on reboot), /proc and /sys (virtual kernel interfaces), /dev (device files), /mnt and /media (mount points).
Linux Kernel Architectures
x86_64 (most servers/desktops), ARM (embedded/Raspberry Pi/cloud), aarch64 (ARM 64-bit). Kernel manages hardware abstraction, memory, processes, filesystems. Modules extend kernel functionality without recompiling.
Virtualization Role
Linux hosts virtual machines via KVM (Kernel-based Virtual Machine) + QEMU. libvirt/virsh provide management. Understanding VMs, disk images (qcow2, raw), and hypervisor types (Type 1 bare-metal, Type 2 hosted) is explicitly tested in XK0-006.
BIOS/UEFI
POST (Power-On Self Test) โ finds bootable device. BIOS uses MBR (Master Boot Record, first 512 bytes). UEFI uses GPT (GUID Partition Table), supports Secure Boot, stored in /boot/efi.
GRUB2 Bootloader
Loads from MBR or EFI partition. Config: /etc/default/grub (user-editable) + /boot/grub2/grub.cfg (generated โ do NOT edit directly). Regenerate with grub2-mkconfig -o /boot/grub2/grub.cfg. GRUB menu allows kernel selection, recovery mode, single-user mode.
Kernel + initramfs
GRUB loads kernel (vmlinuz) and initial ramdisk (initramfs/initrd) into memory. initramfs mounts a temporary root filesystem with drivers needed to mount the real root. Kernel decompresses and takes over hardware.
systemd (PID 1)
First process after kernel. Reads unit files from /etc/systemd/system/ and /lib/systemd/system/. Brings system to a target (replaces SysV runlevels).
Systemd Targets
poweroff.target (0), rescue.target (1/single-user), multi-user.target (3/multi-user no GUI), graphical.target (5/GUI), reboot.target (6). Check: systemctl get-default. Change: systemctl set-default multi-user.target
Login
getty launches login prompt. PAM authenticates user. Shell starts (bash, zsh, etc.)
Kernel Modules
Loadable kernel extensions for drivers and functionality. Commands: lsmod (list loaded modules), modprobe module_name (load with dependencies), modprobe -r module_name (remove), modinfo module_name (show info). Persistent loads: /etc/modules-load.d/*.conf
Hardware Discovery Tools
lspci โ list PCI devices (network cards, GPUs). lsusb โ list USB devices. lshw โ detailed hardware info. dmidecode โ BIOS/SMBIOS info (RAM, CPU, board). lscpu โ CPU architecture info. dmesg โ kernel ring buffer (hardware events, driver messages).
Device Files
/dev/sda (first SATA/SCSI disk), /dev/sdb (second), /dev/nvme0n1 (NVMe), /dev/vda (virtual disk in KVM). Partitions: /dev/sda1, /dev/sda2. Block devices (b) vs character devices (c) in ls -l /dev/
| Scenario | Action |
|---|---|
| Edit kernel params once | At GRUB menu โ press e โ edit linux line โ Ctrl+X to boot |
| GRUB rescue prompt | set root=(hd0,1) โ set prefix=/boot/grub2 โ insmod normal โ normal |
| Rebuild grub.cfg | grub2-mkconfig -o /boot/grub2/grub.cfg |
| Reset forgotten root password | Boot to rescue/emergency target โ passwd root โ touch /.autorelabel (SELinux) |
| Single-user mode | Add single or 1 to kernel line in GRUB |
Partitioning Tools
fdisk โ MBR partitions (interactive, supports up to 4 primary or 3+extended). gdisk โ GPT partitions (needed for >2TB disks or UEFI). parted โ supports both MBR and GPT, scriptable. After partitioning: partprobe to inform kernel, then mkfs.ext4 /dev/sda1 to format.
Filesystem Types
ext4 (default Linux, journaled, stable, max 16TB), xfs (high performance, default RHEL, good for large files), btrfs (copy-on-write, snapshots, built-in RAID), swap (virtual memory extension). Format: mkfs.ext4, mkfs.xfs, mkswap. Enable swap: swapon /dev/sda2
| Component | Command | Description |
|---|---|---|
| Physical Volume | pvcreate /dev/sdb | Initialize disk/partition for LVM |
| Volume Group | vgcreate vg_data /dev/sdb | Pool of physical volumes |
| Logical Volume | lvcreate -L 20G -n lv_data vg_data | Virtual partition from VG |
| Format | mkfs.ext4 /dev/vg_data/lv_data | Create filesystem on LV |
| Extend LV | lvextend -L +10G /dev/vg_data/lv_data then resize2fs | Grow logical volume online |
| Display | pvs, vgs, lvs | Show PV/VG/LV info |
| RAID | Min Disks | Redundancy | Performance | Notes |
|---|---|---|---|---|
| RAID 0 | 2 | None | Best read/write | Striping โ any disk failure = total loss |
| RAID 1 | 2 | 1 disk can fail | Read faster | Mirroring โ 50% capacity |
| RAID 5 | 3 | 1 disk can fail | Good | Striping + parity โ (n-1) capacity |
| RAID 6 | 4 | 2 disks can fail | Moderate | Double parity โ (n-2) capacity |
| RAID 10 | 4 | 1 per mirror pair | Excellent | Stripe of mirrors |
mount Command
mount /dev/sda1 /mnt โ temporarily mount. mount -t ext4 /dev/sda1 /mnt โ specify type. umount /mnt โ unmount. mount -a โ mount all in /etc/fstab. Check mounts: mount, df -h, lsblk
/etc/fstab
Persistent mount configuration. Format: DEVICE MOUNTPOINT FSTYPE OPTIONS DUMP PASS. Use UUID (not device name) for reliability: UUID=abc123 /data ext4 defaults 0 2. Options: defaults, ro (read-only), noexec, nosuid, nofail (boot even if mount fails).
ip Command Suite
Replaces ifconfig/route/netstat. ip addr show โ show IP addresses. ip addr add 192.168.1.10/24 dev eth0 โ add IP. ip link set eth0 up/down โ enable/disable interface. ip route show โ routing table. ip route add default via 192.168.1.1 โ add default gateway. ip neigh โ ARP table.
NetworkManager & nmcli
nmcli device status โ show all devices. nmcli connection show โ list connections. nmcli connection up CONNECTION_NAME โ activate. nmcli con mod CONNECTION_NAME ipv4.addresses 192.168.1.10/24 โ modify IP. Config files: /etc/NetworkManager/system-connections/
DNS Configuration
/etc/resolv.conf โ nameserver entries (often managed by NetworkManager/systemd-resolved). /etc/hosts โ local hostname resolution (checked first). dig domain.com โ DNS lookup with details. nslookup domain.com โ simple DNS lookup. host domain.com โ quick lookup. /etc/nsswitch.conf controls resolution order (files โ dns).
Navigation & File Operations
pwd (print working dir), ls -la (long list + hidden), cd - (previous dir), find /path -name "*.log" (find files), locate filename (indexed search), which command (find binary), type command (built-in or external). Wildcards: * (any chars), ? (one char), [abc] (character class).
Redirection & Pipes
> redirect stdout (overwrite), >> append, 2> redirect stderr, 2>&1 merge stderr into stdout, &> both to file, /dev/null (discard). | pipe stdout to next command. tee split to file + stdout. Examples: ls 2>/dev/null, command > out.txt 2>&1
Environment Variables
export VAR=value โ set for current session + child processes. echo $VAR โ display. env โ show all. unset VAR โ remove. Persistent: add to ~/.bashrc (user) or /etc/environment (system). Key vars: PATH, HOME, USER, SHELL, PS1 (prompt), LANG.
Text Processing
grep -r "pattern" /path (recursive), grep -i (case-insensitive), awk '{print $1}' (field extraction), sed 's/old/new/g' (substitute), cut -d: -f1 /etc/passwd (field cut), sort, uniq, wc -l (line count), head -n 10, tail -f /var/log/syslog (follow log).
tar (Tape Archive)
Create: tar -czf backup.tar.gz /path (create, gzip, file). Extract: tar -xzf backup.tar.gz (extract, gzip, file). List: tar -tzf backup.tar.gz. -c=create, -x=extract, -z=gzip, -j=bzip2, -J=xz, -v=verbose, -f=filename, -C /dest=extract to directory.
rsync
Efficient incremental sync. rsync -av /source/ /dest/ (archive + verbose). rsync -avz user@remote:/path /local/ (remote sync with compression). -a=archive (preserves permissions, timestamps, symlinks), --delete (remove files deleted at source), --exclude='*.tmp'. Faster than cp โ only transfers changes.
dd
Low-level disk copy. dd if=/dev/sda of=/backup/disk.img bs=4M status=progress โ create disk image. dd if=/dev/zero of=/dev/sdb bs=1M โ wipe disk. bs = block size. Dangerous โ no safety checks. Use for disk cloning, creating bootable USBs, wiping disks.
Compression Tools
gzip file โ file.gz (fast, moderate compression). bzip2 file โ file.bz2 (slower, better compression). xz file โ file.xz (best compression, slowest). zip/unzip (cross-platform). Decompress: gunzip, bunzip2, unxz.
KVM (Kernel-based Virtual Machine)
Linux's native Type 1 hypervisor (runs inside the kernel). Requires CPU virtualization extensions (Intel VT-x or AMD-V). Check: lscpu | grep Virtualization or egrep '(vmx|svm)' /proc/cpuinfo. Works with QEMU for full hardware emulation.
virsh Commands
virsh list --all (list VMs), virsh start vm_name, virsh shutdown vm_name, virsh destroy vm_name (force off), virsh define vm.xml (create from XML), virsh dumpxml vm_name (export config), virsh console vm_name (connect to console). VMs stored in /etc/libvirt/qemu/
VM Disk Images
qcow2 (QEMU Copy-On-Write โ supports snapshots, thin provisioning, preferred format). raw (no overhead, best performance, no snapshots). qemu-img create -f qcow2 disk.qcow2 20G โ create image. qemu-img info disk.qcow2 โ show info. qemu-img convert -f raw -O qcow2 disk.raw disk.qcow2 โ convert formats.
lv_app with a size of 10GB from the volume group vg_data?/var/data/ to a remote server at backup.example.com, preserving all file permissions and only transferring changed files. Which command achieves this?ip route add default via 192.168.1.1 do?/dev/sda for backup purposes. Which command is correct?Quiz Complete!
Boot Order
BIOS/UEFI โ GRUB2 โ Kernel โ Initramfs โ Systemd. Five stages, in order, every time Linux boots.
LVM Order
pvcreate (Physical Volume) โ vgcreate (Volume Group) โ lvcreate (Logical Volume) โ mkfs โ mount. Always in this order.
RAID Tolerance
RAID 0=no redundancy. RAID 1=1 disk failure OK. RAID 5=1 disk failure OK. RAID 6=2 disk failures OK. RAID 10=1 per mirror pair.
rsync vs dd vs tar
rsync: incremental, network-aware, preserves attrs. dd: bit-for-bit block copy (disks/images). tar: bundle files into archive with compression.
ip Command Cheatsheet
ip addr show, ip route show, ip link set eth0 up, ip neigh show. Replaces ifconfig, route, arp.
KVM Check
egrep '(vmx|svm)' /proc/cpuinfo โ if output is empty, CPU doesn't support hardware virtualization. No virtualization extensions = no KVM VMs.
/etc/default/grub. Generated file (do NOT edit): /boot/grub2/grub.cfg. Regenerate: grub2-mkconfig -o /boot/grub2/grub.cfg. UEFI path: /boot/efi/EFI/distro/grub.cfgpvcreate /dev/sdb โ init disk for LVM. 2. vgcreate vg_name /dev/sdb โ create VG. 3. lvcreate -L 20G -n lv_name vg_name โ create LV. 4. mkfs.ext4 /dev/vg_name/lv_name then mount. Display: pvs, vgs, lvs--delete (mirror source), --exclude='pattern', -n (dry run). Transfers only CHANGED files โ efficient for backups.systemctl get-default. Set: systemctl set-default multi-user.targetip addr show โ list all IPs. ip addr add 10.0.0.5/24 dev eth0 โ add IP. ip route show โ routing table. ip route add default via 10.0.0.1 โ set default gateway. ip link set eth0 up โ enable interface. Replaces: ifconfig, route, arp.tar -czf backup.tar.gz /path/ (gzip) or tar -cjf backup.tar.bz2 /path/ (bzip2). Extract: tar -xzf backup.tar.gz -C /dest/. List: tar -tzf backup.tar.gz. Flags: c=create, x=extract, z=gzip, j=bzip2, J=xz, v=verbose, f=file, C=destination./etc, /var, /boot, /dev). Then practice basic shell navigation, redirection (>, >>, 2>), and pipes (|).
pvcreateโvgcreateโlvcreateโmkfs) and RAID levels (0=no redundancy, 1=mirror, 5=1 parity, 6=2 parity, 10=striped mirrors). Learn /etc/fstab format (UUID, options, dump/pass) and the ip command suite.
modprobe, /etc/modules-load.d/), and systemd target management.
nofail in fstab, ip addr/ip route commands, systemctl get-default, tar czf/xzf flags, rsync -av for incremental backup.
ip addr/ip route/ip link. fstab nofail. tar czf=create / xzf=extract. rsync -av=incremental. grub2-mkconfig=rebuild config.