CentOS 7的引导程序Grub2执行halt指令失败

在许多ACPI管理的系统里,CentOS 7引导程序Grub2在执行关机"halt"指令时会失败,屏幕显示如下出错信息:

grub> halt
 Unknown opcode 0x6
 Unknown opcode 0x12
 Unknown opcode 0x7d
 ACPI shutdown failed

此时,只能长按电源按钮强行关机。

Grub上游源代码已经整合了一个能解决这个问题的补丁,但仍未被大多数Linux发行版采纳。

我刚把这个补丁(删除了无法正确合并的ChangeLog片段)加入了CentOS 7的Grub2 SRPM软件包;RPM包可从http://dl.zhmail.com/rhel/7/x86_64/目录下载。

CentOS 7中Grub 2升级步骤如下:

$ sudo rpm -Fvh grub*.x86_64.rpm
$ sudo grub2-install --force --skip-fs-probe /dev/sda6
Installing for i386-pc platform.
grub2-install: warning: File system ‘xfs’ doesn't support embedding.
grub2-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
Installation finished. No error reported.

注意:在以上grub2-install命令中,/dev/sda6是我的笔记本电脑上CentOS 7的/boot分区。执行grub2-install时须根据实际情况调整命令参数。

重启系统后,grub就能正确执行halt指令了。

如果你想在grub启动菜单中增加Shutdown和Reboot两个菜单项,可以在/etc/grub.d/40_custom中加入如下两个menuentry:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.

menuentry 'Shutdown' {
    echo 'System shutting down...'
    halt
}

menuentry 'Reboot' {
    echo 'System rebooting...'
    reboot
}

然后,键入以下命令重新生成grub.cfg文件:

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.