閱讀315 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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

最後更新:2017-07-27 09:03:11

  上一篇:go  Go語言與數據庫開發:01-02
  下一篇:go  tu