debian9.6中update-grub找不到的解决办法及它与update-grub2的区别

本文详细解析了在Linux环境下遇到的“bash:update-grub:未找到命令”问题,通过对比update-grub和update-grub2,揭示了命令执行路径的不同,并提供了解决方案,即使用sudo前缀或直接调用grub-mkconfig。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,bash: update-grub: 未找到命令

guoyanzhang@bogon:~$ update-grub
bash: update-grub: 未找到命令

为什么呢?我们搜一下:

guoyanzhang@bogon:~$ whereis update-grub
update-grub: /usr/sbin/update-grub /usr/share/man/man8/update-grub.8.gz

明明是有的,但是为什么又说找不到呢?注意看/usr/sbin/,不是/usr/bin,我们平时在普通用户tab出来的是在/bin下,不是在/sbin下,使用/sbin下的,就要使用sudo:

guoyanzhang@bogon:~$ sudo update-grub
[sudo] guoyanzhang 的密码:
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.9.0-8-amd64
Found initrd image: /boot/initrd.img-4.9.0-8-amd64
Found Arch Linux (rolling) on /dev/sda3
Found Debian GNU/Linux 9 (stretch) on /dev/sda4
Adding boot menu entry for EFI firmware configuration
done

2,再看update-grub2

guoyanzhang@bogon:~$ sudo update-grub2
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.9.0-8-amd64
Found initrd image: /boot/initrd.img-4.9.0-8-amd64
Found Arch Linux (rolling) on /dev/sda3
Found Debian GNU/Linux 9 (stretch) on /dev/sda4
Adding boot menu entry for EFI firmware configuration
done

结果是一样的。

3,表面比较

guoyanzhang@bogon:~$ whereis update-grub
update-grub: /usr/sbin/update-grub /usr/share/man/man8/update-grub.8.gz
guoyanzhang@bogon:~$ whereis update-grub2
update-grub2: /usr/sbin/update-grub2 /usr/share/man/man8/update-grub2.8.gz
guoyanzhang@bogon:~$ sudo ls /usr/sbin/update-grub2 -l
lrwxrwxrwx 1 root root 11 10月 29 03:18 /usr/sbin/update-grub2 -> update-grub

update-grub2其实只是一个链接符号,链接到update-grub。

4,内容比较

guoyanzhang@bogon:~$ sudo cat /usr/sbin/update-grub
#!/bin/sh
set -e
exec grub-mkconfig -o /boot/grub/grub.cfg "$@"
guoyanzhang@bogon:~$ sudo cat /usr/sbin/update-grub2
#!/bin/sh
set -e
exec grub-mkconfig -o /boot/grub/grub.cfg "$@"

内容其实是个脚本,真正执行的是grub-mkconfig这句,在archlinux上,直接用这句来更新grub。

参考:https://www.cnblogs.com/EasonJim/p/7471650.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值