Linux: Manage chroot Environments with Atoms
Ask any old-school Linux user about chroot environments and they’ll either nod in the understanding of what the tool offers or turn away, so you can’t see the fear in their eyes.
Although that might be a bit hyperbolic, creating chroot environments isn’t exactly the easiest thing to do from the command line.
But wait… what are chroot environments?
What Are chroot Environments?
Essentially, chroot environments create isolated, virtualized copies of a software system that can be used for testing or development, without harming your host operating system. These environments are a great option for testing things that pose any kind of risk to a production machine.
Traditionally, chroot environments have been created via the command line, which can be a bit complicated. Fortunately, there’s a GUI tool available that makes managing chroot environments much easier.
That app is called Atoms and it allows you to create, manage, and use chroot environments. Atoms currently supports the following Linux images:
- Alpine Linux
- Alma Linux
With Atoms, you can easily select which distribution (as well as the release) image you want your environment to use. Once you’ve created your environment, you can access it, do whatever you need to do, and then exit it, knowing that whatever you did within the environment didn’t harm your host OS.
Think of Atoms as yet another user-friendly means of creating virtualized environments without making any changes to your production file system.
Let me show you how to install Atoms and then we’ll create our first chroot environment.
How to Install Atoms
To work with Atoms, you’ll need a Linux distribution that supports Flatpak. You won’t find Atoms as a .deb or .rpm package, nor is it available via Snap. So if you’re current Linux OS doesn’t have Flatpak installed, you’ll need to install that first. Distributions such as Fedora ship with Flatpak pre-installed. For Ubuntu-based distributions, you can install Flatpak with a command like:
sudo apt-get install flatpak -y
If you are only now installing Flatpak, you’ll need to set it up before it can install apps from Flathub. To do that, make sure to issue the following command (after Flatpak is installed):
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
Once you’ve done that, restart your system so the changes take effect.
The installation of Atoms is very simple. Open your terminal window and issue the following command:
flatpak install flathub pm.mirko.Atoms
Make sure to answer y to all the questions. After the installation completes, you can either log in and log out (so the Atoms launcher will be added to your desktop menu) or run Atoms immediately with the command:
flatpak run pm.mirko.Atoms
When Atoms first launches, you’ll see the Create New Atom button (Figure 1).
The Atoms app at first run doesn’t include any chroot environments.
Create Your First chroot Environment (aka Atom)
Click Create New Atom and, in the resulting pop-up (Figure 2), you’ll be required to name the atom, select a distribution to use as the base image, and then select the release version of the chosen distribution. You might find, with certain distributions, that you are limited to only the latest release.
After configuring your new Atom, click Create and the app will do its thing. When the process completes (which should take less than a minute), close the pop-up window and you’ll see your atom listed.
Using Your New Atom
From the Dashboard tab, click the entry for your new Atom and you’ll see entries for Browse Files, Details, Bindings, and Destructive Actions (Figure 3).
If you click Browse Files, it will mount the environment and open your file manager, so you can navigate around the file system hierarchy. The real work, however, happens in the Console tab.
Click the Console tab and you’ll find yourself at the root prompt for your environment, where you can start testing, developing, and whatever you need (Figure 4).
One thing to keep in mind is that a chroot environment isn’t 100% analogous to either a virtual machine or a bare metal installation. You’ll run into trouble when installing applications such as Docker, Podman, Apache2, etc.
However, what you can do is, from the Dashboard, click Browse files and then, using your file manager, copy and paste your source/scripts into the required directory and work from there. Using that same method, you can create new directories. You might also find permissions issues, so you’ll want to drop to the console and create a new user like so:
useradd -m USERNAME
Where USERNAME is the username to add.
Then, give that user a password with the command:
You can then change to that user with the command:
At this point, you will have permission to write to the new user’s home directory (change into with the cd command).
When you’re done using the Atom, you can click the left-pointing arrow at the top left of the Dashboard tab. If you no longer need the Atom, click Destructive Actions in the Dashboard, and then click Destroy Atom.
Atoms is a great way to quickly create chroot environments. It may take you a while to get up to speed on using them, but at least the hard part is taken care of. Add chroot environments, by way of Atom, to your development/testing process and see if they don’t make your life a bit easier (and less destructive to your production systems).