Home / Alt manpages / grub-mkdevicemap(8)

  • grub-mkdevicemap(8)
  • Admin command
  • linux

Generate and Check a GRUB Device Map Without Guessing

You will create a GRUB device map in a chosen file, inspect what the probe found, and decide whether it belongs in /boot/grub/device.map. Allow about 10 minutes. You need the grub-common package and a shell; writing the default file needs root access.

What this command changes

grub-mkdevicemap generates a map between GRUB BIOS-style drive names and operating system device files. A map entry has the general shape (hd0) /dev/sda. GRUB tools can use this information when a fixed device ordering matters, especially while working with an environment that differs from the machine's normal boot environment.

Modern GRUB configurations usually prefer filesystem UUIDs or labels, so a device map is not a general cure for a boot failure. If no map exists, GRUB utilities can construct a temporary map. Treat a persistent map as an explicit override: a stale disk order can be worse than no file at all.

1. Check the installed version

This guide was checked with Ubuntu's grub-common package version 2.12-1ubuntu7.3. Confirm the command on the machine you are changing:

$ grub-mkdevicemap --version
grub-mkdevicemap (GRUB) 2.12-1ubuntu7.3

The version line can differ on another release. Confirm that the executable is the one supplied by the expected package before continuing:

$ command -v grub-mkdevicemap; dpkg-query -W -f='${Package} ${Version}\n' grub-common

Checkpoint

You have a working command and know which GRUB package version you are about to use.

2. Generate a disposable map first

Do not begin by writing the default path. Generate a temporary copy so that you can inspect it without changing the boot configuration:

$ map_file=$(mktemp /tmp/grub-device-map.XXXXXX); grub-mkdevicemap --no-floppy --device-map="$map_file" --verbose; printf 'map: %s\n' "$map_file"; sed -n '1,80p' "$map_file"

--device-map selects the output file. --no-floppy skips probing floppy drives, which avoids a needless delay or probe error on most current machines. --verbose asks for diagnostic messages, but it is normal for a quiet run to exit successfully. The file can also be empty when the environment exposes no devices that the utility can map.

On a machine with a discoverable disk, the contents may resemble this format:

(hd0) /dev/sda
(hd1) /dev/sdb

Those entries are an example of the file format, not output to copy blindly. Check the actual device names with lsblk and compare them with the system's intended boot order. Do not infer that hd0 must be the disk mounted at /.

Checkpoint

The generated file exists, and every mapping you intend to keep matches a real device and the firmware or virtual machine disk order.

3. Decide whether a persistent map is needed

Keep the temporary result if a GRUB tool or a virtual machine setup specifically needs a stable BIOS-to-device override. Otherwise, leave the system without a persistent map and use UUIDs or filesystem labels in custom GRUB entries.

Be especially cautious after adding, removing, or reordering disks. Kernel device names such as /dev/sda are not a permanent identity. A map made before a hardware change can point GRUB at the wrong disk. If you are repairing a remote or production machine, arrange console or recovery access before changing boot-related files.

4. Install the map at the default path only when justified

The manpage's default output is /boot/grub/device.map. Writing there changes system state and normally requires elevated privileges. First preserve any existing file, then generate the new map:

$ sudo cp --preserve=mode,ownership /boot/grub/device.map /boot/grub/device.map.backup; sudo grub-mkdevicemap --no-floppy --device-map=/boot/grub/device.map --verbose

The backup command is expected to fail if no old map exists. That is safe: continue with the generation command only after checking the message and confirming that the destination is the file you intended. Never replace a map on a host whose disk order you have not checked.

To use a different location, keep the explicit option when invoking the GRUB tool that consumes the map:

$ sudo grub-probe --device-map=/path/to/verified-device.map --target=drive /dev/sda1

The exact consumer may have additional requirements. grub-mkdevicemap itself only documents the map-generation options listed below; it does not install a boot loader or rewrite grub.cfg.

5. Verify the result and recover if it is wrong

Read the installed file and check its ownership and mode:

$ sudo sed -n '1,80p' /boot/grub/device.map; stat -c '%A %U:%G %n' /boot/grub/device.map

Every non-comment line should identify a GRUB drive and an operating system device. If the map is wrong, restore the backup rather than editing a drive name from memory:

$ sudo cp --preserve=mode,ownership /boot/grub/device.map.backup /boot/grub/device.map

If there was no previous map, remove the newly created file only after confirming that no GRUB workflow depends on it, then let the utilities use their temporary mapping. Removal is a privileged, state-changing operation; use your distribution's normal recovery procedure if the machine no longer boots.

Options that matter here

  • -n or --no-floppy skips floppy probing.
  • -s or --probe-second-floppy probes the second floppy drive. Use it only when that hardware is relevant.
  • -m FILE or --device-map=FILE selects the output path; the default is /boot/grub/device.map.
  • -v or --verbose requests verbose messages.
  • -h and -V print help or version information and exit.

Done means

  • The installed version and package were checked.
  • A disposable map was generated and inspected first.
  • Each retained mapping matches the intended disk order.
  • Any persistent change has a recoverable backup.
  • You can explain why a map is needed instead of relying on it by habit.