Linux问题情报分享(2):grub-install工具不能处理devxvda*路径

    xiaoxiao2022-07-09  206

    如果你的系统盘是/dev/xvda,而你又需要重新安装grub,你可能会遇到这样的问题

    [root@demo ~]# fdisk -l -u Disk /dev/xvda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00021c72 Device Boot Start End Blocks Id System /dev/xvda1 * 2048 83886079 41942016 83 Linux [root@demo ~]# grub-install /dev/xvda expr: non-numeric argument expr: non-numeric argument The file /boot/grub/stage1 not read correctly. [root@demo ~]#

    造成这个问题原因是因为grub-install中有类似如下sed语句

    [root@demo ~]# grep shv /sbin/grub-install sed -e 's%\([shv]d[a-z]\)[0-9]*$%\1%' \ sed -e 's%.*/[shv]d[a-z]\([0-9]*\)$%\1%' \ [root@demo ~]#

    这两条sed是解析磁盘和分区路径的。很明显类似/dev/xvda这样的路径是处理不了的。

    知道了原因,调整起来就简单了

    cp /sbin/grub-install /sbin/grub-install.orig sed -i -e 's/\[shv\]/[shxv]\\{1,2\\}/' /sbin/grub-install

    修改完毕,看看效果

    [root@demo ~]# sed -i -e 's/\[shv\]/[shxv]\\{1,2\\}/' /sbin/grub-install [root@demo ~]# grub-install /dev/xvda Installation finished. No error reported. This is the contents of the device map /boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. # this device map was generated by anaconda (hd0) /dev/xvda [root@demo ~]#

    最后,记的恢复grub-install,以避免升级或者更新遇到麻烦

    cat /sbin/grub-install.orig > /sbin/grub-install 相关资源:新年快乐! python实现绚烂的烟花绽放效果
    最新回复(0)