From the course: Advanced Linux: The Linux Kernel

Understanding the bootloader GRUB - CentOS Tutorial

From the course: Advanced Linux: The Linux Kernel

Start my 1-month free trial

Understanding the bootloader GRUB

- [Narrator] Booting, let's talk about booting. And to talk about booting we should talk about bootloaders. And if we going to talk about bootloaders for Linux; we should talk GRUB. GRUB is the most common bootloader for desktops and servers running Linux. Embedded Linux devices, like say an Android phone, might have a different bootloader. But even with a different bootloader, there's a lot of analogous things that a bootloader has to do just because it has to boot Linux. So what is GRUB's role? What's a bootloader's role? Well, when does it get run? For example, affects it's role. When you power on your computer, there's typically some sort of power-on self-test that's done that checks to make sure there's memory in the CPU and that sort of stuff. Looks good, and then it runs, say a BIOS, commonly. And then that BIOS will be configured to boot from something like disk, or your CD or a USB disc, right? So, here we're going to talk about booting from disc. So on disk in a special place where the BIOS can find it, will be some part of GRUB, the beginning of GRUB. Doesn't have to be all of GRUB. And the BIOS is going to load that in and start running it. Then GRUB, might have to load some more of itself in. But eventually, what GRUB's going to do is go out to your disc, like your boot directory, and read in the kernel file that's configured to run. Say a VMLINUZ file, and commonly for desktops and servers there will be a second file that GRUB will load in. An initial root file system. That's probably a RAM-based file system image. And that has slash, and bin, and netsy and so forth. But a very abbreviated version. It has, as a main role, getting other stuff started, so that your kernel is going to be able to use your real file system. So, usually there's one or more loadable models in there, like maybe file system drivers, that your kernel needs to be able to use your real file system. Once those are loaded, then the kernel will be able to continue on. So, GRUB loads those two files into memory. GRUB's got some sort of configuration; so it knows the kernel and what options to pass to the kernel. Including telling the kernel about where it put the initial root file system. All right. So it passes those things and it starts the kernel running. Well, GRUB is pretty powerful and it turns out, you can interrupt GRUB once it starts before it starts Linux. And you can get essentially a command prompt. And you can interact with GRUB and change how it's going to boot Linux. And even change which kernel it's going to boot and maybe even get a kernel over the network. So there's a lot of power possible with GRUB. And because GRUB has support for file systems; some earlier bootloaders didn't know about how to find a file in a file system by name, but GRUB has built-in support for a lot of Linux file systems. And you don't have to know the name of the kernel exactly. It can search for it. It can do file name completion, like the bash shell can. So you can say, I want a file that starts with VMLINUZ and hit the tab key, and it can help complete the name. So you don't have to memorize it; that could be handy. There's other utilities that go with GRUB. Some important ones, like what you need to do if you're going to change your GRUB configuration file. So you can find out about the commands related to GRUB by using the man -k grub command. That will list all the commands that have the keyword GRUB.

Contents