Boot loader’s job is to start the kernel – that is, to load the kernel into memory and start the kernel with a set of kernel parameters. (Ward, 2014) Kernel parameters are text-based parameters that tell the kernel about how it should start. Boot loader also selects among multiple kernels, switches between sets of kernel parameters, allows users to meddle with the kernel parameters and kernel images and provides support for booting other operating systems.
One of the most popular boot loaders is GRUB, short for Grand Unified Boot Loader. So, if you ever see some errors related to GRUB, you now know: “Oh, it’s my boot loader that’s the problem”.
To be honest, I never had to deal with boot loader problems, but I imagine they must be bad. May the force of Google help you in your quest to resolve those.
Thank you for reading!
Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 97-98
Today we will talk about how your computer boots up (or, equivalently, how does it start up). We will look at the first steps your computer executes when you turn it on. This will be important to understand if you ever encounter a boot-time problem. Of course, you will use Google, but having context as to what is actually happening will prove really valuable.
Your computer boots up in the following sequence of steps: (Ward, 2014)
A boot loader is ran by machine’s BIOS or boot firmware
The boot loader finds the kernel image on disk, loads it into memory, and starts it
The kernel initializes the hardware devices and its drivers
The kernel mounts the root filesystem
The kernel starts a program called init; init has PID equal to 1
init starts all of the other necessary system processes
At some point at or near the end of this entire process, you get the option to log in to your system
Let’s clarify some terms here. Let’s go one by one:
What is BIOS? BIOS stands for Basic Input/Output System and it is used to check for hardware errors andrun the boot loader. (“BIOS,” n.d.) Think of BIOS as the starting point of your computer; when you turn your computer on, it checks if all the hardware is OK and if it is, it runs the boot loader. Instead of BIOS, you can have other boot firmware (such as UEFI – Unified Extensible Firmware Interface (“Unified Extensible Firmware Interface,” n.d.)), but its job remains the same – check the hardware, if that’s OK, run the boot loader.
What is the boot loader? The boot loader is a small program whose task is to find the kernel image on disk, load it into memory and start it. (Ward, 2014). We will talk more about boot loaders in another post, but they are a small, albeit a critical piece of code which loads the kernel.
To review, the kernel is the “core” of the operating system and the root filesystem is the hierarchical filesystem starting from the root folder (/).
What is init? init is a special process whose task is to start all of the other necessary system processes and init has a PID of 1. We will also talk more about init in another post (or posts).
I think we clarified all of the terms present in this article.
A caveat for the those of you who are interested in the nitty-gritty details: initramfs can be used to mount the root filesystem.When the kernel image gets loaded by the boot loader, the kernel can mount initramfs, if it exists. This is an advanced Linux detail, but I just wanted to mention it here. More information can be found in (“About initramfs,” n.d.).
In this post, I will devote a few sentences to device-related topics that, in my opinion, aren’t that important. Don’t get me wrong, you could write a couple of posts on each one of these topics, but they are not that important in your everyday use. Even though you will most likely never do anything with the information presented in this post, it does paint the picture of the Linux operating system and thus I decided to write up a few sentences on each of the topics I thought warranted it. My 2 cents would be: Read through the contents of those posts once, know that these things exist and if you ever need them, use Google to find exactly what you need for your particular purpose. The references are listed in the order in which the topics appear.
Partitioning disk devices
You can partition (and re-partition) your permanent storage devices from the command line. Although I never had the need to do this (except when I was installing my operating system), you maybe might, and that’s when you can call the big ol’ Google for help. Just know that you can do this.
df and free
The df command tells you how much free space you have on your disk drive. The free command displays the amount of free memory (RAM and swap). (Shotts, 2019)
Filesystem 1K-blocks Used Available Use% Mounted on
sysfs provides a uniform view for attached devices based on their actual hardware attributes. (Ward, 2014)
You can go to /sys/devices to see all the devices. It differs from the /dev directory because /dev is designed for interacting with devices, while sysfs is designed to view device information and manage the device.
The lsof command lists open files and the processes using them. By files, I mean both regular files and files that represent other non-files, such as network resources. (Ward, 2014)
udev is a device manager for the Linux kernel. (“udev,” n.d.)
udev manages devices nodes in the /dev directory and also handles all user space events raised when hardware devices are added or removed from the system. Term clarification: user space is the space of the user (different from the kernel space, which only the kernel can access) and you can think of events as messages that are sent when certain actions happen on the system.
UUID, short for Universally Unique Identifier, is a type of serial number used to identify filesystems. (Ward, 2014)
Displaying a list of mounted filesystems
To display a list of mounted filesystems, use the mount command without any arguments. (Shotts, 2019)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=4001344k,nr_inodes=1000336,mode=755)
The format of the listing is as follows: device on mount_point type filesystem_type (options) .
In order to repair a filesystem, you will most likely use a program called fsck. fsck stands for “file system check”. If you encounter this, you are dealing with a bad problem. May the force of Google and good luck be with you in resolving it!
What the fsck?
As I said in the last post, if you ever encounter fsck, that means that you are dealing with a bad issue with your filesystem. Therefore, people sometimes utter the words: “What the fsck?” when dealing with fsck. (Shotts, 2019)
/etc/fstab lists the devices to be mounted at the time the computer starts (also known as boot time). (Shotts, 2019)
Here is my /etc/fstab file:
mislav@mislavovo-racunalo:~$ cat /etc/fstab
# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
The rows that begin with a # are comments and are to be ignored. The first column is the device (identified by its UUID), the second is the mount point, the third is the file system type, the fourth is the options, the fifth specifies if and when a filesystem is to be backed up with the dump command and the sixth is the order in which filesystems should be checked with the fsck command (they are checked at boot (computer start up) time).
md5sum – What is it used for?
Let’s talk about something that you may encounter sometime. It’s the md5sum command. md5sum is a hash function.
Hash functions are relevant because for different inputs they produce different outputs. Even a slight difference in the input will produce massively different output. You can, for example, use the md5sum command to verify that your file is the same file on the website available for download by calculating the md5sum of your file with the md5sum command and comparing it to the md5sum of the original file (available somewhere on the website where you downloaded the file). If those two match, you can be very confident that you have the same file. If those two do not match, then you have a different file than the original.
When you attach a new device to your machine, it is most likely automatically mounted (at least it is on my Debian 10). However, when you want to stop using the device, it is always a good idea to right click on it (in the GUI) and press something along the lines of “Safely remove device”. Why is it so?
You see, in operating systems, there are these things called buffers. Think of buffers like this. Let’s say you were transporting a bunch of wooden planks. The guy who has the truck to transport it comes to your driveway, takes all the planks at your driveway and drives them to the destination. The problem is that it takes a very long time for the driver to go from your house to the destination. So, if you were to carry planks on a plank-by-plank basis and you always waited for the driver with only one plank in your hands, the job would take a very, very long time. But, you can carry planks on the driveway and once the driver arrives, he picks up all the planks on the driveway and drives them to the destination. In this analogy, your driveway is the buffer.
This driving wooden planks analogy can be used to explain writing data to an attached device (such as an USB or an external hard drive). Your operating system has a buffer to which it writes the data and then it writes the data from the buffer to your external device, because data can be written much faster from your operating system to the buffer than from the buffer to your external device. The buffer exists to equalize the speed difference.
So now we come to the reason why unmounting is important – unmounting makes sure that all of the data in the buffer is written to the external device. This happens, again, because writing to the buffer is a lot faster than it is to transfer data from the buffer to an external device.
In today’s Linux distributions, mounting is usually done automatically. I never had to mount anything manually on my personal computer. However, sometimes you will have to mount something (or a tutorial will ask you to do so), so here is how it is done:
mount -t type device mountpoint
As we can see, it is done with the mount where type is the filesystem type (ex4, FAT, NTFS, …), device is the device file (remember the /dev folder discussion) and the mountpoint is the point in our Linux directory structure where we want to place the device (the device’s storage). (Ward, 2014)
Now you know how to mount a device. Again, you will rarely ever do this, but when you do, you know what you’re doing and what each of those arguments to the mount command mean. Sounds like you had a great Linux teacher!
Thank you for reading!
Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Page 76
Today we will talk about something more conceptual yet again. I know that you might be thinking: “Why this conceptual stuff again? It’s been a lot of that lately and I’m tired of that…”. I get it. But be patient – this knowledge will pay off. I am trimming the fat – the things you don’t need to know – but it pays to know these particular concepts. Especially mounting and unmounting because even though you’ll probably never do those manually, there will be some situations where you will have to mount or unmount (an example – “burning” an operating system on an USB) and you have to know what is going on.
Still with me? Good. So what is mounting? Mounting is the process of attaching your device(your device’s storage)in the Linux directory structure. As we know, everything in Linux starts from the root folder (/). Every other directory is accessible from the root folder by navigating from the root folder to the other folders hierarchically below it. When you insert a new device (say, a USB drive) you have to place it in a directory so that it is accessible from the root directory. The directory in which the new device resides is called its mount point. That process (when you assign a directory accessible from the root folder to a new device) is called mounting. Unmounting is the reverse process from mounting – removing the association between a directory in the directory hierarchy and the device (device’s storage).
So basically, when you mount, you make your device’s storage accessible to your Linux computer and when you unmount, you make your device’s storage inaccessible. Not all devices that are mounted need to have storage, but that doesn’t matter for our practical applications. (“What is meant by mounting a device in Linux?,” n.d.)
I modeled my explanation after (“understanding ‘mount’ as a concept in the OS [duplicate],” n.d.) , which you can read as well for a second perspective.