main branch of your CloudLab class profile.
1
2
sudo apt update
sudo apt install -y cgroup-tools stress debootstrap
1
echo $$
unshare to create a new PID namespace and fork a bash process:
1
sudo unshare --fork --pid --mount-proc bash
1
2
echo $$
ps aux
exit once to return to the host and test pid again.
1
2
exit
echo $$
/sys/fs/cgroup.mygroup:
1
sudo cgcreate -g memory:mygroup
1
2
# 100MB = 104857600 bytes
echo 104857600 | sudo tee /sys/fs/cgroup/mygroup/memory.max
stress test inside that cgroup that tries to eat 99MB of RAM. Ctrl-C to terminate the running process
1
sudo cgexec -g memory:mygroup stress --vm 1 --vm-bytes 99M --vm-keep
stress test inside that cgroup that tries to eat 101MB of RAM.
1
sudo cgexec -g memory:mygroup stress --vm 1 --vm-bytes 101M --vm-keep
chroot.chroot is the ancestor concept.
1
mkdir container
1
sudo debootstrap --variant=minbase stable /users/$USER/container http://deb.debian.org/debian
1
for dir in dev proc sys; do sudo mount --bind /$dir /users/$USER/container/$dir; done
1
sudo unshare --mount --uts --ipc --pid --fork chroot /users/$USER/container /bin/bash
/home or /users. They don’t exist here! You are isolated.
1
exit
chroot, if we mounted /proc, we would see all the host’s processes.unshare to create a new namespace, then immediately chroot into our folder.
1
sudo unshare --mount --uts --ipc --pid --fork chroot container /bin/bash
ps and setup a separate mount point for /proc from inside the container
1
2
apt update
apt install -y procps
ps aux inside the container.bash process as PID 1.exit to return to the host.docker run replaces all these manual commands.