RedHat7系统下使用xfsdump备份服务器后,在恢复的过程中有一步需要安装grub到启动分区设备中

# grub2-install /dev/sda1

在RedHat7.2的时候可以正常运行:

# grub2-install /dev/sda1
Installing for i386-pc platform.
Installation finished. No error reported.

但是在RedHat7.3的时候发生异常:

# grub2-install /dev/sda1
Installing for i386-pc platform.
grub2-install: error: unknown filesystem.

原因是在重新创建boot分区的文件系统时执行了以下命令

# /dev/sda1 为boot分区设备
mkfs.xfs -f /dev/sda1
xfs_admin -U f6d07d03-6115-4546-a31c-361453e4b9b8 /dev/sda1

其中使用到了xfs_admin -U命令来指定file system的uuid,通过查看xfs_admin的man手册,描述如下:

Set the UUID of the filesystem to uuid. A sample UUID looks like this: "c1b9d5a2-f162-11cf-9ece-0020afc76f16". The uuid may also be nil, which will set the filesystem UUID to the null UUID. The uuid may also be generate, which will generate a new UUID for the filesystem. Note that on CRC-enabled filesystems, this will set an incompatible flag such that older kernels will not be able to mount the filesystem. To remove this incompatible flag, use restore, which will restore the original UUID and remove the incompatible feature flag as needed.

关键内容是在启用CRC的文件系统中会设置一个不兼容标志,这个标志会被grub2-install检测到,并导致错误发生。

在RedHat7.2中默认是不启用CRC的,而在RedHat7.3中被默认开启了,所以导致问题发生。

解决办法:
使用如下命令替换上述两条命令:

mkfs.xfs -f -m uuid=f6d07d03-6115-4546-a31c-361453e4b9b8 /dev/sda1

man手册中的描述是:

Use the given value as the filesystem UUID for the newly created filesystem. The default is to generate a random UUID.

问题解决。