I recently encountered a failure where a disk partition was found to become read-only during a cluster software upgrade, causing the storage application to recognize the disk as unavailable. Investigation revealed that the cluster upgrade process regenerates the GRUB configuration file for each node, which causes the disk partition to become read-only during the execution of
grub2-mkconfig. Document the flow of the
grub2-mkconfig command execution until the real disk read-only command is issued.
When executing the
grub2-mkconfig command, GRUB will call os-prober (/etc/grub.d/30_os-prober) for scanning other operating systems for subsequent configuration if the configuration
GRUB_DISABLE_OS_PROBER=true is not specified.
os-prober is used to detect the presence of operating systems on other disks. It is usually provided by individual distributions and is available in source at https://salsa.debian.org/installer-team/os-prober.
The os-prober included by default with CentOS is not the same as the source version and contains some additional configuration, which can be viewed via the RPM changelog at.
You can see exactly what has been changed by downloading the source RPM for os-prober and viewing the os-prober.spec file to see a list of additional patches.
It’s a pain to look at each patch individually, so look directly at the os-prober-related files already installed on the OS
grub2-mkconfig calls os-prober flow
The ultimate goal of
grub2-mkconfig is to generate grub.cfg, which is executed sequentially by calling the configuration scripts under the
/etc/grub.d/ path, where the
/etc/grub.d/30_os-prober configuration script exists in CentOS.
The specific code to execute
os-prober is as follows.
CentOS os-prober execution flow
Create a new namespace, it is recommended to comment out this behavior during debugging os-prober
Ensure that all file system types are supported by executing
Get the information about the mounted partitions, swap partitions, and RAID device partitions on the node.
Get all partition information of the node.
- Skip if partition already exists in swap partition information or RAID device partition information
- Get the file system information as type by
blkid -o value -S type $path, for example.
- If type == btrfs, determine if it is a btrfs volume, and filter if it is; if not, use
/usr/libexec/os-probes/50mounted-teststo probe against the partition
- If the partition is not in the mounted partition information, probe using all methods under the
/usr/libexec/os-probes/50mounted-testspath, traversing the execution
- If the partition is in the mounted partition information, probe all ways under the
/usr/libexec/os-probes/50mounted-testspath and iterate through them
End of detection
/usr/libexec/os-probes/50mounted-tests Probing process
- Parameter checksum to get the fs type property of the partition
- If type is undetected, empty, LVM, swap, ctypto, ntfs, then exit directly
- If type == btrfs, then probe process for subvolume
- If grub-mount and grub2-probe are present, determine if the partition is mounted by GRUB.
- If none of the above branches are entered, make the partition read-only
- blockdev -setro $partition
- and set the signal handling function by trap, when EXIT,HUP,INT,QUIT,TERM signal is received, the partition will be reset to read and write.
- Mount the partition to a temporary mount point according to the current type, and try probing under the
/usr/libexec/os-probes/mounted/path, and iterate through it.
- End of detection
If there is a situation on your node where it is unmounted and the file system type is not null, then it is recommended to disable os-prober execution by setting the GRUB configuration:
GRUB_DISABLE_OS_PROBER=true to prevent the disk partition from becoming read-only.