Often times, you want to do some work on unstable, but run stable on your main system. There are other times where you want a test system that's somewhat isolated from your primary desktop.

Chroots are one way of doing this. With a chroot, the chroot guest system shares the kernel, but has a completely different root filesystem. However, the isolation isn't perfect: since the share the same kernel, the chroot can affect things outside if it tries. Thus, it isn't as completly secure as virtualization, but under most non-pathological non-malicious uses, it is a pretty easy and efficient way to test things.

This page explains how to set up and configure a chroots on debian, and the basics of using them for development.


Install debootstrap on the host system. Run it to install the base system.

sudo debootstrap --arch=amd64 sid ./chroot-sid-amd64 http://mirror.cc.columbia.edu/pub/linux/debian/debian/
  # --arch=amd64       == architecture to install (not required, must be compatible with host system)
  # sid                == suite to install
  # ./chroot-sid-amd64 == destination directory
  # http://...         == mirror directory

Now, ./chroot-sid-amd64 contains a complete Debian system.

You can test it by running the chroot command:

sudo chroot chroot-sid-amd64/ /bin/bash

This will run bash inside of the chroot as root. Note that it doesn't share files, for example, at this stage /home is empty and /usr is tiny.

Now, we need to get this set up so that we can easily use the chroot.


The host and guest system are running the same kernel, so they can communicate. We want to use this to make our life easier.

Our guest system will share the same /home as the host system. This means that you can access the same files inside the chroot as outside - this makes our life easy.

We use the tool schroot to automate this.


Schroot is an automatic chroot command, that takes care of some extra set-up for us: It automatically bind-mounts the /home and /tmp filesystems, makes your user exist within the chroot, allows you to run root commands inside the chroot.

First off, install the schroot package. Then, edit the config file /etc/schroot/schroot.conf and set it up to know about this chroot. Add this at the very bottom (adjusting the location=, users=, root-users= to the proper values.

description=Sid amd64 for development

Example using LVM:

#mount-options=-o atime,sync,user_xattr
lvm-snapshot-options=--size 2G

Now, run schroot -c sid. You see

srichard@ramanujan:~$ schroot -c sid
I: [sid-c0a1acda-3204-457b-a84e-57d41804e52e chroot] Running login shell: ‘/bin/bash’

Note that your bash prompt changes: it now says :sid in there - this is the name from schroot config file. This way you can tell which of your open shells are in the chroot, and which are not.

If you ls /home now, you'll note that inside the same chroot has the same /home as outside. This means you can access all of your files just as easily within the chroot as outside. Schroot took care of this bind-mounting automatically for us.

You appear in the same relative directory inside the chroot as you did outside: so if you were in ~/dev before, you end up in ~/dev afterwards.

Command summary:

What next?

You should log in to the chroot as root schroot -u root, and run aptitude and install any development packages you need. Then, do all of your development work inside of the chroot, using the unstable build tools.

If you need to

/etc/apt/sources.list is set to the mirror you used to initially install, and can be different from the mirror outside the chroot. Of course, you can change this to whatever mirror/suite/components you like.

Don't forget to occasionally aptitude update/upgrade, especially if this chroot is for unstable development work!

If you eventually have lots of unneeded dependencies in the chroot, or it gets corrupted by broken packages, never fear. Since it's a captive system, you can simply remove all of it, and recreate it. Your files are safely in your primary home directory, so they aren't deleted. BUT WAIT - make sure that there are no bind-mounts remaining inside the chroot, or anything which might cause things to removed recursively outside of the chroot! Basically, check the output from mount and make sure nothing funny is there...



Make a /etc/debian_chroot file with a name in it so you can tell when you are in it. This is automatically created when you use schroot. You can make this appear in your bash prompt if you want:

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
#(or just throw in $debian_chroot in there)

Looks like this for me:


DebianNotes/Chroots (last edited 2014-09-30 14:03:15 by RichardDarst)