"Every beginning is difficult, but only the bravest reach for their power."
Greetings, young mages!
First of all, do not be intimidated by the amount of text in today's Chapter, but to turn an ordinary sorcerer into a true Witcher, one must acquire solid foundations, which is why at the beginning I will explain every spell and gesture in detail. Future meetings will not be as detailed in descriptions but more concise and focused on strategic spellcasting. To start your Linux adventure, follow these steps to prepare a bootable USB or CD for Gentoo Linux installation:
In Linux, USB block devices are located in the /dev/ directory and named sd.. followed by sequential letters - sda, sdb, sdc, etc...
As I hope you know, disks can be divided into partitions, but the physical device is the disk, not the partition. A partition is a logical device.
Partitions in Linux are numbered sequentially after the letter, for example:
/dev/sda1, /dev/sda2...
/dev/sdb1, /dev/sdb2... ..., /dev/sdb78
/dev/sdc
...
...
Graphically, it looks something like this:
The difference is that my disk is not connected to a serial bus (SATA and SCSI disks) but to a PCIe bus, so the system names them differently, usually "nvme", and the naming convention is similar:
nvme0n1p1 - the first partition of the first disk connected to the first controller (numbering starts from 0)
nvme1n1p5 - the fifth partition of the first disk connected to the second controller.
The downloaded ISO image is an image of a device (some data carrier on which someone previously prepared a bootable system). Bootable, meaning one from which you can start the computer.
When you restore (write) the downloaded ISO image, you restore the device image to another device - your USB drive. Your USB drive likely has one partition, and the system detects it as /dev/sda1. But since you are restoring the image of the entire device, you restore it to the entire device /dev/sda, not to the partition /dev/sda1.
How to check the name of your USB drive?
The easiest way is to look in the /dev directory - this is the directory where all system device files are located. We will discuss the /dev directory and the system tree later, but now you need to check which letter your USB drive has been assigned.
cd /dev
Remove the USB drive from the computer and go to the /dev directory. Here we learn the first command "cd" - change directory, which allows us to navigate between directories, and from now on it will be familiar to you.
ls -l sd*
The "ls" (list) spell displays the contents of a directory. This command (like most Linux commands) has parameters. You can see the list of parameters by typing ls --help. --help is a standard parameter, and if the program is not some punk invention written in a basement under a blanket, the --help parameter will work.ls -l sd*
And see which devices are visible in your system.
If you don't have any sd* devices, the command will display a message that there is no such file or directory.dd command in the terminal:
cd ~/Downloads
or cd ~/Desktop - just go to the directory where you downloaded the ISO.
Here are some more magical commands and gestures:
pwd
This command shows the current directory you are in.
TAB (press the tab key)
Check how the tab key works in bash - it is a very helpful gesture. Commands work better with a wand, and the shell works better with the tab key. The tab key "completes" or lists (casts the "ls" spell), which significantly speeds up work. For example:
cd /home/tom/Downloads - we go to the "Downloads" directory in the home directory of the user "tom"
ls - list the contents of the "Downloads" directory
==> here we see the list of items in Downloads and type the command:
dd if=[TAB] - press the tab key, and after pressing [TAB] we will see the result of the ls command, then continue typing:
dd if=ar[TAB] - press [TAB] again, and at this point, all files starting with "ar" will be displayed, and if there is only one, its name will be automatically inserted into the command line, and we will get something like this:
dd if=archlinux-2025.02.01-x86_64.iso - now we can continue typing the command:
dd if=archlinux-2025.02.01-x86_64.iso of=/dev/sdX bs=4M status=progress
We will discuss what the above commands mean later, but now we need a runtime environment, so for now, just open the terminal (the black window of black magic), insert your USB drive into the computer (i.e., into the USB port ;)), find its name, and type in the terminal what is below.
/dev/sdX with the name of your USB device, i.e., /dev/sda or /dev/sdb, c, d... sudo dd if="path and name of the downloaded ISO image" of=/dev/sdX bs=4M status=progress
F2, F9, F12, Del or Esc during startup). If you don't know, check online which key to press during startup to enter the BIOS.cd ~ - Go to the home directory
mkdir OOS - Create the OOS directory (or any other)
cd OOS - Enter the OOS directory
qemu-img create -f qcow2 gentoo.img 50G
You can also copy the downloaded ISO image to the same directory. In Windows, I assume you know how to do this. In Linux and Mac:
mv ~/Downloads/image.iso ~/OOS/(enter the correct path to the downloads directory and the ISO file name)
If you have created a hard disk image and downloaded the ISO image, you can start the environment to build your own black magic portal:
qemu-system-x86_64 -m 4G -smp 4 -enable-kvm -cpu host -drive file=gentoo.img -cdrom archlinux.iso -boot order=d -nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22 -display gtk,zoom-to-fit=on -vga virtio -usb -device usb-tablet -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/x64/OVMF_CODE.4m.fd -drive if=pflash,format=raw,file=/usr/share/OVMF/x64/OVMF_VARS.4m.fd
qemu-system-x86_64.exe -m 4G -smp 4 -cpu host -drive file=gentoo.img -cdrom archlinux.iso -boot order=d -nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22 -display gtk,zoom-to-fit=on -vga virtio -usb -device usb-tablet -drive if=pflash,format=raw,readonly=on,file="C:\Program Files\qemu\share\edk2-x86_64-secure-code.fd" -drive if=pflash,format=raw,file="C:\Program Files\qemu\share\edk2-x86_64-vars.fd"
qemu-system-x86_64: choose your CPU type. If your computer hardware is from Windows and is less than 15 years old, then 99% the option qemu-system-x86_64 is the right one for you. If you have older hardware with a 32-bit processor, choose qemu-system-i386. For older Macs with Intel processors, choose qemu-system-x86_64, for newer ones (with M2, M3, M4) choose qemu-system-aarch64 QEMU can emulate almost any available processor type, so choose the right one.
| Command / Option | Description |
|---|---|
| Linux | |
| qemu-system-x86_64 | Run QEMU in 64-bit mode. |
| -m 4G | Allocate 4GB of RAM. |
| -smp 4 | Set 4 CPU cores. |
| -enable-kvm | Use KVM for better performance. |
| -cpu host | Use the host's real CPU. |
| -drive file=disk.img,format=qcow2,if=virtio | Disk image `disk.img` in QCOW2 format with VirtIO interface. |
| -cdrom system.iso | ISO image `system.iso` as a CD-ROM drive. |
| -boot order=d | Boot first from CD-ROM. |
| -nic user,model=virtio-net-pci,hostfwd=tcp::2222-:22 | NAT network emulation with VirtIO driver, port forwarding 22 to 2222 localhost |
| -display gtk,zoom-to-fit=on | Run QEMU in a GTK window with automatic size adjustment. |
| -vga virtio | VirtIO graphics driver for better performance. |
| -usb -device usb-tablet | Improved mouse handling in the QEMU window. |
| -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/x64/OVMF_CODE.4m.fd -drive if=pflash,format=raw,file=/usr/share/OVMF/x64/OVMF_VARS.4m.fd |
UEFI BIOS firmware files |
| Windows | |
| qemu-system-x86_64.exe | Run QEMU in 64-bit mode on Windows. |
| -m 4G | Allocate 4GB of RAM. |
| -smp 4 | Set 4 CPU cores. |
| -cpu qemu64 | Use the emulated `qemu64` processor (better compatibility with Windows). |
| -drive file=disk.img,format=qcow2,if=ide | Disk image `disk.img` in QCOW2 format with IDE interface for better compatibility. |
| -cdrom system.iso | ISO image `system.iso` as a CD-ROM drive. |
| -boot order=d | Boot first from CD-ROM. |
| -netdev user,id=net0,hostfwd=tcp::2222-:22 | Create a network device in user mode, port forwarding 22 to 2222 localhost |
| -device e1000,netdev=net0 | Emulate an Intel e1000 network card. |
| -display sdl | Run QEMU in an SDL window (more compatible on Windows). |
| -vga std | Standard graphics driver for better compatibility. |
| -usb -device usb-tablet | Improved mouse handling in the QEMU window. |
| -drive if=pflash,format=raw,readonly=on,file="C:\Program Files\qemu\share\edk2-x86_64-secure-code.fd" -drive if=pflash,format=raw,file="C:\Program Files\qemu\share\edk2-x86_64-vars.fd" |
UEFI BIOS firmware files |
With the bootable drive ready, you are prepared to dive into the world of Linux. Let the adventure begin!
The Awakening of the Witchers
Witchers, after centuries of waiting, the time has come to rebuild the power of the Gray Beards.
Each of you, young mage, must understand that magic is built on solid foundations – Gentoo will become your shield and sword. You will decide how to wield the power of your system. Walk carefully but with confidence, for great spells begin with small incantations.
You have just stepped onto the path of the witcher's craft, but instead of potions and silver swords, you will delve into the secrets of operating systems. Your first challenge will be mastering Gentoo Linux, a system as wild and demanding as a cave troll. But do not fear! With the help of the sages of Kaer Morhen (that is, me and this book), you will uncover every secret of this system, from installation to kernel configuration. Remember, young adepts, that Gentoo is not a toy.
It is a powerful tool that, in the wrong hands, can cause more harm than good. Therefore, it is important to approach it with due caution and respect. Do not rush, read the instructions carefully, and do not hesitate to ask if you do not understand something. After all, even Geralt of Rivia was not born with knowledge of all the signs and potions. He had to learn them, just as you are now learning Linux. And when you master Gentoo, no system will scare you! You will be able to create your own configurations, optimize the system for your needs, and fix problems that are unsolvable for others. You will become true system witchers, ready to face any challenge.
.
The dot represents the current directory. Why? In Linux, sometimes you need to provide the full path to a file. If we are already in the directory where we want to execute a file, we don't need to type:
python /mnt/USB1/directory1/directory2/script.py
Instead, we write:
python ./script.py
..
Two dots represent the parent directory. It works similarly to a single dot. For example, if we need to copy a file from a directory two levels up, we can use the syntax:
cp ../../file.iso .
The above command copies file.iso from two levels up (../../) to the current location (.)
~
cat, head, hexdump.pwd
ls
cd
touch
mkdir
rm
cp
mv
hexdump
head
Linux is an open-source operating system that has gained popularity due to its flexibility, security, and stability. Its hierarchical file system structure allows for intuitive data management, and the variety of terminal tools makes it ideal for both servers and personal computers. Linux is designed to work in a network and functions like a network.
The /dev directory represents hardware devices as files, increasing flexibility in hardware management. Operators such as ".", "..", and "~" make navigating the file system easier. Imagine Linux as a vast continent, full of diverse lands, cities, and villages, with their own customs, languages, and cultures.
To travel freely across this continent, you must know its map – the directory tree and important files. At the top of this hierarchy is the root directory, denoted by "/". From there, all paths branch out to different corners of the system.
The Linux system tree is a collection of directories, each (conventionally) intended for something specific. Below is the tree and a brief description of the most important top-level folders.
/
|-/boot - location for boot files (boot loader, kernel)
|-/dev - device folder - sounds strange but will be explained shortly
|-/etc - folder for all system variables and configuration files
|-/home - folder for user home directories
|-/lib - location for system libraries
|-/mnt - mount point for resources
|-/opt - location for "alternative" libraries
|-/proc - a virtual file system that provides information about the system and running processes
|-/root - the system administrator has a special place here
|-/sys - a virtual file system that provides an interface for hardware management
|-/tmp - location for temporary files
|-/usr - contains most user programs and system libraries that are not essential for system boot
|-/var - short for "variable", location for data that changes frequently during system operation
The above description is superficial, and everything will be explained in the future, but the /dev directory deserves special attention.Probably most of you are accustomed to Windows drive letters like C:, D:,E:, etc. Probably no one remembers anymore that there were also A: and B:, which were reserved for floppy drives. The approach where the operating system is "tied" like a dog to a disk worked 30 years ago. And I know you might think I'm not objective because, in my opinion, a worse system than Windows has yet to appear. However, the worst thing about this system is the way Windows separates the software layer from the hardware layer. In Windows, you cannot remove the C: drive because the system runs on it. The user stores their files on it, so they must have administrator rights to write to the disk. They must also have administrator rights to send data to the sound card, network card, or graphics card. And if the user has administrator rights, it's a simple step into the abyss, with eyes closed, because any process run by the user, including viruses, can obtain these administrator rights. This system will never be secure because it is designed that way. It cannot be secure because it will not work. And that's the end of the debate about Windows security, and everything related to Windows security is patching holes with putty and duct tape, and it works until it starts leaking from another side.
Linux runs in RAM. When the computer starts, the BIOS is loaded first, which directly manages the hardware - it decides when to turn on the RAM, when to turn on the disks, wake up the processor, coprocessor, buses, etc. Then the BIOS looks for the boot partition (both Windows and Linux have such a partition) and from it runs the bootloader (also all x86 and x86_64 systems have bootloaders, but in Windows, the bootloader is hidden from the user, so they don't know what's happening in their computer). The bootloader, in turn, has the boot options of the system kernel with boot parameters written in its configuration file, for example:
linux (hd1,gpt1)/gentoo.img root=/dev/sda3
This roughly means: So, the BIOS loads the kernel into RAM, and in it, the directory tree and system files are created, and the entire operating system works in it. NOT ON THE HARD DRIVE. Therefore, Linux does not run on the disk but in the computer's operational memory. You can imagine it as a cargo airport, with a control tower where the kernel receives shipments (data) from a terminal (e.g., from the network), looks where they are addressed or addresses them, and directs them to the next terminal (e.g., to the disk), so they reach their destination.

