What GRUB Is and Why Command Line Installation Matters

GRUB, short for GRand Unified Bootloader, is a small program that runs before your operating system starts. Its job is to find the kernel of an installed system, load it into memory, and hand over control. Most major Linux distributions use GRUB 2, the version that has been the mainstream choice since the mid-2000s. This educational guide covers how GRUB installation works from the command line, which is useful when a graphical installer is not available or when a system will not boot.

Learn How to Replace a Headlight Connector →

Command line work usually falls into two situations. The first is a rescue case, where the menu is missing and you see a prompt that starts with grub>. The second is a repair or migration case, where you boot from a live USB session and reinstall GRUB onto a disk. Both situations depend on the same idea: GRUB must know where the disk, partition, and kernel files are located. Once you understand that idea, the commands become much easier to follow.

A practical takeaway: before you change anything, write down which disk holds your system and which firmware type your computer uses. Those two facts shape nearly every command in the sections that follow. Some learners find it helpful to keep a short notes file with the disk name, partition layout, and the boot mode, so they can refer to it during a repair.

How BIOS and UEFI Boot Modes Change the Process

Before you type any GRUB command, you need to know whether your machine started in legacy BIOS mode or in UEFI mode. The difference affects where GRUB stores its files and which install command you run. Many computers made after the early 2010s use UEFI by default, but older hardware and some virtual machines still use BIOS.

Free Guide to Classic Car Pricing and Values →

In BIOS mode, the first 446 bytes of the disk's Master Boot Record hold the first stage of GRUB. The partition table is usually MBR, which supports up to four primary partitions and disks up to 2 TiB. Larger disks often use GPT, which handles much bigger sizes. On a GPT disk using BIOS boot, GRUB needs a small "BIOS boot" partition, commonly about 1 MiB, to store its core image.

In UEFI mode, GRUB is installed as an EFI application inside an EFI System Partition, often called the ESP. This partition is usually formatted as FAT32 and commonly sized between 512 MiB and 1 GiB. The ESP is mounted at a path such as /boot/efi when you work from a live session.

A practical takeaway: check the boot mode first. On a Linux system, the presence of the directory /sys/firmware/efi indicates UEFI mode. If that directory is missing, the system is most likely using BIOS mode.

Reading Disks and Partitions at the grub> Prompt

When GRUB drops to its command prompt, it does not use Linux device names like /dev/sda1. Instead, it uses its own naming scheme. A disk is written as hd0 for the first hard drive, hd1 for the second, and so on. A partition is written inside parentheses, such as (hd0,msdos1) for the first partition on an MBR disk or (hd0,gpt2) for the second partition on a GPT disk.

Get Your Free Global Blue Tax Refund Guide →

The ls command lists the devices GRUB can see. Running ls alone may show something like (hd0) (hd0,msdos1) (hd0,msdos2). You can then inspect a partition by running ls (hd0,msdos1)/. If you see folders such as boot/ or files such as vmlinuz-6.x and initrd.img, that partition likely holds your Linux kernel.

Users often guess at partition numbers, which leads to wasted time. Counting from one, and checking each partition with ls, is a more reliable method. Partition numbering in GRUB begins at 1, even though some tools start at 0.

A practical takeaway: map your partitions with ls before setting any root value. Write down which partition contains the kernel files. This habit reduces mistakes when you move on to the boot commands.

Booting a Kernel Manually From the Command Line

If GRUB cannot find its configuration file, you can start your system by hand. The usual sequence has four parts. First, set the root device with a command such as set root=(hd0,gpt2). Second, load the kernel with linux /vmlinuz root=/dev/sda2. Third, load the initial RAM disk with initrd /initrd.img. Fourth, run boot. The root= option inside the linux line uses the Linux device name, not the GRUB name, so the two naming systems appear in the same line.

Learn About Android Widgets and How They Function →

The file names above are examples. Your kernel may be named vmlinuz-6.8.0-45-generic or a similar string. Use the tab key at the GRUB prompt, where supported, to autocomplete file names. Tab completion lists matching files and reduces typing errors.

Manual booting is a temporary measure. It starts the system for one session but does not repair the stored GRUB configuration. For that reason, many learners treat manual booting as a way to reach their desktop so they can run repair tools from inside Linux.

A practical takeaway: write each command on paper before you type it. Check the partition name, the kernel file name, and the initrd file name. A single wrong character can stop the boot process and return you to the prompt.

Reinstalling GRUB From a Live Session

A common repair path uses a live USB session. You boot the computer from a Linux installation drive, identify the system partition, mount it, and then run grub-install inside a chroot environment. A chroot makes the mounted system appear as the root directory, so GRUB writes its files to the correct place.

Learn Where to Find Storage Unit Auctions Near You →

A typical sequence on a BIOS system with an MBR disk looks like this: mount the root partition at /mnt, bind the /dev, /proc, and /sys directories into it, enter the chroot, run grub-install /dev/sda, and then run update-grub. Note that the install target is the disk, not a partition. On UEFI systems, the sequence changes. You mount the ESP at /boot/efi and run grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB. The --bootloader-id value sets the label that appears in the firmware boot menu.

Some distributions use slightly different package names or command paths, so check your version's documentation when results differ from this outline. Many repair guides also mention that update-grub rebuilds the configuration file from the scripts in /etc/grub.d/.

A practical takeaway: keep the live session open until you confirm the system boots. Unmount the partitions in reverse order and reboot only after each command finishes without errors. Writing down the exact target disk before running grub-install helps prevent reinstalling GRUB onto the wrong drive.

Common Mistakes, Recovery Options, and Where to Learn More

Most GRUB repair problems come from a small set of errors. The most frequent is installing GRUB to a partition when the firmware expects a disk, or the reverse. Another common problem is forgetting that UEFI systems need the ESP mounted before the install command runs. A third is using the wrong device name because the disk order changed after adding a drive. Each of these errors can cause the system to fail on the next boot, which is why planning matters.

Learn How to Replace a Headlight Connector →

Backups help a great deal. Before making changes, copy important files to an external drive, and record the current partition layout with a tool such as lsblk or fdisk -l. Some users also create a small note of the GRUB configuration file location, which is usually /boot/grub/grub.cfg on many systems. Having that information ready can speed up any later repair.

Learners who want more detail can explore the GRUB manual, distribution wiki pages, and community forums for their specific Linux version. These resources often include examples for different disk layouts, such as encrypted root partitions, RAID arrays, and dual-boot setups with Windows. Information about these scenarios may be available in official documentation, although procedures can change between releases.

A practical takeaway: treat this guide as an educational starting point. Read the manual for your distribution, test commands in a virtual machine when possible, and keep a written record of every change. This approach supports understanding of how GRUB works and can make future repairs less stressful.