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

如果你的系统盘是/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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值