Using multiple GNU/Linux at the same time-Bedrock Linux
Published: 2021-07-30 12:55:47

Hello, in this article, I will talk about Bedrock Linux, which is a daemon that allows to use software packages from more than one package manager, while also installing and using multiple distributions in layers. Although it is described as a separate Linux distribution, we can say that it is a daemon that connects the distributions installed to the root directory and then installed in layers, to the root directory. This is a system that allows to use multiple different software packages together with a very useful and customizable architecture.

In order to understand this architecture, I will first talk about the linux system hierarchy. Next, I'll review the bedrock Linux hierarchy and simply explain how to install and use it.

### Linux System Hierarchy

Linux is an operating system kernel with a Unix-like design. The kernel is designed by Linus Torvalds and is still developing it as open source. The latest kernel version is Linux 5.14. and available at the link. Linus Torvalds also owns the git project, a source code management and version control software. Named in 1991, this monolithic kernel is widely used in operating systems used by supercomputers, personal or mobile devices. For example, Android, Debian, RHEL(Red Hat Enterprise Linux), CentOS are examples of GNU/Linux distributions. Especially Debian and Debian-based distributions, RHEL and RHEL-based distributions are frequently used as server operating systems.
Linux and Unix are monolithic kernels. Monolithic kernels occupy a larger area than microkernels. Essentially, operating systems using Monolithic kernels run all operating system functions in "kernel mode", that is, kernel space. Each process is in separate address spaces. Kernel and OS services are in the same address space. Processes can request service from the kernel. This creates a layer of security between the kernel and applications. It also provides high speed as there will be no message traffic. However, a change to the kernel requires recompilation and the kernel code can become quite complex. In systems using microkernel, "kernel mode" takes up less space. System services such as the file system, virtual memory manager, and CPU scheduler are in the "user mode" area on the kernel, and each has its own address space. Applications also have their own address space. Such cores are customizable and easily expandable. In Microkernel, a fault in a component does not affect the whole system thanks to the system architecture. In this respect, we can describe this architecture as durable. However, in case of an error in monolithic systems, the whole system will be affected because the services are interconnected. But it has a clear advantage over monolithic architecture in terms of speed. Examples of microkernels are symbian, minix, GNU. Most Linux distributions are not actually a Linux project, but rather a GNU project. Because linux is just a kernel and it makes up a very small part of the whole system. Hybrid architectures, on the other hand, are a combination of the good features of monolithic and microkernels, thereby reducing weaknesses. They keep more code in the kernel space. Communication units and many drivers are embedded in the kernel area. However, when a new component is added, it does not require recompilation as in monolithic architecture. For example, Darwin and macos kernel XNU, BSD-based freeBSD, windows NT are coded in this architecture. Modern operating systems prefer this architecture.
 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20g5ipx99ugostjyktbi.png)

__source__ : [wikipedia](https://en.wikipedia.org/wiki/Monolithic_kernel)

#### Init System

It is the ancestor process on a GNU/Linux system. It takes 1 as pid and after the kernel is loaded, it is decided which runlevel the system will start with by checking the runlevels in /etc/inittab in modes such as windows or safemod that we are used to from macos. Runlevels can be seen in the figure below. As seen in the inittab file in Centos7 system, 0 halt, 1 single usermode, 2 multiuser etc. is being used. 3, ie Full multiuser mode, is used by default as initdefault. After init is started, other processes are started in the appropriate order and in the mode used under /etc/rc.d/init.d. For example, udev , apache, preload services can be started after init. This is used like /etc/rc.d/init.d/init3.d/S100preload. init3.d is in 3rd mode and S100 indicates that preload will be started in 100th order.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bip1tkh9kzezqnrbiati.png)
 
This structure is not preferred in today's GNU/Linux distributions. In most of them, systemd, which was written in 2010, comes by default. It is also used in new generation structures such as runit, OpenRC, Upstart. The old build is the SysV init system. In new structures, there are features such as starting processes in parallel, automatically starting the process that a process needs, automatic restarting if the process terminates. Systemd is a slightly slower init system than others. The system with the fastest boot time among them is Runit and it is cross platform. Available on GNU/linux, Solaris, Macos X.

