Install Debian (based) Linux Distributions in a Folder (chroot)
Your support makes all the difference!
We believe security software like Kicksecure needs to remain open source and independent. Would you help sustain and grow the project? Learn more about our 10 year success story and maybe DONATE!
How to create a chroot (change root) in a secure way using mmdebstrap and systemd-nspawn.
Documentation for this is incomplete. Contributions are happily considered! See this for potential alternatives.
Chroot Use Cases
- See this list of chroot use cases in wikipedia.
chroot is not a security feature.
Quote Changing Roots:
systemd-nspawn tool which acts as chroot(1) on steroids
it makes use of file system and PID namespaces to boot a simple lightweight container on a file system tree.
It can be used almost like chroot(1), except that the isolation from the host OS is much more complete, a lot more secure and even easier to use
systemd-nspawn is capable of booting a complete systemd or sysvinit OS in container with a single command.
- Booting of the container can take less than 3 seconds.
systemd-nspawn be made a secure jail? The following quote might be outdated and/or not reflect a "hardened container". Quote systemd lead developer:
Note however that this protects the host OS only from accidental changes of its parameters. A process in the container can manually remount the file systems read-writeable and then change whatever it wants to change.
What are these issues? Related to running root vs non-root inside the container? Can these security holes nowadays be closed?
Since we are inside a VM already, can containers be used for better security?
Quote systemd-nspawn man page:
Specify one or more additional capabilities to drop for the container. This allows running the container with fewer capabilities than the default (see above).
systemd-nspawn supports unprivileged containers,
, though the containers need to be booted as root.
That could be an OK limitation?
To leave the chroot press keep holding key
CTRL and press key
5 quickly 3 times within 1 second. 
mmdebstrap is a tool that can be used to securely create chroots.
debootstrap is insecure at times such as if APT is vulnerable and the fixed package only available from security.debian.org APT repository not the regular Debian repository because it can use only 1 APT repository at a time. And security.debian.org does not include all packages created to create a chroot.
A secure alternative is
mmdebstrap.  See also other advantages of
- xchroot: chroot for users with Xorg/X11 forwarding and automatic mounting + aufs/unionfs read only root support.
- Needs cautious review. Same author as debcheckroot which does not do gpg signature verification of downloaded package metadata because thinks that's useless.
- ↑ https://unix.stackexchange.com/questions/577065/connected-to-container-mycontainer-press-three-times-within-1s-to-exit-sessi
- ↑ alternative is multistrap (might be outdated, author has no experience with it)