Linux Basics Lab Guide
Difficulty: Beginner Estimated Time: 45 minutes Last Updated: February 11, 2026
Learning Objectives
- Practice Linux process management commands
- Directly observe the isolation effect of Linux namespaces
- Understand resource limits through cgroups
- Practice file permissions and ownership management
Prerequisites
- [ ] Linux terminal access (Ubuntu 20.04+ recommended)
- [ ] sudo privileges
- [ ] Completed Linux Basics learning
Exercise 1: Process Management
Goal
Practice process listing, background execution, and signal sending.
Steps
Step 1.1: Check currently running processes
# Processes in the current terminal
ps aux | head -20
# View process relationships in tree format
ps auxf | head -30Step 1.2: Run a background process
# Run a sleep process in the background
sleep 300 &
echo "PID: $!"
# Check background jobs
jobs -lStep 1.3: Send a signal to a process
# Get the process ID
SLEEP_PID=$(pgrep -f "sleep 300")
echo "Sleep PID: $SLEEP_PID"
# Request termination with SIGTERM
kill $SLEEP_PID
# Verify the process has terminated
ps aux | grep "sleep 300" | grep -v grepNeed a hint?
- Use
kill -lto see a list of available signals kill -9 PIDforcefully terminates with SIGKILLpkill -f "pattern"allows name-based termination
Verification
# The sleep process should not exist
pgrep -f "sleep 300" && echo "Still running" || echo "Termination complete"Exercise 2: Linux Namespace Isolation
Goal
Create namespaces to observe process and network isolation.
Steps
Step 2.1: Verify PID namespace isolation
# Run bash in a new PID namespace
sudo unshare --pid --fork --mount-proc bash -c '
echo "PID list inside the new namespace:"
ps aux
echo "Current process PID: $$"
'Expected output:
PID list inside the new namespace:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 ... ... ... S ... 0:00 bash -c ...
root 2 0.0 0.0 ... ... ... R ... 0:00 ps aux
Current process PID: 1Step 2.2: Network namespace isolation
# Create a network namespace
sudo ip netns add test-ns
# List namespaces
sudo ip netns list
# Check network inside the isolated namespace
sudo ip netns exec test-ns ip addr
# Cleanup
sudo ip netns delete test-nsNeed a hint?
- Host network interfaces are not visible inside the network namespace
- Only the
lo(loopback) interface exists, and it's DOWN by default - This is the principle behind container network isolation
Verification
# Verify the namespace has been deleted
sudo ip netns list | grep test-ns && echo "Still exists" || echo "Deletion complete"Exercise 3: cgroup Resource Limits
Goal
Use cgroups to limit process memory usage.
Steps
Step 3.1: Check cgroup information
# Check cgroup v2 mount
mount | grep cgroup
# Check cgroup of current process
cat /proc/self/cgroup
# Check cgroup controllers
cat /sys/fs/cgroup/cgroup.controllers 2>/dev/null || echo "Using cgroup v1"Step 3.2: Check memory usage
# System memory information
free -h
# Memory usage of specific processes
ps aux --sort=-%mem | head -10Step 3.3: Connection to Kubernetes resource limits
# This is how resources.limits works in K8s
# Let's look at a Pod manifest example
cat << 'EOF'
apiVersion: v1
kind: Pod
metadata:
name: memory-demo
spec:
containers:
- name: memory-demo
image: nginx
resources:
requests:
memory: "64Mi"
limits:
memory: "128Mi"
EOFNeed a hint?
- K8s
resources.limits.memoryis translated to cgroup memory limits for the container - Exceeding the limit results in OOMKilled status
- You can check resource limits with
kubectl describe pod
Exercise 4: File Permission Management
Goal
Practice managing file permissions and ownership.
Steps
Step 4.1: Create a file and check permissions
# Create a test file
mkdir -p /tmp/linux-lab
echo "Hello Linux" > /tmp/linux-lab/test.txt
# Check current permissions
ls -la /tmp/linux-lab/test.txtStep 4.2: Change permissions
# Add execute permission
chmod +x /tmp/linux-lab/test.txt
ls -la /tmp/linux-lab/test.txt
# Set with numeric mode (read/write - read - none)
chmod 640 /tmp/linux-lab/test.txt
ls -la /tmp/linux-lab/test.txt
# Set the same permissions as K8s Secret volume defaults
chmod 0644 /tmp/linux-lab/test.txtStep 4.3: Change ownership
# Check current user and group
id
# Change group (if executable)
sudo chown $USER:root /tmp/linux-lab/test.txt
ls -la /tmp/linux-lab/test.txtVerification
# Verify permissions are -rw-r--r--
stat -c "%a %U %G" /tmp/linux-lab/test.txtCleanup
# Delete test files
rm -rf /tmp/linux-lab
# Clean up remaining processes
pkill -f "sleep 300" 2>/dev/nullTroubleshooting
The unshare command is not found
Install the util-linux package:
sudo apt-get install util-linux # Ubuntu/Debian
sudo yum install util-linux # CentOS/RHELThe ip netns command does not work
The iproute2 package is required:
sudo apt-get install iproute2 # Ubuntu/Debian
sudo yum install iproute # CentOS/RHEL