Part 7 of 7 · 2 min read
Exercises
Easy
Easy 1: Which namespace (20 minutes)
Name the kind for: a private host name, private process numbers, private network devices.
Done when: UTS, PID, network.
Hint
use the table in section 2.
Easy 2: Two numbers (20 minutes)
A process is number 1 in its PID namespace and number 4,812 on the host. Which number does ps show inside, and which on the host?
Done when: 1 inside and 4,812 on the host.
Hint
each namespace has its own table.
Easy 3: Same or different (20 minutes)
Two processes show net:[4026531833] and net:[4026532267]. Do they share a network?
Done when: no, the numbers differ.
Hint
equal numbers mean the same namespace.
Medium
Medium 1: Use unshare (45 minutes)
Run unshare --uts --pid --fork --mount-proc sh and, inside it, run hostname test, hostname, echo $$ and ps -e. Run hostname again after leaving. Report what changed.
Done when: the host name test only inside, $$ equal to 1, a short ps list, the old name outside.
Hint
--fork is needed so that the shell is the first child.
Medium 2: Compare ns numbers (45 minutes)
Start the program of section 3, and in the child list /proc/self/ns (use ls -l). Compare with your shell's numbers and say which kinds differ.
Done when: uts, pid (for children) and net differ, and mnt, ipc, user and cgroup are equal.
Hint
ls -l /proc/self/ns.
Medium 3: User map (45 minutes)
As a normal user, run unshare --user --map-root-user id and cat /proc/self/uid_map. Explain both lines.
Done when: uid 0 inside, and a map of 0 YOURUID 1.
Hint
the third number in the map is the length of the range.
Hard
Hard 1: Join a namespace (90 minutes)
Start a process in a new UTS namespace that sleeps, find its PID, and use nsenter --target PID --uts hostname to read its host name. Explain what setns did.
Done when: the host name of the sleeping process is printed, and a sentence that the entered process joined that namespace for the command.
Hint
use sleep 100 inside unshare --uts in the background.
Hard 2: PID 1 duties (90 minutes)
In a new PID namespace, start a shell that starts a background process and exits. What happens to the namespace? Test it, and explain with the rules for process number 1.
Done when: the namespace ends when its number 1 exits, and the kernel kills the rest.
Hint
try unshare --pid --fork sh -c 'sleep 100 & exit'.
Hard 3: What is missing (90 minutes)
List three things that a process in only a PID and mount namespace can still do to its neighbours, and which namespace or limit would stop each.
Done when: three items, such as use all memory (cgroup), change the host name (UTS), open the host's ports (network).
Hint
think about CPU, memory, network, time and users.