LinuxCommandLibrary

grub-mkdevicemap

Create device map file for GRUB

SYNOPSIS

grub-mkdevicemap [OPTION]... [FILE]
If FILE is specified, the device map is written to it. Otherwise, it is written to standard output.

PARAMETERS

FILE
    Optional argument. Specifies the path where the generated device map should be written. If omitted, the map is written to standard output.

-n, --no-floppy
    Prevents `grub-mkdevicemap` from probing floppy disk devices when generating the map.

-s, --skip-missing
    Instructs the command to not generate entries for disks that are identified but currently missing from the system.

--help
    Displays a help message and exits.

--version
    Displays version information and exits.

DESCRIPTION

`grub-mkdevicemap` is a utility from the GRUB (GRand Unified Bootloader) suite designed to create or update the `device.map` file. This essential file serves as a crucial mapping between GRUB's internal device naming conventions (e.g., `(hd0)`, `(hd1)` for hard disks) and the operating system's device names (e.g., `/dev/sda`, `/dev/sdb`, `/dev/nvme0n1`).

The command scans all available block devices on the system and attempts to determine their corresponding GRUB device names. The generated map is vital for GRUB to correctly identify the physical disks and partitions it needs to access during the boot process, including the root filesystem and the GRUB installation partition. Without an accurate `device.map`, GRUB may fail to locate its configuration files or the operating system's kernel, leading to boot failures.

Typically, `grub-mkdevicemap` is run automatically during GRUB installation (e.g., via `grub-install`). However, it might need to be executed manually when significant hardware changes occur, such as adding or removing disks, or when the order of disks changes in the BIOS/UEFI settings, to ensure GRUB's continued ability to boot the system correctly. The generated file is usually placed at `/boot/grub/device.map` or `/boot/grub2/device.map`.

CAVEATS

Requires root privileges to scan and identify block devices on the system.
An outdated or incorrect `device.map` can prevent GRUB from locating boot partitions, leading to boot failures.
The order of disks recognized by the operating system (e.g., `/dev/sda`, `/dev/sdb`) might not always match the order GRUB or the BIOS/UEFI expects (`(hd0)`, `(hd1)`).
Modifying the `device.map` manually without proper understanding can lead to an unbootable system.

USAGE EXAMPLE

To generate and save the device map to the standard GRUB location (requires root privileges):
sudo grub-mkdevicemap -n > /boot/grub/device.map

To view the generated map without saving:
sudo grub-mkdevicemap

IMPORTANCE OF <I>DEVICE.MAP</I>

The `device.map` file is critical because GRUB uses its own syntax for identifying disks (e.g., `(hd0)` for the first hard disk) which may not directly correspond to the kernel's assigned device names (e.g., `/dev/sda`). This mapping ensures GRUB can correctly locate the boot partition and other necessary files, especially in systems with multiple disks or specific boot orders.

HISTORY

`grub-mkdevicemap` is an integral part of the GRUB 2 bootloader suite, which superseded the original GRUB Legacy. While the concept of a device map existed in GRUB Legacy, GRUB 2 introduced a more modular and robust architecture, and `grub-mkdevicemap` was developed as the dedicated utility to manage this crucial mapping.

Its development has been closely tied to the evolution of GRUB 2 itself, aiming to automate and simplify the process of mapping physical disks to GRUB's internal device names, thereby ensuring consistent boot behavior across various hardware configurations. It has remained a stable and essential component for managing GRUB's understanding of the system's disk topology.

SEE ALSO

Copied to clipboard