While reinstalling a server and moving it to Debian, I ran into the problem that I need to sync the EFI partitions. The system is using a RAID on two disks (RAID 1), but the EFI partitions can’t be a RAID and need to exist on both disks. Or rather it is useful to have the EFI partition on every disk: if one disk fails, the system can boot from the other disk.
grub only installs the necessary files on one partition. However one can use a script as grub hook, and sync all partitions.
This script needs to determine if a device (the EFI partition) is already mounted somewhere, or needs to be mounted. Turns out there is a little and not well-known tool for this.

Mounting a device on Linux
Devices on Linux can be mounted in several ways. One is by manually specifying the device name and the mount point:
| |
The above commandline will mount the device /dev/sda2 on the mount pont /mnt (which must already exist). The mount command will determine the filesystem on the partition, if that doesn’t work it can be specified using the -t option:
| |
A second way to mount devices is by pre-defining which device will be mounted on which mount point. This information is stored in the file /etc/fstab, and this file contains one line per device and mount point.
| |
This allows to mount the mount point /boot/efi by issuing the following command:
| |
It is also possible to use the label of the disk:
| |
This is safer. The device name can change if a disk configuration changes. The label however is unique and identifies this specific device and partition.
Identify the mount point
What if I don’t know if the device is already mounted somewhere or not, and if I don’t know the exact mount point. The findmnt tool will help with that:
| |
That’s very helpful!
If the device is currently not mounted, the findmnt tool will not output anything, and also exit with a return code RC=1. This comes handy in scripts.
The output of the tool can be formatted. I need the following options:
--first-only: Only show the first find - not that I expect more mount points, but play it safe--noheadings: Skip the headers (likeTARGET,SOURCE,FSTYPE, andOPTIONS)--output=TARGET: Only output theTARGETcolumn, that is the actual mount point
Using these options together:
| |
The device /dev/sda2 is mounted on /boot/efi.
See this blog posting and this repository with scripts how the findmnt tool is used to identify mount points for grub.
Comments
With an account on the Fediverse or Mastodon, you can respond to this post. Known replies are displayed below:
Note: This will load data from mastodon.social.
Learn how this is implemented here.
Share: