Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Set-up · 30 minutes

Set up your operations lab

After this lesson you can
  • Get the practice system ready for boot, container, Git and troubleshooting lessons
  • Install rootless podman, Git and the helper tools, and pull two small images
  • Prove with a check script that the lab is ready
Lab files of this lesson (1)

The lab folder as it stands after this lesson. Unzip it in ~/krlab.

More

The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.

What you need

Part 4 breaks things on purpose. A script plants a full disk, a wrong route, a runaway process or a failing service, and you find and repair it. The faults are real, so they run on a practice system that you may break and restore. Use the one from Part 2 or Part 3: a Linux virtual machine, or a spare computer. Take a snapshot of it first, as the set-up lesson of Part 3 showed. Do not use the main system of a work laptop, and never run these scripts on a system that is not yours.

NeedWhy
Ubuntu 24.04 with systemd, bash and apt (the outputs come from this release)The lessons use systemctl, journalctl and Ubuntu paths.
A user with sudo rightsPlanting and repairing faults needs administrator rights.
About 4 GB of memory and 10 GB of free disk spaceImages, a test volume and a memory limit of 50 MB.
A network connection for apt and for two image downloads (about 70 MB)Lessons 2 and 3 pull images from a public registry.

On a newer release (Ubuntu 26.04 and later) the commands and exit codes are the same. The wording of messages, the version numbers and the kernel and Python versions in the outputs differ a little. Answer every check from a number, a name or an exit code, never from a message.

A virtual machine is the best choice, and a snapshot taken now (named before-operations) is your way back. The outputs of this part come from a virtual machine with Ubuntu 24.04. A Linux container with its own init system also works if it allows nested containers, but it does not boot its own kernel: lesson 1 then reads the boot of its host, and the swap, kernel log and loop device steps of lessons 7 and 8 are refused. How to take a snapshot is explained in the set-up lesson of Part 3.

The operations lab
Practice systemInternetFault scriptsYouPodmanRegistry123Practice systemInternetFault scriptsYouPodmanRegistry123
  1. You → Fault scripts: plant a fault, then repair it
  2. You → Podman: run rootless containers
  3. Podman → Registry: pull alpine and nginx, 70 MB

Set it up

1. Start the system and check your rights

Log in and open a terminal. id prints your user and groups, and sudo -v checks that sudo accepts you (the set-up lesson of Part 2 explained both).

id
sudo -v
uid=1000(you) gid=1000(you) groups=1000(you),27(sudo)

sudo -v prints nothing when it works.

2. Install the tools

podman runs containers without root (lessons 2 and 3). git records changes, and git-filter-repo rewrites history (lesson 4). python3-yaml reads YAML (lesson 5). lsof lists open files (lesson 8), nftables gives the nft command (lesson 6), and curl makes web requests.

sudo apt update
sudo apt install -y podman git git-filter-repo python3-yaml lsof nftables curl

The output is long and ends without an error.

3. Pull the two images

podman pull downloads an image. Lessons 2 and 3 use a small base system, alpine, and a web server, nginx. Pull them now, as your own user and without sudo, so that the later lessons start fast. Always use the full name of an image.

podman pull docker.io/library/alpine:3.20
podman pull docker.io/library/nginx:alpine

Each command prints the layers that it copies and ends with the id of the image.

4. Make the lab folder

mkdir -p ~/krlab/linux-operations
cd ~/krlab/linux-operations
pwd
/home/you/krlab/linux-operations

Every lesson starts from this folder. Files that a lesson tells you to save go here.

5. Write the check script

Save this script as labcheck.sh in the lab folder. The function check runs a command and prints ok or MISSING. It counts the checks that passed, prints the last line, and exits with a failure code if one failed. Two words of the shell are new. local keeps a variable inside the function. shift drops the first argument, so that "$@" (all the arguments) holds the command that check must run. Run it as your own user and not with sudo, because the test of rootless podman needs an ordinary user.

labcheck.sh

#!/usr/bin/env bash
# labcheck.sh - checks that this machine can run Part 4 of the Linux course (operations and troubleshooting).
export PATH="$PATH:/usr/sbin:/sbin"
ok=0
total=0

check() {
    local name=$1
    shift
    total=$((total + 1))
    if "$@" > /dev/null 2>&1; then
        ok=$((ok + 1))
        echo "ok       $name"
    else
        echo "MISSING  $name"
    fi
}

check "administrator rights" sudo -n true
check "systemd runs" test -d /run/systemd/system
check "rootless podman" bash -c '[ "$(podman info --format "{{.Host.Security.Rootless}}")" = true ]'
check "image alpine" podman image exists docker.io/library/alpine:3.20
check "image nginx" podman image exists docker.io/library/nginx:alpine
check "git and git-filter-repo" bash -c 'git --version && git filter-repo --version'
check "python3 yaml" python3 -c 'import yaml'
check "tools of the lessons" bash -c 'for t in ip nft ss curl lsof namei findmnt journalctl; do command -v $t || exit 1; done'
check "private network namespace" bash -c 'sudo -n ip netns add krcheck && sudo -n ip netns del krcheck'
check "lab folder" test -w "$HOME/krlab/linux-operations"

echo "lab ready: $ok of $total"
(( ok == total ))

Check your lab

Run the script with bash. The check "administrator rights" is sudo -n true, where -n means "never ask for a password", so run sudo -v first.

sudo -v
bash labcheck.sh
ok       administrator rights
ok       systemd runs
ok       rootless podman
ok       image alpine
ok       image nginx
ok       git and git-filter-repo
ok       python3 yaml
ok       tools of the lessons
ok       private network namespace
ok       lab folder
lab ready: 10 of 10

Each line is one requirement, and the last line is the result. Type the last line of your own run.

If it fails

A line that starts with MISSING names what is absent. Fix it, and run the script again.

LineWhat to do
administrator rightsRun sudo -v and type your password, then run the script again. If sudo refuses you, ask the owner of the system, or use your own virtual machine.
systemd runsThe system does not use systemd. In a container, use an image that starts systemd.
rootless podmanRun the script as your own user, without sudo. If it still fails, check that uidmap is installed (sudo apt install -y uidmap) and that your user has a line in /etc/subuid and /etc/subgid. Log out and in again. If podman still refuses to start, run podman info and read the line that names the problem.
image alpine, image nginxRun step 3 again. A failed download needs a working network and a correct clock.
git and git-filter-repoRun step 2 again and read the error of apt.
python3 yamlsudo apt install -y python3-yaml.
tools of the lessonsRun step 2 again. namei and findmnt come with the package util-linux, which every Ubuntu has.
private network namespacesudo ip netns add krcheck failed. A container may need the setting security.nesting or more rights. Use a virtual machine for lessons 6 and 11.
lab folderGo back to step 4. Check that the folder is yours with ls -ld ~/krlab/linux-operations.

If the last line says lab ready: 9 of 10, you can do the lessons that do not use the missing part. Lessons 2 and 3 need podman, lesson 4 needs git and git-filter-repo, lessons 6 and 11 need the namespace, and lessons 6 to 11 need sudo. Fix the missing part before you start them.