This one small detail, that in Linux everything is a file, makes conquering the fortress that is the operating system a real challenge. Why?
In Linux, a process run by a user inherits the rights of that user (previously granted by the administrator), no more. So if the user has access to the printer file (/dev/lp0) and the cdrom file (/dev/cdrom), then the process run by the user (e.g., a CD burning program or text editor) also has these rights, and the user can print and burn CDs or listen to music. But in Linux, the hard drive is also a file in the system, the CPU is a file, the USB port is a file, everything is a file, and everything is in the /dev directory. And we can assign rights to files - read rights, write rights, change the owner and groups. So if the user "tom" downloads malicious software, they become its owner, and if the software requests access to any resource, the kernel checks what "tom" is allowed to do, and if "tom" does not belong to the group of users allowed to use the printer, it says "Tom, you are free in your own home". And that is what solidifies our fortress.
/
|-/dev
| |-sda
| | |-sda1
| | |-sda2
| | |-sda3
| | |-sda4
| |-sdb
| |-sdb1
| |-sdb2
|-/home
|-tom
|-not_tom
For example, the user "tom" (since Linux is case-sensitive, it is customary to use lowercase letters in user names) can be denied write access to the device /dev/sda1. They can also be denied write access anywhere in the system except the /home/tom folder. And since every process run by the user inherits their rights, no virus will have write access anywhere except the user's home directory, and even if their folder is full of viruses, the system is safe. And by deleting the user's directory, we get rid of all the junk in the system.
However, any system can be ruined, and while Windows security is based on patching holes, in Linux, the system is secure, but a talented administrator can effectively change that ;).
| 🔍 Feature | 🪟 Windows | 🐧 Linux |
|---|---|---|
| Popularity among hackers | 🎯 High – a big target | 🔍 Lower |
| Source code | ❌ Closed – less audited | ✅ Open – more eyes on bugs |
| Automatic application startup | ❌ Possible | ✅ Requires granting permissions |
| Drivers | ❌ External – potential vulnerabilities | ✅ Built into the kernel |
| Permissions | ❌ Easy to bypass (UAC) | ✅ Good user separation |
| Hardware access | ❌ Complicated API | ✅ "Everything is a file" |