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

简介: grub-install不能处理/dev/xvda这样的路径,需要重装grub时怎么处理呢?

如果你的系统盘是/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
相关文章
|
19天前
|
Linux
在Linux中,列出几种常见打包工具并写相应解压缩参数。
在Linux中,列出几种常见打包工具并写相应解压缩参数。
|
13天前
|
Linux 开发工具
Linux查看已经安装软件的版本,安装软件的路径,以及dpkg、aptitude、apt-get、apt工具的使用
Linux查看已经安装软件的版本,安装软件的路径,以及dpkg、aptitude、apt-get、apt工具的使用
20 2
Linux查看已经安装软件的版本,安装软件的路径,以及dpkg、aptitude、apt-get、apt工具的使用
|
9天前
|
安全 Linux 测试技术
Kali Linux预装的自动化渗透测试工具
Kali Linux预装的自动化渗透测试工具
20 2
|
13天前
|
存储 缓存 监控
Linux性能分析工具-perf并生成火焰图
Linux性能分析工具-perf并生成火焰图
|
20天前
|
SQL 关系型数据库 MySQL
在Linux中,mysql 数据备份工具有哪些?
在Linux中,mysql 数据备份工具有哪些?
|
20天前
|
存储 Linux Shell
在Linux中,如何查看当前路径?
在Linux中,如何查看当前路径?
|
22天前
|
监控 安全 Linux
在Linux中,如何理解系统管理工具,如Webmin和Ajenti。
在Linux中,如何理解系统管理工具,如Webmin和Ajenti。
|
22天前
|
存储 算法 Linux
在Linux中,如何理解加密工具?如GnuPG和OpenSSL。
在Linux中,如何理解加密工具?如GnuPG和OpenSSL。
|
22天前
|
运维 监控 网络协议
在Linux中,有哪些系统管理和配置工具?
在Linux中,有哪些系统管理和配置工具?
|
10天前
|
Ubuntu Linux
用crash工具学习Linux内核 —— 查看cgroup_roots
用crash工具学习Linux内核 —— 查看cgroup_roots