####File System and Directory Hiearchy

The file system is a markup structure on the disk that allows the operating system to find the file. GNU/Linux distributions usually use ext2–3–4 journaling systems. It can also find file traces on NTFS, the windows file system. Everything is a file and designed in a hierarchical order in directories. Files, drivers, executables, libraries are located in these directories. This directory structure can be seen in the figure below.
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ye60yom2xkt68spmmfyt.png)

In normal use, we can say that the most used directories are /var, /lib, /usr and /home. In addition, directories branch themselves into trees. For example, the /usr directory contains the /usr/bin directory with binary files. Or the directory /var/lib is available under /var. __/bin__ directory is loaded at boot and contains basic commands. __/sbin__ contains binary files that provide system information or make changes. __/lib__ contains shared libraries, __/media__ contains removable disks, __/mnt__ contains new mounted filesystem, __/var__ contains variables. The __/home__ directory contains users' private files. __/etc__ contains configuration files. The __/boot__ directory contains the bootloader and some core files, such as grub, lilo, related to system boot. These directories can be divided into different partitions and connected to the system. This is a widely used method. For example, when the home directory is installed on a partition separate from root, the programs installed in the users' files and user directory are not deleted when the system is reinstalled or a different GNU/Linux distribution is installed. Bedrock Linux designers have developed a different model on this hierarchy.
 
### Bedrock Linux

Bedrock Linux is a productivity-oriented daemon that aims to use modules from many distributions, defined as a meta-distribution, together in a single operating system. In other words, you can work on debian and use pacman or AUR package managers and packages from arch linux. You can use libraries in different operating systems and fonts installed in different systems for different programming. This system also has some bugs. It is currently progressing above 0.7 poki minor. In addition, it cannot be said that it is security-oriented. This system is very useful for users who want to benefit from the power of not only a single system, but also many systems, and who want to use more than one package manager, different packages or different init systems at the same time. You can check it from the [link](https://bedrocklinux.org/index.html). 

The system is very simple to use. Once the Strata concept is well understood, it is quite easy to adapt for an advanced user. After a shell script is downloaded from Github, it is started as root and you will be asked to confirm the action you want to do, as a warning that the actions cannot be reversed. It then takes the distribution in your root directory and moves it to a stata under /bedrock. You can integrate other distributions into your system with the __brl__ command. You can also configure your system in bedrock.conf file. It is located under /etc/becrock. __brl apply__ is used to apply the changes. Community side usage rates are given on the official page of Bedrock linux ([link](https://bedrocklinux.org/0.7/distro-compatibility.html)). Generally, you have a low error rate for frequently used distributions. For example debian,ubuntu,centos,arch are used quite often and there are no known problems. But many problems have been reported in different distributions such as clear linux, nixOS. The concept of Strata will be discussed in the next section.

####Strata

Bedrock installs each distribution on one layer, establishing a communication bridge between them and providing the appropriate environment for other inter-use.

``` bash
$ brl fetch --list
```
With the command, distributions that can be used as stratum can be seen.

```bash
$ brl fetch void
```
With this command void linux startum can be created. It has the void linux runit init system. When Bedrock init interface comes, you can see it as void:runit.
```bash
$ strat -r debian neofetch
```
When the command is used, the neofetch package in debian stratum will run and see debian as the root directory. It outputs debian as os-release. But when neofetch is used directly, bedrock linux will be seen as os-release. Occurs when build tools scan the environment and find dependencies from different distributions. In case of confusion due to the bedrock environment like this, inter layer hooks can be bypassed using the __restrick -r__ parameter. If you are using two distributions with the same package manager, for example apt and rpm are the most used package managers, then you can start ubuntu as apt. Such an application may be needed because the source repos are different.

If a package exists in more than one startum then it will be executed in “pinned” stratum. You can check this with __brl which__ . All layers can see /run , /temp , /home directories as global file path.

You can enable-disable some stratums if needed. You can use the __brl enable/disable__ command. You can use the __brl remove -d__ command to delete Stratum directly.

```bash
$ brl remove -d fedora
```

#### Installation, Use and Review

In this section, some topics such as how to create and configure some startums by installing bedrock on ubuntu-based virtual linux lite in virtualbox, how to install package software will be explained. You can choose in a different distribution. In particular, distributions that have not undergone major changes based on common or frequently used distributions can run smoothly. For installation, you can download the script suitable for the CPU architecture from the link. First of all, daemon installation should be done by running bedrock shell script as root user.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bgknqwgs8b4ea82si4z.png)
 
“Not reversable!” By typing you agree to these terms and installation begins. Before the installation, the os in the root is taken to a temporary location. Then bedrock is installed on root and the os in the temporary location is installed in a layer. After the process is finished, you can see the init selection textmode interface with reboot.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zvldwsqq7fyuwy69jiqw.png)
 
Here, the system is booted from the system marked with "*". /sbin/init points to /usr/lib/systemd/systemd here. Systemd services are started and system boot is provided. When ubuntu is booted, processes named crossfs and etcfs are file systems for moving files, libraries, fonts between layer boundaries. In addition, the paths containing the stratum binary files are added to the PATH variable. This way bash or any shell

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvi22k93jmb0q1xxa1to.png)
 
