Windows now has a subsystem for Linux, where you can try different distros as an application. With no virtual machine needed. Is there something like that on Linux?
First, it's always going to be a richer and more "real" experience if you try out a distribution on a VM, but ...
With no virtual machine needed. Is there something like that on Linux?
Sure, the techniques that WSL 2 use are available to pretty much any Linux OS, with similar caveats and limitations.
Keep in mind that, as @UtkarshChandraSrivastava mentioned in this answer, WSL 2 really is running in a VM.
The distribution that is running inside WSL 2, however, is running in a namespace/container. Each running distribution has a different:
- PID namespace
- Mount namespace
- IPC namespace
- UTS namespace
- WSLg System Distribution
However, they all share the following with the parent WSL2 VM (and thus each other):
- User namespace
- Network namespace
- Cgroup namespace
- Device tree (other than
- CPU/Kernel/Memory/Swap (obviously)
/initbinary (but not process)
This is very similar to the way that Docker, Podman, and other container systems work. They may use slightly different configurations for the namespaces, but the core technology is typically the same.
So at a base level, you can reproduce much of what WSL2 does on Ubuntu using containers, be they Docker, Systemd-machined, Podman, or others. There's typically additional configuration needed to run a GUI (especially Desktop environment) in any of these scenarios, but it's also typically possible.
With that in place, you'll be able to check out a distribution's:
- Package manager
- Stock repositories
- Other features like AUR on Arch
- General configuration (stock shell startup files, etc.)
However, you may have difficulty with networking tools or desktop tools. Also, as with WSL2, the kernel inside the container will be the one from the host Ubuntu distribution, not anything specific to the distribution you are testing.
At a much simpler level than a container, of course, it's even possible to accomplish much of the same experience using a simple
chroot environment for a different distribution.
WSL-2 does use "lightweight utility virtual machine (VM)".
You will always need a VM to run different OS.
There is something better known as Multipass if you just need a shell to test different tools/distros.
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 (
/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
/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
/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.
In my opinion, you are looking for GNOME Boxes, which uses the cutting edge virtualization technologies as
qemu but makes the things easy.
Yes - it provides very limited configuration options, but literally said you can install a new operating systems in a virtual machine with about 5 clicks.
To install GNOME Boxes via
apt run the following commands:
sudo apt update sudo apt install gnome-boxes
Notes and references: