Tag: boot loader

How to update the GRUB bootloader on Debian and derivative distributions (Kali Linux, Ubuntu, Linux Mint)

The GRUB operating system loader is installed and updated on Linux like any other software package. But the peculiarity of the bootloader is that even after updating the package, the actual working files of the bootloader, which are located on the partition mounted along the /boot/grub/ path, are not automatically updated.

That is, when new versions of GRUB are released, the package in your OS is updated automatically.

But the bootloader itself, which is installed on a separate disk partition and mounted along the /boot/grub/ path, is not updated.

To start using the new features that are added in new versions of GRUB, you need to manually update the bootloader.

When to update the GRUB bootloader in /boot/grub/

The signal that a new version of GRUB has been released is something like the following messages:

Setting up grub-common (2.06-8+kali1) ...
...........
Setting up grub2-common (2.06-8+kali1) ...
...........
Setting up grub-pc-bin (2.06-8+kali1) …

Another sign that the GRUB package has been updated is a request to update the default GRUB configuration file.

In order to use the new features introduced in this GRUB update, it is recommended to install it in MBR or UEFI. Due to potential configuration incompatibilities, it is recommended that you perform both installation and configuration creation.

That is, if you see this message, then you need to update the bootloader in /boot/grub/.

How to check if GRUB is being used on the operating system

On Arch Linux and derivative distributions, the GRUB package can be installed but is not used because the bootloader is systemd-boot.

To verify that GRUB is the bootloader, run the following command:

ls -l /boot/grub/grub.cfg

If the /boot/grub/grub.cfg file is found, then GRUB is being used, if the grub.cfg file is not found, then GRUB is not used and does not need to be updated. That is, you do not need to follow the steps shown in this article!

For details, see the article: How to check if a computer is using BIOS or UEFI; GRUB or systemd-boot bootloader; MBR or GPT partition table

How to update the GRUB bootloader in /boot/grub/

To update the bootloader, you need to run a command like:

grub-install --recheck /dev/DISK

Where /dev/DISK should be the name of your drive.

Drive names can be checked with the command:

fdisk -l

Example output:

Disk /dev/vda: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start       End   Sectors Size Id Type
/dev/vda1  *     2048 104857566 104855519  50G 83 Linux


Disk /dev/vdb: 450 KiB, 460800 bytes, 900 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

In this case, the drive name is /dev/vda. Note that /dev/vda is not a boot partition or some other partition – it's the entire drive.

So, the command to update GRUB in /boot/grub/ in my case is the following:

grub-install --recheck /dev/vda

Example output:

Installing for i386-pc platform.
Installation finished. No error reported.

You also need to create a new configuration file with the following command:

grub-mkconfig -o /boot/grub/grub.cfg

Example output:

Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.0.0-kali6-cloud-amd64
Found initrd image: /boot/initrd.img-6.0.0-kali6-cloud-amd64
Found linux image: /boot/vmlinuz-6.0.0-kali5-cloud-amd64
Found initrd image: /boot/initrd.img-6.0.0-kali5-cloud-amd64
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done

GRUB bootloader update and GRUB configuration update completed successfully. The next time you boot, your operating system will use the new features that were added by the GRUB update.

How to update the GRUB bootloader in Arch Linux and derivatives (Manjaro, BlackArch)

The GRUB operating system loader is installed and updated on Linux like any other software package. But the peculiarity of the bootloader is that even after updating the package, the actual working files of the bootloader, which are located on the partition mounted along the /boot/grub/ path, are not automatically updated.

That is, when new versions of GRUB are released, the package in your OS is updated automatically.

But the bootloader itself, which is installed on a separate disk partition and mounted along the /boot/grub/ path, is not updated.

To start using the new features that are added in new versions of GRUB, you need to manually update the bootloader.

When to update the GRUB bootloader in /boot/grub/

The signal that a new version of GRUB has been released is something like the following message:

(3/4) upgrading grub                               [######################] 100%
:: To use the new features provided in this GRUB update, it is recommended
   to install it to the MBR or UEFI. Due to potential configuration
   incompatibilities, it is advised to run both, installation and generation
   of configuration:
     $ grub-install ...
     $ grub-mkconfig -o /boot/grub/grub.cfg

This message says that in order to use the new features introduced in this GRUB update, it is recommended to install it in MBR or UEFI. Due to potential configuration incompatibilities, it is recommended that you perform both installation and configuration creation. And also given exemplary commands.

That is, if you see this message, then you need to update the bootloader in /boot/grub/.

How to check if GRUB is being used on the operating system

On Arch Linux and derivative distributions, the GRUB package can be installed but is not used because the bootloader is systemd-boot.

To verify that GRUB is the bootloader, run the following command:

ls -l /boot/grub/grub.cfg

If the /boot/grub/grub.cfg file is found, then GRUB is being used, if the grub.cfg file is not found, then GRUB is not used and does not need to be updated. That is, you do not need to follow the steps shown in this article!

For details, see the article: How to check if a computer is using BIOS or UEFI; GRUB or systemd-boot bootloader; MBR or GPT partition table

How to update the GRUB bootloader in /boot/grub/

To update the bootloader, you need to run a command like:

grub-install --recheck /dev/DISK

Where /dev/DISK should be the name of your drive.

Drive names can be checked with the command:

fdisk -l

Example output:

Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4b23ea92

Device     Boot  Start      End  Sectors  Size Id Type
/dev/vda1  *      2048   411647   409600  200M 83 Linux
/dev/vda2       411648 62914559 62502912 29.8G 83 Linux

In this case, the drive name is /dev/vda. Note that /dev/vda is not a boot partition or some other partition – it's the entire drive.

So, the command to update GRUB in /boot/grub/ in my case is the following:

grub-install --recheck /dev/vda

You also need to create a new configuration file with the following command:

grub-mkconfig -o /boot/grub/grub.cfg

Example output:

Generating grub configuration file ...
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot:  initramfs-linux-fallback.img
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done

GRUB bootloader update and GRUB configuration update completed successfully. The next time you boot, your operating system will use the new features that were added by the GRUB update.

How to check if a computer is using BIOS or UEFI; GRUB or systemd-boot bootloader; MBR or GPT partition table

How to know if UEFI or GRUB is being used?

The system booting process consists of the following 4 steps:

  1. System initialization: UEFI or BIOS (POST)
  2. Starting the bootloader (GRUB2 or systemd-boot)
  3. Kernel initialization
  4. Starting systemd, the parent of all processes

Related:

If the BIOS is used in the first step, then the GRUB bootloader is most likely involved in the second step.

If UEFI is used in the first step, then both the GRUB bootloader and the systemd-boot bootloader can be used in the second step.

If you're wondering if your computer is running UEFI or GRUB, then this question is the wrong one because UEFI and GRUB are not mutually exclusive.

Modern GRUB2 can work with both BIOS and UEFI (using efibootmgr). On Arch Linux, BIOS and UEFI support is bundled into a single grub package. In Debian and derivative distributions, GRUB comes in two versions:

  • grub-pc (BIOS version)
  • grub-efi (UEFI version)

How to find out if your computer is using BIOS or UEFI

The easiest way is to check if the computer is using UEFI. If the answer is negative, then this means that the BIOS is used on the computer.

To check if your computer supports UEFI, run the command:

ls -l /sys/firmware/efi

If a list of directories is displayed, for example this:

This means that this computer supports UEFI.

If an error message is shown:

ls: cannot access '/sys/firmware/efi': No such file or directory

This means that this computer is working with BIOS.

Also you can check for UEFI variables:

efivar -l

If a large list of variables is shown, then the computer was booted using UEFI.

If an error message is displayed

-bash: efivar: command not found

That means the computer is running on BIOS.

You can also use the efibootmgr utility to check:

efibootmgr

If it displays information about the UEFI Boot Manager, then UEFI is being used.

Please note that the latter method is not reliable, since the efibootmgr utility is not required even for UEFI computers. That is, if, when using UEFI, you receive a message that the command was not found, then the computer may support UEFI, but the efibootmgr package is not installed on it.

Another way is the bootctl utility:

sudo bootctl

Couldn't find EFI system partition. It is recommended to mount it to /boot or /efi.
Alternatively, use --esp-path= to specify path to mount point.
System:
    Not booted with EFI

Pay attention to the message “Not booted with EFI”, that is, the computer uses BIOS.

Finally, the presence of an EFI partition can be checked with fdisk:

sudo fdisk -l

If the boot disk has an “EFI System” partition, then this computer supports UEFI.

Since UEFI requires a separate “EFI System” partition, it can be argued that if this partition is not on the boot disk, then this computer does not support EFI, but works with BIOS.

How to find out if a computer is running GRUB or systemd-boot

To find out if the systemd-boot bootloader is being used, run the command:

sudo bootctl is-installed

The answer is rather concise: “yes” or “no”.

You will only get an answer if your computer uses UEFI. Otherwise, it will output:

Couldn't find EFI system partition. It is recommended to mount it to /boot or /efi.
Alternatively, use --esp-path= to specify path to mount point.

By exclusion, you can determine that if the systemd-boot bootloader is not used, then the GRUB bootloader is most likely used. But how to reliably confirm that it is the GRUB bootloader that is being used?

A system with GRUB installed must have a /boot/grub folder and a /boot/grub/grub.cfg file. To confirm that the GRUB bootloader is being used, you can check for their presence:

ls -l /boot/grub/grub.cfg

You can find other ways to identify GRUB, such as looking for the string “GRUB” in the boot area of the disk, but this method only applies to GRUB-PC! This method does not work with GRUB-EFI.

Since Debian currently has two different versions of GRUB-EFI and GRUB-PC, which are quite different, let's look at how to identify each of them.

How to know if GRUB-EFI or GRUB-PC is being used

As already mentioned, there are two versions of GRUB in Debian and derivatives:

  • grub-pc (BIOS version)
  • grub-efi (UEFI version)

They are quite different, and the methods for determining them also differ.

On Arch Linux and its derivatives, the GRUB-EFI and GRUB-PC versions are bundled into one package.

Using the previous information, you can logically determine whether GRUB-EFI or GRUB-PC is being used:

  1. If the computer uses EFI but does not use the systemd-boot bootloader, then the GRUB-EFI bootloader is used
  2. If the computer does not use EFI, then the GRUB-PC bootloader is probably used

There are also more reliable ways to check which version of the GRUB bootloader your computer is using.

First of all, check the contents of the /boot/grub directory:

ls -l /boot/grub

The presence in this directory of the subdirectory “x86_64-efi” indicates that this operating system uses GRUB-EFI:

The presence of the “i386-pc” directory says that GRUB-PC is being used:

If you receive an error message:

ls: cannot access '/boot/grub': No such file or directory

It means that this OS does not use GRUB.

In the Debian and derivatives repositories, the GRUB-EFI and GRUB-PC installation packages are marked as conflicting, meaning that only one of them can be installed. Therefore, we can check the installed packages to determine which version of GRUB is being used:

dpkg -l | grep grub | grep ii

The installed packages “grub-efi-amd64” and “grub-efi-amd64-bin” indicate that GRUB-EFI is being used:

The installed packages “grub-pc” and “grub-pc-bin” say that GRUB-PC is being used:

Another way to confirm that the operating system is using the GRUB-PC bootloader is the following command:

dd bs=512 count=1 if=/dev/sda 2>/dev/null | strings | grep GRUB

If any output is shown, GRUB-PC is being used.

In the previous command, you need to correctly specify the disk name, you can see the disk names with the command:

fdisk -l

An example command if the operating system is installed on the /dev/vda drive:

dd bs=512 count=1 if=/dev/vda 2>/dev/null | strings | grep GRUB

This screenshot shows that the OS uses GRUB-PC:

There is no similar command for GRUB-EFI.

How to find out if your computer is using an MBR or GPT partition table

Typically, EFI computers use the GPT partition table, and BIOS computers use the MBR, although exceptions are possible.

The following command will show the partition table type for a particular drive:

lsblk -dno PTTYPE /dev/DISK

For example:

lsblk -dno NAME,PTTYPE /dev/nvme0n1

And the following command will display the partition table types for all disks in the operating system:

lsblk -dno NAME,PTTYPE

To check which partition table is on the computer using fdisk, run the command:

sudo fdisk -l

Pay attention to the “Disklabel type” value:

  • gpt stands for GPT
  • dos stands for MBR

The same information can be obtained using the cfdisk utility:

cfdisk /dev/nvme0n1

Pay attention to the value of “Label”:

  • gpt stands for GPT
  • dos stands for MBR

UEFI does not see installed Linux (SOLVED)

How to add a new boot option to UEFI

UEFI usually automatically detects operating system loaders on media connected to a computer. But sometimes UEFI does not show all available options. Let's see how to add a new option to the UEFI boot menu.

For example, I plugged a flash drive with two operating systems – Windows 11 and Kali Linux – into my computer USB port, pressed ESC during boot to select boot options. The screenshot shows two options:

  • Linux OS on internal drive
  • Windows OS on a flash drive

If I select the first option, then it will boot from the internal disk, if the second, then Windows will boot. There is no way to boot Kali Linux from a flash drive.

Go to UEFI settings.

To come to the advanced UEFI settings, on my laptop I use the F7 key.

Go to the “Boot” tab.

As you can see, two boot options are selected and I can add additional ones – both from the drop-down list and new ones that are not in the list.

Among the options available in the drop-down list, there is no Kali Linux from a flash drive.

I select “Add New Boot Option”.

In the “Path for boot option” field, I need to specify the path to the /EFI/kali/grubx64.efi file.

I select a USB flash drive (there is a line “USB” in the path).

Select the “EFI” folder.

Select the “kali” folder.

Select the “grubx64.efi” file.

In the “Add boot option” field, I enter a name for this boot option and click the “Create” button.

The new boot option has been successfully created.

I add this option to the boot menu.

I save the settings made and restart the computer.

The option to boot “Kali” from a flash drive is now available.

The Linux bootloader is aware of the existence of Windows 11 installed and adds the ability to boot it into its menu.

When you select the “Windows Boot Manager” item, Windows 11 is booted from a USB flash drive.

When choosing to boot Kali Linux, you are required to enter a password for the encrypted partition on which the /home folder is located.

Further, work from a USB flash drive in Kali Linux continues as usual.

What to do if there are no settings for adding boot options in UEFI (BIOS)

UEFI varies from manufacturer to manufacturer: some have a lot of settings, some don't. It is possible that UEFI does not see the Linux bootloader and does not have the option to add a new item to the boot menu.

In this case, you can use a different approach. The essence of the method is that any UEFI by default tries to load the bootloader with the /EFI/BOOT/BOOTX64.EFI path. This is the so-called fallback path to the bootloader. Therefore, it is enough to rename the existing path to fallback for UEFI to start loading it.

For example, the path to the Kali Linux bootloader is /EFI/kali/grubx64.efi. In this case, you need to rename the “kali” folder to “BOOT” and the “grubx64.efi” file to “BOOTX64.EFI”.

These files are located on a hidden partition with the FAT32 file system.

Renaming files and folders on an EFI partition in Linux

To make these changes on Linux, mount the drive with read/write permissions and rename the directory and file.

Let's see the names of disks and partitions:

sudo fdisk -l

The partition with the EFI System on which we want to make changes is called /dev/sdb1, let’s mount it:

mkdir /tmp/efi
sudo mount /dev/sdb1 /tmp/efi

Now rename the folder and file sequentially.

sudo mv /tmp/efi/EFI/kali/ /tmp/efi/EFI/BOOT/
sudo mv /tmp/efi/EFI/BOOT/grubx64.efi /tmp/efi/EFI/BOOT/BOOTX64.EFI

When finished, unmount the /dev/sdb1 partition:

sudo umount /dev/sdb1

Renaming files and folders on an EFI partition in Windows

Open the Windows Command Prompt with administrator rights. To do this, press Win+x and select “Windows Terminal (Admin)”.

In the command line, run the program and wait for it to open:

diskpart

At the DISKPART prompt, type:

list disk

We need to find out what number the boot disk has. In my case it is 0.

Now enter the following command, replacing 0 with the number of your boot disk:

sel disk 0

Now the following command will list the volumes:

list vol

This is a very important step! We need to find out what number the partition with EFI has. The EFI partition has a FAT32 file system and does not have a letter.

In my screenshot, the EFI volume is number 2.

Run the following command, replacing 2 with your partition number:

sel vol 2

Now this volume needs to be assigned a letter. It can be any unoccupied letter.

assign letter=V:

Exit DISKPART:

exit

Close Command Prompt.

To edit the names of folders and files on the disk, administrator rights are required. To do this, for example, I run Double Commander with administrator rights.

See also: Free analogue of Total Commander

After that, you can edit the EFI partition like regular folders and files.

How to update the systemd-boot loader in /boot

Update /boot

During the installation of Arch Linux on modern computers with UEFI (BIOS replacement), we create a small partition on the disk with a mount point in /boot into which we install the boot loader using bootctl. This bootloader is systemd-boot, which is part of systemd. Over time, systemd can be updated like any other Arch Linux package. This does not automatically update the loader in /boot. For this reason, if you have been using the same Arch Linux installation for a long time, then your boot loader in /boot may be out of date.

This article will show you how to view version and supported features, and how to update systemd-boot in /boot on Arch Linux (as well as BlackArch and Manjaro).

What is systemd-boot

systemd-boot (short for sd-boot) is a simple UEFI boot manager. It provides a graphical menu for selecting an entry to boot and a kernel command line editor. Systemd-boot only supports systems with UEFI firmware.

systemd-boot loads boot record information from the EFI system partition (ESP), usually mounted in /efi/, /boot/, or /boot/efi/ during OS startup, and from an extended bootloader partition if it exists (usually mounted in /boot/). Fragments of the configuration file, kernels, initrds, and other EFI images to boot should usually reside on an ESP or extended boot loader partition. Linux kernels must be built with CONFIG_EFI_STUB so that they can be directly run as an EFI image. At boot time, systemd-boot automatically collects a list of boot records from the following sources:

  • Boot entries defined using the loader specification descriptor files located in /loader/entries/ on ESP and in the advanced loader section. They usually describe Linux kernel images with associated initrd images, but can also describe arbitrary other EFI binaries.
  • Unified kernel images as per bootloader specification as EFI executable binaries in /EFI/Linux/ on ESP and in the extended bootloader section.
  • Microsoft Windows EFI Boot Manager, if installed.
  • Apple MacOS X Boot Manager, if installed.
  • EFI Shell binary, if installed
  • Reboot to the option UEFI Firmware Configuration, if supported.

systemd-boot supports the following features:

  • Major changes to the boot manager configuration (such as setting a timeout, choosing a default boot record, etc.) can be made directly from the boot loader UI at boot time as well as at run time with EFI variables.
  • The boot manager integrates with the systemctl command to implement features such as systemctl reboot --boot-loader-entry=… (to reboot to a specific boot menu item, eg “reboot to Windows”) and systemctl reboot --boot-loader-menu=… (to reboot in the bootloader menu) by implementing the bootloader interface.
  • The EFI variable, set by the bootloader, tells the OS about the ESP used at boot time. It is then used to automatically mount the correct ESP partition in /efi/ or /boot/ while the OS is running.
  • The Boot Manager provides information about the boot time taken by the UEFI firmware using the Boot Loader Interface. This information can be displayed using systemd-analyze
  • Boot Manager implements load counting and automatic rollback to older workload records in case of failure.
  • The boot manager additionally reads a random seed from the ESP, concatenates it with the “system token” stored in the constant EFI variable, and extracts a random seed for the OS to use as an initialization of the entropy pool, providing a full pool of entropy during early boot.

How to update the bootloader in /boot

The bootctl program can check EFI firmware and bootloader status, list and manage available bootloaders and bootloader entries, and install, update, or remove systemd-boot on the current system.

To check if your system uses systemd-boot, run the command:

bootctl is-installed

To check the current version of the bootloader and see other information about it, run the following command:

bootctl

You will see something like the following:

Pay attention to the Product line - it contains the version, in the screenshot it is 249.5-3.

Also look at the Features list - if you installed your system a long time ago, then some features may be disabled - an update will fix this.

For example, the Features list in the screenshot:

               ✓ Boot counting
               ✓ Menu timeout control
               ✓ One-shot menu timeout control
               ✓ Default entry control
               ✓ One-shot entry control
               ✓ Support for XBOOTLDR partition
               ✓ Support for passing random seed to OS
               ✗ Load drop-in drivers
               ✓ Boot loader sets ESP information

Most of the list is marked with green checkmarks (), but one item (in your case, these may be other items) is marked with a red cross (). This means that systemd supports all of the listed functions, including those marked with a cross, but the currently installed bootloader does not support what is marked with a cross. In order for the bootloader to start supporting the entire list, it needs to be updated.

Using the command

pacman -Ss systemd

you can see the current version of the systemd package. In the screenshot, it is 250-1. That is, you can upgrade to a newer version.

To check the current version of systemd, you may prefer the following command:

pacman -Si systemd

Updating the systemd-boot loader in /boot is performed with the following command:

sudo bootctl update

You need to restart your computer for the changes to take effect.

How to change the default operating system in Arch Linux (for UEFI and systemd-boot)

This instruction applies to all boot loaders that implement the Boot Loader Specification and/or Boot Loader Interface, such as systemd-boot.

If you have a modern computer (no older than seven years at the time of writing), then it most likely uses UEFI instead of BIOS and, therefore, uses systemd-boot to boot, which is usually mentioned in the Arch Linux installation instructions (although there may be grub).

The bootctl program can check EFI firmware and bootloader status, list and manage available bootloaders and bootloader entries, and install, update, or remove systemd-boot on the current system.

To check if your system uses systemd-boot, run the command:

bootctl is-installed

The following command will show all available loader entries that implement the Boot Loader Specification, as well as any other entries found or automatically generated by a loader that implements the Boot Loader Interface.

bootctl list

  • title is an entry name. Note that the entry with the string “(default)” is selected as the default loaded
  • id is an identifier, it is needed in the commands described below to change the OS loaded by default
  • source is a path in the OS
  • linux is the Linux kernel
  • initrd is initial RAM filesystem. The purpose of initramfs is to boot the system to the point where it can access the root filesystem.
  • options are boot options

The following command sets the default bootloader entry. It takes one string of the bootloader entry ID as an argument.

sudo bootctl set-default ID

The set-oneshot command will set the default entry for the next boot only, set-default will set it permanently for all future bootings.

sudo bootctl set-oneshot ID

Optionally, the bootloader entry ID can be one of: @default, @oneshot, or @current, which corresponds to the current default bootloader entry for all future downloads, the current default bootloader entry for the next boot, and the currently loaded bootloader entry. These special identifiers are converted to the current values of the EFI variables LoaderEntryDefault, LoaderEntryOneShot, and LoaderEntrySelected. These special identifiers are primarily useful as a quick way to permanently make the currently loaded bootloader entry the default choice, or update the default bootloader entry for the next boot to the default bootloader entry for all future bootings, but they can be used for others operations as well. If an empty string ("") is specified as the identifier, the corresponding EFI variable will not be set.

The boot manager integrates with the systemctl command, so the following commands can be used:

systemctl reboot --boot-loader-entry=ID

This command will reboot the computer to the specified bootloader entry.

By the way, to get a very compact list containing only bootloader entries, run the command:

systemctl reboot --boot-loader-entry=help

The following command will immediately reload you into the EFI boot menu. This menu will have a timeout for the specified number of SECONDS:

systemctl reboot --boot-loader-menu=SECONDS
Loading...
X