Set-up · 30 minutes
Set up a practice system where you are the administrator
- Choose a Linux system that you may change and break
- Install the tools that the lessons use and create the folder ~/krlab/linux-admin
- Prove with a check script that the lab is ready
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
This course teaches you to look after a system: add users, change services, install software, mount disks. For that you need a Linux where you are the administrator and which you may break. Never use the main system of your work laptop, and never use a server that other people depend on. A mistake in lesson 4, 6 or 7 can lock you out or erase a disk.
Choose one of these. The first is the best.
| Option | What it is | Limits |
|---|---|---|
| Virtual machine | A whole Linux inside a program on your computer (VirtualBox, VMware, or virt-manager on Linux). Install Ubuntu Server 24.04 LTS (the lessons show the output of a clean install). | None. You can add a second virtual disk for lesson 4 and take a snapshot before you start. |
| WSL 2 on Windows | Ubuntu inside Windows. In a PowerShell window that you started as administrator, run wsl --install -d Ubuntu, and restart. Then turn on systemd: in Ubuntu, write [boot] and systemd=true on two lines into /etc/wsl.conf, and run wsl --shutdown in PowerShell. | You cannot add a disk or boot a kernel. Lesson 4 works only on image files. |
| Container | An Ubuntu container that runs systemd (for example with LXD or Incus). | It shares the kernel of its host, so you cannot use a loop device or switch on swap. In lesson 4, do the steps on image files and the RAM file system, and read the rest. |
| Spare computer | An old PC with Ubuntu installed on its own disk. | You must be sure that it holds nothing you need. |
The outputs of the lessons come from Ubuntu 24.04 LTS on a virtual machine with 4 CPUs, 4 GiB of memory and one 20 GiB disk. Use that release if you can. Your numbers will differ, and your own system differs in disk names, swap, snap devices and extra services (the lessons say where). On a newer release, small differences in the text of messages are normal. Ubuntu 26.04 uses sudo-rs for sudo and uutils for ls, so the error text of visudo -cf (lesson 7) and some options of ls differ. The commands use apt, so use Ubuntu or Debian. The columns for other families are in lesson 9. How to install each option depends on your computer, and it is not tested here. If you have never made a virtual machine, one short route is Multipass, which runs on Linux, Windows and macOS: on Linux install it with sudo snap install multipass, then run multipass launch 24.04 --name krbox --disk 15G --memory 4G and multipass shell krbox. You are then the user ubuntu, who may use sudo. For the other options, follow the instructions of the program that you choose.
You need about 4 GB of memory for the system, 15 GB of disk space, and a network connection for lesson 9. You need an account that may use sudo. The first account that the Ubuntu installer creates may do it.
Set it up
1. Start the system and open a terminal
Start your practice system and log in. Open a terminal. In a virtual machine with a snapshot function, take a snapshot now and name it clean. If you break the system, you can go back to it.
2. Check that you are an administrator
id prints your user and your groups, and sudo -v asks for your password and checks that sudo accepts you. A member of the group sudo may use it.
id
sudo -vuid=1001(you) gid=1001(you) groups=1001(you),27(sudo)sudo -v prints nothing when it works. If it says that you are not in the sudoers file, ask the person who set up the system, or use an account that is.
3. Install the tools of the lessons
apt is the package manager of Debian and Ubuntu (lesson 9 explains it). update refreshes the list of packages, and install -y installs without a question. The packages give you lshw and iostat (lessons 1 and 2), the ACL tools (lesson 7), cron and at (lesson 12), and fdisk, make and the C compiler gcc (lessons 4 and 10).
sudo apt update
sudo apt install -y lshw sysstat acl cron at fdisk make gccThe output is long, and it differs on every system. It ends without an error.
4. Make the lab folder
Every lesson works in a folder under ~/krlab. mkdir -p creates a folder and the folders above it, and cd moves you into it.
mkdir -p ~/krlab/linux-admin
cd ~/krlab/linux-admin
pwd/home/you/krlab/linux-admin5. Save the check script
The script runs five checks. Its function check runs a command and prints ok or MISSING. It counts the checks that passed, prints the last line, and exits with an error code if one failed. Save the text below as labcheck.sh in ~/krlab/linux-admin, with an editor (lesson 7 of Part 1), or take it from the lab files of the course. Save the zip in ~/Downloads. If unzip is missing, install it with sudo apt install unzip. Then run cd ~/Downloads && unzip files.zip && cd linux, and sh kr-lab.sh 2-admin/00-set-up-an-admin-lab ~/krlab/linux-admin. The same command with the name of another lesson folder builds the lab as it stands after that lesson (it also holds the files of Part 1: a file with the same name is the one of Part 2 when that lesson has it, and until lesson 14 build-case.sh is the one of Part 1). A later lesson explains how such a script works.
labcheck.sh
#!/usr/bin/env bash
# labcheck.sh - checks that this machine can run Part 2 of the Linux course (administration).
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" bash -c '[ "$(id -u)" -eq 0 ] || sudo -n true'
check "systemd runs" test -d /run/systemd/system
check "apt answers" apt-cache policy bash
check "tools of the lessons" bash -c 'for t in lshw iostat setfacl crontab at fdisk make cc; do command -v $t || exit 1; done'
check "lab folder" test -w "$HOME/krlab/linux-admin"
echo "lab ready: $ok of $total"
(( ok == total ))Check your lab
The check "administrator rights" is sudo -n true: -n means "never ask for a password". On a normal account it fails until sudo has a fresh password entry, so run sudo -v first, and then the script.
sudo -v
bash labcheck.shok administrator rights
ok systemd runs
ok apt answers
ok tools of the lessons
ok lab folder
lab ready: 5 of 5Each 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.
| Line | What to do |
|---|---|
administrator rights | Run sudo -v and type your password, then run the script again. If sudo refuses you, ask the owner of the system, or log in with the first account that the installer made, which may use sudo. |
systemd runs | In WSL, check /etc/wsl.conf (the WSL row of the table in What you need) and run wsl --shutdown. In a container, use an image that starts systemd. The check looks for the folder /run/systemd/system. |
apt answers | You may not run Debian or Ubuntu. Use one of them: the lessons use apt. |
tools of the lessons | Run step 3 again. Read the error of apt: a missing network or a wrong clock stops it. |
lab folder | Go back to step 4. Check that the folder is yours with ls -ld ~/krlab/linux-admin. |
If the last line says lab ready: 4 of 5, the lab works for every lesson that does not need the missing part. Read the lessons that use that part first, and fix it before you start them. Do not change a system that is not yours.