📜 ⬆️ ⬇️

Simplify building Linux from sources using the UmVirt LFS Packages site

Perhaps many of the users of GNU / Linux in the light of recent initiatives by the authorities to create a "sovereign" Internet were puzzled to insure against the inaccessibility of the repositories of popular GNU / Linux distributions.

Someone who downloads CentOS, Ubuntu, Debian repositories, someone builds their distributions based on the available distributions, and someone armed with LFS (Linux From Scratch) and BLFS (Beyond Linux From Scratch) books has already started to compile their distributions from the source as believes that under the conditions of a “sovereign” Internet, hacker attacks, virus outbreaks, data leaks will necessarily occur, and the binaries will simply become obsolete in some time.

Recently got around to fully compile a virtual machine from source, based on the instructions outlined in the book Linux From Scratch Systemd Edition v.8.3. I hasten to share the results with you.

Linux build process


The process of building Linux from sources can be divided into three stages:
')
  1. Based on the current operating system, the LFS build environment is built.
  2. The build environment will assemble an image of the LFS virtual machine.
  3. In the virtual machine, additional packages from the BLFS book are installed that are not in the LFS book.

Static script files


In the process of working with the build environment, it is convenient to use the clipboard and SSH: I copied commands from the booklet and pasted them into the build environment console.

After starting the created virtual machine, serious problems appeared. Unlike the terminal window, it is impossible to insert the code into the virtual machine client window. Typing keyboard commands is inconvenient and there is a risk of typos. The danger of typos is that they can not appear immediately, but after a while and lead to serious problems.

It is known that commands can be entered not only from the keyboard but also from the standard stream (STDIN). The source of the standard stream can use the serial port as well as the result of the script program operation, the so-called standard output (STDOUT).

Many people know that the wget command can output the contents of the loaded file standard output (STDOUT):

wget http://example.com -O - 

If the output of the wget command is sent to the interpreter, you can execute arbitrary code. The code will be executed as if it were typed on the keyboard or copied from the clipboard:

 wget http://umvirt.com/linux/helloworld.sh -O - | bash 

Thus, you can place files with commands on any Web server and send their contents to the interpreter.

Dynamic Script Files


Static files in a thing are certainly good if you know exactly what needs to be done, and if the package is being installed, if the dependencies are not clearly established or not, then what?

A dynamic website comes to the rescue based on the LAMP Web server (Linux-Apache-MySQL-PHP). If the site can dynamically generate pages (HTML files) and images, it should be a bit more difficult for ordinary text files.

So it turned out. Wrote a site UmVirt LFS Packages that generates scripts for the Bash interpreter. The site database contains information about packages, dependencies, patches, add-ons and build commands.

Now to install the mc (midnight commander) package, you can write the command:

 wget --no-check-cerificate https://umvirt.com/linux/packages/0.1/mc/install -O - | bash 

The site script itself will receive data from the database and generate the dependency checking code and the script code for installing the package. The interpreter will process the instructions from the script.

To make this possible, information about installed packages is stored in a database in a virtual machine disk.

The database of installed packages is located in the / var / cache / ulfs-packages directory and is a list of empty files with names corresponding to the package names.

If the package is not found in the database, recursive dependency installation occurs.

Facilities


To make the installation of packages more convenient, one more UmVirt LFS Assistant website has written the chimp script, which uses the UmVirt LFS Packages database. The main task of UmVirt LFS Assistant is the execution of other commands.

Using chimp, installing packages is even easier:

 chimp install mc 

Demonstration


To familiarize yourself with the work of the UmVirt LFS Packages and UmVirt LFS Assistant services, you can download the base image Initial UmVirt LFS v.0.1 Update 1 . Install Horg by executing one command:

 chimp install X 

During the script operation, 141 packages will be automatically installed. To save compile time, you can replace the value in the / etc / profile file with the variable MAKEFLAGS with "-j1" (one stream), for example, "-j6" (six streams).

Decentralization and customization


For security, autonomy, and customization purposes, the source code for the UmVirt LFS Packages and UmVirt LFS Assistant services is publicly available. Anyone can download it, deploy and correct services within its infrastructure.

Source: https://habr.com/ru/post/445178/


All Articles