I am installing the neofetch package on Ubuntu. You can install it from the ubuntu apt repos. Then, when I use the neofetch command, the base system appears as bedrock. To run neofetch in Ubuntu startum.

```bash
$ strat -r ubuntu neofetch
```
command should be used. With restrict cross-startum hooks are disabled. This way neofetch will only work in ubuntu stratum.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93jgn2d8zqiwcnrivrhb.png)

To create another startum,
```bash
$ brl fetch --list 
alpine
arch
...
...
$ brl fecth void
``` 

You can check the distros out with the command. Then it is downloaded and installed from stratum mirror with __brl fetch__. For example, for void linux using runit, after the packages are pulled, void can be seen in the init menu. When __strat -r void neofect__ is run again, it will warn that the package is not present. Because there are no hooks in between, it cannot reach the neofetch package in ubuntu startum. In this stratum, the package is installed and run with __sudo xbps-install neofetch__.

There are both ubuntu and void startums in the system. Here the xbps package manager and apt package manager can be used jointly. E.g

```bash
$ sudo xbps-install filezilla 
```
via this command , Filezilla can be installed and run in ubuntu stratum. The opposite is also true. For example, in Arch linux startum, you can install a package from AUR packages and access it from other startums. For this, git can be installed with pacman and the spring helper software can be installed from the github repo. With __yay -Sy brave__ a package belonging to arch stratum can be used by all stratums.

![filezilla on void stratum ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e557bb5c3589ofhq0lal.gif)

In the next system startup, there are three options for init selection. Besides arch and ubuntu using systemd, void linux uninit system using runit can be used.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ianxoi2qryi9ylzgjf49.png)
 
System-related settings can be made in the __bedrock.conf__ file. For example, the default init can be changed, the timeout period can be shortened, the directory where the fonts are located or the priority settings between the stratums can be made. Mirror servers can be changed for __"brl fetch"__. For detailed information, you can use this [link](https://bedrocklinux.org/0.7/configuration.html).

This system is completely productivity-oriented. There may be some security related problems.The official page has some answers for those who have security concerns.
However, if security is at the forefront for you and the features of multiple distributions are desired to be used together, it is more appropriate to use distributions such as Qubes.Qubes virtualizes each OS to the next level. It is a system that aims to provide security through isolation. It recommends Whonix by default, but you can also install windows or fedora, debian. Safety and productivity/speed are two conflicting concepts here. I think this distro is a meta distro to be used by distro-hoopers after major 1.0.0 release. Even this version is free from many problems and lives a very stable user experience.