4

What Is GRUB in Linux?

 1 year ago
source link: https://www.codecademy.com/resources/blog/grub-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

If you use Linux, you may have seen the GRUB screen once or twice. The title will say “GNU GRUB” in all capital letters and give you some options to choose from when booting up. This is the GRUB menu interface, and it’s an important part of the boot process in Linux operating systems.

If you haven’t seen this screen before and use Linux often, you should still know what GRUB is. Ahead, we’ll look at what GRUB is, how it’s installed, its boot process, and more.

What is GRUB?

GRUB is the program on Linux systems that loads and manages the boot process. There are a few different boot loaders for Linux (like GRUB, LILO, and SYSLINUX), but GRUB is the most popular — and one of the few still being maintained.

When your Linux operating system starts up, GRUB is the first program that runs. It loads the kernel of the operating system, and then the kernel loads the rest of the operating system, including the shell, the desktop environment, and other operating system features.

GRUB is also a boot manager. The boot loader is the part of GRUB that loads the kernel of the operating system into memory. The boot manager part of GRUB is the menu that allows you to select different operating system kernels to load.

GRUB supports Logical Block Addressing Mode (LBA), which translates the system’s directory and file structure into the format used by the hard drives on the system so you can find files stored on the hard drives. It also gives users flexibility when booting a system by allowing kernel parameters to be modified by the user for custom boot processes.

Plus, GRUB automatically finds the Linux kernel to boot if it knows the hard drive number, partition number, and filename of the kernel. GRUB, though it is a Linux program, can also boot other non-Linux operating systems, like Windows.

How is GRUB installed?

Once you install GRUB on a computer, it becomes the default boot loader. Here are the steps to follow to install GRUB:

  1. Find the latest version of the GRUB package on the official GNU website, or obtain an installation disk for it. Always use the latest version of GRUB when you install it.
  2. Next, open the root shell prompt and run the /sbin/grub-install command to install the GRUB package to your system.
  3.  After installing GRUB, restart your machine. The GRUB menu interface will now show before the kernel loads when the system boots.

Many distributions of Linux, like Ubuntu, automatically install GRUB when you install the operating system. This happens in the background while you go through the installation process.

What is the GRUB boot process?

Every time you start or reboot a Linux operating system, it goes through a few steps before you can start using the computer. These steps are:

  1. BIOS. The BIOS is the first stage of booting a computer and is not part of the operating system. It’s stored in nonvolatile memory, like ROM or flash memory on the computer’s motherboard. It ensures that all the core hardware connected to the computer is in working condition so the computer can successfully boot. Once this check is done, it loads the Master Boot Record or MBR from the primary hard drive, which is where GRUB is stored.
  2. GRUB. The BIOS loads GRUB, and then GRUB selects the type of operating system kernel it should load. If there is only one, it will load that. If there is more than one operating system installed, it will display the GNU GRUB screen for a few seconds in case the user wants to select one of the options, otherwise it loads the kernel of whichever operating system was set as default.
  3. Kernel. The kernel performs the following steps in read-only mode: First, it loads the memory, then it mounts and loads the root file system before switching to the actual filesystem. Then, it loads the devices in the system, remounts the filesystem in read-write mode, and mounts up.
  4. Init. In the final stage, your computer uses init files to execute a runlevel program, which is responsible for starting and stopping services on the machine and presenting the user login prompt.

What are the GRUB interfaces?

GRUB has three interfaces that provide different levels of functionality. Any one of these interfaces allows you to boot a Linux kernel (and other operating systems as well).

  • Menu Interface. The menu interface is GRUB’s default interface. It’s the screen you see that has the GNU GRUB heading and the list of different operating systems to choose from ordered by their name. You can select the kernel you want to load by using the arrow keys and hitting enter to boot the kernel you selected. Usually, a timeout period is set up in GRUB that will select the default kernel and boot that kernel if no selection is made before the timeout period is up.
  • Menu Entry Editor Interface. To enter this interface in GRUB, use the arrow keys first to select a specific kernel and press the e key. The commands that GRUB uses to load this entry are displayed in this interface. You can edit these entries here to modify how GRUB loads that specific kernel.
  • Command Line Interface. This interface is like the menu entry editor interface. You can reach it by pressing the c key when you have selected an entry from the menu interface. It’s a basic interface, but it gives you more control over changing the commands GRUB uses to load the specific kernel you selected.

Learn more about Linux

If you’re a developer (or plan on becoming one), you’ll probably work with Linux at some point. You might develop your code on a Mac or Windows machine, but when it goes to production, it’ll probably run on Linux because it is the most common operating system for servers.

Check out our course Learn the Command Line if you want to learn how to get better with Linux — and if you want to learn more about the fundamentals of computers and operating systems, along with  programming, databases, and data structures, check out our Computer Science Career Path.

Subscribe for news, tips, and more


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK