For our container we want a root filesystem so we'll extract one from the busybox docker container.
We will then extract it into a folder (as root to preserve permissions).
$ id=$(docker run -d busybox /bin/true)
$ docker export $id > busyboxfs.tar
$ docker rm $id
$ mkdir busyboxfs
$ sudo tar -xf busyboxfs.tar -C busyboxfs
First well drop ourselves into namespaces unshared from parent with the unshare
command.
$ sudo unshare -fmuip
This will fork our process as a child process and create a mount, uts, ipc, and process namespace.
Next we'll pivot_root to our busyboxfs
mkdir -p $(pwd)/busyboxfs/old-root
mkdir -p /busyboxfs
mount --bind $(pwd)/busyboxfs /busyboxfs
pivot_root /busyboxfs /busyboxfs/old-root
mount -t proc proc /proc
cd /
umount -l /old-root
exec /bin/sh
This switches our root filesystem to the busyboxfs and then removes any access to the old rootfs. This also switches our init pid to the /bin/sh process making it pid 1
$ ps -ef
PID USER TIME COMMAND
1 root 0:00 /bin/sh
55 root 0:00 ps -ef