schroot
TL,DR: schroot is a good way to run programs from another Ubuntu version, or another Debian-based distribution, .
You can try out many aspects of another distribution with schroot. This is the lightest-weight virtualized environment for running a Linux inside another Linux (it's technically a virtual environment, but much in the same sense of Python's virtual environments, if that tells you anything — it doesn't involve any form of CPU-based or kernel-based virtualization).
chroot is a Unix feature that lets you run a program inside a directory, so that the program only sees that directory and its subdirectories, and not the rest of the system. Linux distributions want certain files in specific places (/etc
, /lib
, etc.), and chroot lets you tell a program that the “real” /etc
is actually /somewhere/etc
and so on. For example, you install Debian in /debian
, and you run chroot /debian bash
and get a bash prompt running in Debian. You get Debian's bash, and every program started from that bash is whatever is in Debian, and apt install somepackage
will install the package in that Debian and so on, because what the chrooted programs see as /etc
is the real /debian/etc
and so on. The kernel (so the hardware drivers), the network configuration and all other aspects of the system that aren't determined by disk files are the ones of the outside world.
A chroot has many limitations. For example, since it doesn't see anything outside its own tree, it doesn't have access to /home
, /proc
, /dev
and other critical parts of the system that you'd really like to share. It doesn't have the same user accounts. Also, chroot can bypass security policies, so only root (the system administrator) is allowed to use it.
Schroot is a program that provides a lot of convenience features around the use of chroot to install another Linux operating system. It takes care (based on its configuration) of making directories like /home
and /proc
available in the schroot, of sharing user accounts, etc. It's available as an Ubuntu package, so you can just install it with apt install schroot
or your favorite package manager. Once you've installed the program, create a configuration file to declare the schroot you want (see examples on the Debian wiki or elsewhere on the web).
The next bit is to install another distribution in the schroot environment. How to do this depends on the distribution. Caution — You need to be somewhat careful there because the schroot shares a lot of things with the host, such as network access. If you start a network server inside the schroot, it'll want exclusive access on the port, conflicting with the same software on the host unless the two are configured to use different ports. There is no unified way to install another distribution like this.
Debian and derivatives have two very convenient features to install another distribution inside a chroot environment: debootstrap, and service suppression. Debootstrap (apt install debootstrap
) is a tool to download a starter set of packages from Debian, Ubuntu or (perhaps with a little configuration) other Debian-based distribution, and install those packages under a directory of your choice. Modern Debian versions come with service suppression so that installing packages inside a chroot doesn't automatically start system services (be careful about that if you want to try out ancient releases).
For example, I'm a software developer and I sometimes need to test how my software interoperates with older or newer versions of other software. To test interoperability with software from about 2015, I use a schroot with Ubuntu 16.04:
$ cat /etc/schroot/chroot.d/xenial
[xenial]
description=Ubuntu 16.04
directory=/chroot/xenial
type=directory
groups=users
I started the installation of that system with debootstrap xenial /chroot/xenial https://archive.ubuntu.com/ubuntu/
. Then I ran
sudo schroot apt install [more packages I needed]
schroot ./interoperability-tests
to run my interoperability tests with the programs from Ubuntu 16.04.