This short article explains a simple, practical one-shot workflow that lets a non-root user create a root filesystem (rootfs) with debootstrap
and install packages inside it using apt
, by running the operations inside an unprivileged user namespace where the user appears as root
. It includes a ready-to-run script, key explanations, and troubleshooting hints.
Run the provided script as a regular user. It uses unshare --user --map-root-user
to create a user/mount/pid namespace where your UID is mapped to UID 0 inside that namespace. Inside that namespace the script mounts necessary pseudo-filesystems, runs debootstrap
to populate a target directory with a minimal Debian rootfs, then chroot
s into that rootfs and runs apt-get
to install packages (e.g. vim
). When finished, it unmounts the bind mounts and leaves the populated rootfs at the path you chose.