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
相关文章
|
14天前
|
Linux 应用服务中间件 PHP
性能工具之linux常见日志统计分析命令
通过本文的介绍,我相信同学们一定会发现 linux三剑客强大之处。在命令行中,它还能够接受,和执行外部的 AWK 程序文件,可以对文本信息进行非常复杂的处理,可以说“只有想不到的,没有它做不到的。
50 1
|
14天前
|
Ubuntu 安全 Linux
Linux(34)Rockchip RK3568 Ubuntu22.04和Debian 10上配置远程桌面工具
Linux(34)Rockchip RK3568 Ubuntu22.04和Debian 10上配置远程桌面工具
53 0
|
28天前
|
Linux
Linux系统调优相关工具
Linux系统调优相关工具
15 0
|
28天前
|
Linux
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
24 0
|
15天前
|
Linux 网络安全 数据安全/隐私保护
SSH工具连接远程服务器或者本地Linux系统
SSH工具连接远程服务器或者本地Linux系统
18 0
|
1天前
|
数据可视化 小程序 Linux
【Linux】自动化构建工具make/Makefile和git介绍
【Linux】自动化构建工具make/Makefile和git介绍
8 0
|
2天前
|
缓存 Linux
linux性能分析之内存分析(free,vmstat,top,ps,pmap等工具使用介绍)
这些工具可以帮助你监视系统的内存使用情况、识别内存泄漏、找到高内存消耗的进程等。根据具体的问题和需求,你可以选择使用其中一个或多个工具来进行内存性能分析。注意,内存分析通常需要综合考虑多个指标和工具的输出,以便更好地理解系统的行为并采取相应的优化措施。
17 5
|
7天前
|
Linux
Linux课程四课---Linux开发环境的使用(自动化构建工具-make/Makefile的相关)
Linux课程四课---Linux开发环境的使用(自动化构建工具-make/Makefile的相关)
|
8天前
|
存储 Linux
深入探索Linux文件系统:属性、路径与隐藏之谜
深入探索Linux文件系统:属性、路径与隐藏之谜
21 1