Home/Tracks/Linux

Linux

The server operating system you'll live in. Learn how it boots, where the important configuration lives, how to schedule jobs, manage storage and fix a failing service.

 lessons  documents  infographics Cron explainer

How Linux boots

Power on→BIOS / UEFI→MBR / GPT→GRUB→Kernel→initramfs→systemd (PID 1)→Shell / GUI
  1. Firmware (BIOS/UEFI) runs the power-on self test and finds a boot device.
  2. Bootloader (GRUB) loads the kernel and the initial RAM disk.
  3. Kernel initialises hardware, mounts the root filesystem using drivers from initramfs.
  4. systemd (/sbin/init) starts services in order and brings the system to its target (multi-user or graphical).

Kernel space vs user space

The kernel runs in privileged mode and manages processes, memory, device drivers and filesystems. Programs run in user space with least privilege and ask the kernel for work through system calls.

Visual:

Files every admin should know

PathWhat it controls
/etc/passwd · /etc/shadowUser accounts · password hashes (root only)
/etc/groupGroups and members
/etc/sudoersWho can run commands as root (edit with visudo)
/etc/hosts · /etc/resolv.confLocal name overrides · DNS servers
/etc/fstabFilesystems mounted at boot
/etc/netplan/*.yamlNetwork configuration (Ubuntu)
/etc/ssh/sshd_configSSH server settings
/etc/crontab · /var/spool/cron/Scheduled tasks
/etc/systemd/system/Custom and overridden service units
/var/log/System, auth and application logs
~/.bashrcShell environment and aliases

A typo in /etc/fstab or /etc/sudoers can stop a server booting or lock you out. Back up first and validate (mount -a, visudo -c).

Visual:

Health-check commands

Run these first when you log in to a server that “feels slow” or after an alert.

uptime                     # load average and how long it has been up
top                        # live CPU / memory per process (or htop)
free -h                    # memory and swap
df -h                      # disk usage per filesystem
lsblk                      # disks, partitions and LVM volumes
ss -tulpn                  # listening ports and owning process
ip addr                    # interfaces and IPs
systemctl --failed         # services that failed to start
journalctl -xe             # recent errors with explanations
journalctl -p err -b       # all errors since boot

Permissions in one minute

-rwxr-x--- = owner can read/write/execute, group can read/execute, others nothing. In numbers: r=4, w=2, x=1, so that's 750.

chmod 640 /etc/app/config.yml
chown appuser:appgroup /var/www/app -R
sudo -l                    # what can I run with sudo?

Scheduling with cron

A cron line has five time fields followed by the command.

┌──────── minute (0–59)
│ ┌────── hour (0–23)
│ │ ┌──── day of month (1–31)
│ │ │ ┌── month (1–12)
│ │ │ │ ┌ day of week (0–7, 0 and 7 = Sunday)
│ │ │ │ │
30 2 * * 1-5  /opt/scripts/backup.sh >> /var/log/backup.log 2>&1
* any value* * * * * runs every minute
, list0 9,17 * * * at 09:00 and 17:00
- range0 9 * * 1-5 weekdays at 09:00
/ step*/15 * * * * every 15 minutes

Cron explainer

Managing crontabs

crontab -e                 # edit your crontab
crontab -l                 # list it
crontab -u alice -l        # another user's crontab (root)
crontab -r                 # remove it (careful!)
Visual:

Storage: LVM & RAID

LVM — flexible volumes

Disk / partition→PV→VG→LV→Filesystem→Mount point
PV · Physical VolumeA disk or partition prepared for LVM.
VG · Volume GroupA pool of storage built from one or more PVs.
LV · Logical VolumeA resizable “partition” carved from a VG.
Why use itGrow volumes online, pool disks, take snapshots.

These commands modify disks. Practise on a disposable lab disk and double-check device names with lsblk.

lsblk
sudo pvcreate /dev/sdb
sudo vgcreate vg_data /dev/sdb
sudo lvcreate -L 10G -n lv_backup vg_data
sudo mkfs.ext4 /dev/vg_data/lv_backup
sudo mkdir -p /backup
sudo mount /dev/vg_data/lv_backup /backup

# Grow it later by 5 GB, filesystem included
sudo lvextend -r -L +5G /dev/vg_data/lv_backup

sudo pvs; sudo vgs; sudo lvs

RAID levels

RAIDMin disksMethodSurvivesUsable (4 × 1 TB)
02StripingNo failures4 TB
12Mirroring1 disk per mirror2 TB
53Distributed parity1 disk3 TB
64Dual parity2 disks2 TB
104Mirror + stripe1 per mirror pair2 TB

RAID is not a backup. It doesn't protect against deletion, ransomware, corruption, theft or site disasters.

Services & troubleshooting

systemd essentials

sudo systemctl status nginx
sudo systemctl start|stop|restart|reload nginx
sudo systemctl enable --now nginx      # start now and at boot
journalctl -u nginx --since "1 hour ago"
systemctl list-units --type=service --state=running

A service failed to start

  1. systemctl status <service> — read the last log lines.
  2. journalctl -u <service> — see the full error.
  3. Validate the configuration (nginx -t, sshd -t, apachectl configtest).
  4. Check dependencies, permissions, ports in use (ss -tulpn) and free disk space.
  5. Apply a controlled fix, restart and verify.

Disk is 100% full

df -h                                   # which filesystem?
sudo du -xh / --max-depth=1 | sort -h   # which directory?
sudo find /var/log -size +100M          # big logs
sudo journalctl --vacuum-size=500M      # shrink the journal
sudo lsof +L1                           # deleted files still held open

Find out what a file is and who owns it before deleting it. Then expand storage or set up log rotation so it doesn't happen again.

Library

Documents

PDFs open in a new tab. A tick appears on the ones you've opened.