9

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?

12
  • 1
    Are you asking how to do this in Ubuntu, or on Linux in general? If you 're asking for linux in general, we're going to redirect you to unix.stackexchange.com because this site is for Ubuntu only.
    – Thomas Ward
    Dec 7, 2022 at 2:42
  • 1
    @Thomas Ward first of all for Ubuntu.
    – Ya Y
    Dec 7, 2022 at 2:47
  • 8
    "you can try different distros as an application" - eh, not really... WSL still doesn't officially support desktop environments and has only limited support for GUI applications. I would not consider WSL to be a useful method to try different Linux distributions.
    – Nmath
    Dec 7, 2022 at 3:56
  • 3
    It sounds like you're asking if there's a sort of "Linux Subsystem for Linux," right? Dec 7, 2022 at 12:04
  • 7
    "no virtual machine needed" isn't really true either; since WSL2 it's just running on a behind-the-scenes Hyper-V platform.
    – Esther
    Dec 7, 2022 at 17:15

5 Answers 5

26

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 /dev/pts)
  • CPU/Kernel/Memory/Swap (obviously)
  • /init binary (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.

19

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.

8
  • 4
    WSL2 does use vm. WSL1 does not.
    – Dan M.
    Dec 7, 2022 at 14:13
  • 2
    @DanM. Yep because WSL1 did not have proper linux kernel behind it was just an compatibility layer for running Linux binary executables. Dec 7, 2022 at 15:18
  • 2
    I guess it depends what you call an OS, but technically you need a VM to run a different kernel. Everything else can run in a container without virtualization. Does it count as running a different OS when you run Alpine in docker on Ubuntu?
    – Didier L
    Dec 7, 2022 at 16:50
  • 1
    @UtkarshChandraSrivastava Congrats on the Mortarboard! Dec 7, 2022 at 17:51
  • WSL2 does use "lightweight utility virtual machine (VM)" would be correct, but WSL does use "lightweight utility virtual machine (VM)" is absolutely not
    – phuclv
    Dec 8, 2022 at 1:06
6

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.

2
  • Likely a stupid question - (a) because I'm going from memory, (b) that may be impaired from lack of sleep at the moment, and (c) I know you know your stuff. But, I was thinking you could use a bind mount (IIRC, most of which I learned about through your answer on the topic here or U&L) to give the chroot access to the host /home, /proc, and /dev? Or is that just how Schroot handles it for you? Dec 8, 2022 at 23:05
  • 1
    @NotTheDr01ds Not a stupid question at all! You can indeed use a bind mount. And that's what schroot does. It takes care of knowing what bind mounts are needed (and that's configurable), and of unmounting when the schroot session ends. Dec 9, 2022 at 12:20
4

In my opinion, you are looking for GNOME Boxes, which uses the cutting edge virtualization technologies as libvirt, libosinfo and qemu but makes the things easy.

enter image description here

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:

1
  • 1
    Hello, @Quasímodo. If you read the other answers you will see the current version of WSL uses a virtual machine, so that premise is based on a lack of knowledge. On the other hand, GNOME Boxes requires the same level of hardware and the same amount of knowledge like WSL, so I decide to focus on and give a clue about that part: ...you can try different distros... Is there something like that on Linux? I really do like the other answers and already up-voted them, but I do not believe the OP will find them (especially all tech details) as much useful while they asking such question.
    – pa4080
    Dec 9, 2022 at 7:09
-2

At school we use Docker. It's container based, so no VM's required, and it's even better than WSL2 in that aspect (WSL2 uses hidden VM). It only supports cmd though afaik

Not the answer you're looking for? Browse other questions tagged or ask your own question.