Merge pull request #1259 from MikeCoder/master

mike translating...
This commit is contained in:
Xingyu.Wang 2014-06-30 20:09:01 +08:00
commit 39dbd61361
2 changed files with 128 additions and 128 deletions

View File

@ -1,128 +0,0 @@
How to Rescue a Non-booting GRUB 2 on Linux
================================================================================
![Figure 1: GRUB 2 menu with cool Apollo 17 background.](http://www.linux.com/images/stories/41373/grub-command-shell.jpg)
Figure 1: GRUB 2 menu with cool Apollo 17 background.
Once upon a time we had legacy GRUB, the Grand Unified Linux Bootloader version 0.97. Legacy GRUB had many virtues, but it became old and its developers did yearn for more functionality, and thus did GRUB 2 come into the world.
GRUB 2 is a major rewrite with several significant differences. It boots removable media, and can be configured with an option to enter your system BIOS. It's more complicated to configure with all kinds of scripts to wade through, and instead of having a nice fairly simple `/boot/grub/menu.lst` file with all configurations in one place, the default is `/boot/grub/grub.cfg`. Which you don't edit directly, oh no, for this is not for mere humans to touch, but only other scripts. We lowly humans may edit `/etc/default/grub`, which controls mainly the appearance of the GRUB menu. We may also edit the scripts in `/etc/grub.d/`. These are the scripts that boot your operating systems, control external applications such as memtest and os_prober, and theming`./boot/grub/grub.cfg` is built from `/etc/default/grub` and `/etc/grub.d/*` when you run the update-grub command, which you must run every time you make changes.
The good news is that the update-grub script is reliable for finding kernels, boot files, and adding all operating systems to your GRUB boot menu, so you don't have to do it manually.
We're going to learn how to fix two of the more common failures. When you boot up your system and it stops at the grub> prompt, that is the full GRUB 2 command shell. That means GRUB 2 started normally and loaded the normal.mod module (and other modules which are located in /boot/grub/[arch]/), but it didn't find your grub.cfg file. If you see grub rescue> that means it couldn't find normal.mod, so it probably couldn't find any of your boot files.
How does this happen? The kernel might have changed drive assignments or you moved your hard drives, you changed some partitions, or installed a new operating system and moved things around. In these scenarios your boot files are still there, but GRUB can't find them. So you can look for your boot files at the GRUB prompt, set their locations, and then boot your system and fix your GRUB configuration.
### GRUB 2 Command Shell ###
The GRUB 2 command shell is just as powerful as the shell in legacy GRUB. You can use it to discover boot images, kernels, and root filesystems. In fact, it gives you complete access to all filesystems on the local machine regardless of permissions or other protections. Which some might consider a security hole, but you know the old Unix dictum: whoever has physical access to the machine owns it.
When you're at the `grub>` prompt, you have a lot of functionality similar to any command shell such as history and tab-completion. The `grub rescue>` mode is more limited, with no history and no tab-completion.
If you are practicing on a functioning system, press C when your GRUB boot menu appears to open the GRUB command shell. You can stop the bootup countdown by scrolling up and down your menu entries with the arrow keys. It is safe to experiment at the GRUB command line because nothing you do there is permanent. If you are already staring at the `grub>` or `grub rescue>`prompt then you're ready to rock.
The next few commands work with both `grub>` and `grub rescue>`. The first command you should run invokes the pager, for paging long command outputs:
grub> set pager=1
There must be no spaces on either side of the equals sign. Now let's do a little exploring. Type ls to list all partitions that GRUB sees:
grub> ls
(hd0) (hd0,msdos2) (hd0,msdos1)
What's all this msdos stuff? That means this system has the old-style MS-DOS partition table, rather than the shiny new Globally Unique Identifiers partition table (GPT). (See [Using the New GUID Partition Table in Linux (Goodbye Ancient MBR)][1]. If you're running GPT it will say (hd0,gpt1). Now let's snoop. Use the ls command to see what files are on your system:
grub> ls (hd0,1)/
lost+found/ bin/ boot/ cdrom/ dev/ etc/ home/ lib/
lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/
srv/ sys/ tmp/ usr/ var/ vmlinuz vmlinuz.old
initrd.img initrd.img.old
Hurrah, we have found the root filesystem. You can omit the msdos and gpt labels. If you leave off the slash it will print information about the partition. You can read any file on the system with the cat command:
grub> cat (hd0,1)/etc/issue
Ubuntu 14.04 LTS \n \l
Reading /etc/issue could be useful on a multi-boot system for identifying your various Linuxes.
### Booting From grub> ###
This is how to set the boot files and boot the system from the grub> prompt. We know from running the ls command that there is a Linux root filesystem on (hd0,1), and you can keep searching until you verify where /boot/grub is. Then run these commands, using your own root partition, kernel, and initrd image:
grub> set root=(hd0,1)
grub> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub> initrd /boot/initrd.img-3.13.0-29-generic
grub> boot
The first line sets the partition that the root filesystem is on. The second line tells GRUB the location of the kernel you want to use. Start typing /boot/vmli, and then use tab-completion to fill in the rest. Type root=/dev/sdX to set the location of the root filesystem. Yes, this seems redundant, but if you leave this out you'll get a kernel panic. How do you know the correct partition? hd0,1 = /dev/sda1. hd1,1 = /dev/sdb1. hd3,2 = /dev/sdd2. I think you can extrapolate the rest.
The third line sets the initrd file, which must be the same version number as the kernel.
The fourth line boots your system.
On some Linux systems the current kernels and initrds are symlinked into the top level of the root filesystem:
$ ls -l /
vmlinuz -> boot/vmlinuz-3.13.0-29-generic
initrd.img -> boot/initrd.img-3.13.0-29-generic
So you could boot from grub> like this:
grub> set root=(hd0,1)
grub> linux /vmlinuz root=/dev/sda1
grub> initrd /initrd.img
grub> boot
### Booting From grub-rescue> ###
If you're in the GRUB rescue shell the commands are different, and you have to load the normal.mod andlinux.mod modules:
grub rescue> set prefix=(hd0,1)/boot/grub
grub rescue> set root=(hd0,1)
grub rescue> insmod normal
grub rescue> normal
grub rescue> insmod linux
grub rescue> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub rescue> initrd /boot/initrd.img-3.13.0-29-generic
grub rescue> boot
Tab-completion should start working after you load both modules.
### Making Permanent Repairs ###
When you have successfully booted your system, run these commands to fix GRUB permanently:
# update-grub
Generating grub configuration file ...
Found background: /usr/share/images/grub/Apollo_17_The_Last_Moon_Shot_Edit1.tga
Found background image: /usr/share/images/grub/Apollo_17_The_Last_Moon_Shot_Edit1.tga
Found linux image: /boot/vmlinuz-3.13.0-29-generic
Found initrd image: /boot/initrd.img-3.13.0-29-generic
Found linux image: /boot/vmlinuz-3.13.0-27-generic
Found initrd image: /boot/initrd.img-3.13.0-27-generic
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
# grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
When you run grub-install remember you're installing it to the boot sector of your hard drive and not to a partition, so do not use a partition number like /dev/sda1.
### But It Still Doesn't Work ###
If your system is so messed up that none of this works, try the [Super GRUB2 live rescue disk][2]. The official [GNU GRUB Manual 2.00][3] should also be helpful.
--------------------------------------------------------------------------------
via: http://www.linux.com/learn/tutorials/776643-how-to-rescue-a-non-booting-grub-2-on-linux
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://www.linux.com/learn/tutorials/730440-using-the-new-guid-partition-table-in-linux-good-bye-ancient-mbr-
[2]:http://www.supergrubdisk.org/
[3]:https://www.gnu.org/software/grub/manual/grub.html

View File

@ -0,0 +1,128 @@
如何拯救一台没有成功通过Grub启动的Linux电脑
================================================================================
![Figure 1: GRUB 2 menu with cool Apollo 17 background.](http://www.linux.com/images/stories/41373/grub-command-shell.jpg)
Figure 1: GRUB 2 menu with cool Apollo 17 background.
自从我们拥有GRUB以来Linux Bootloader 0.97就开始了传奇的一生。尽管传统的GRUB有很多的有点但是他开始陈旧了并且他的开发者也开始添加更多的功能于是Grub2.0时代就要来了。
GRUB 2 做了几个明显的改进。它可以从移动存储设备上启动并且可以有进入BIOS配置的选项。尽管它有着更复杂的脚本配置但是一个简单的`/boot/grub/menu.lst`文件却一个地方集中了所有配置选项,默认的是存放在`/boot/grub/grub.cfg `。你不能直接编辑,这不是人做的事,太复杂,我们需要用简单的脚本实现。我们卑微的人类可以编辑`/etc/default/grub`文件来修改它主要是控制Grub菜单。我们还可以修改` /etc/grub.d/ `。这些脚本可以启动操作系统控制外部应用程序如memtest 和 os_prober还有theming `./boot/grub/grub.cfg`是建立在`/etc/default/grub`和`/etc/grub.d/*`的基础上的。当你修改了一个地方你必须要运行更新GRUB的命令。
好消息是update-grub脚本是可以可靠的检测内核启动文件并添加所有的操作系统的自动生成你的启动菜单所以你不必手动的修改他们。
我们还要学习如何解决两个常见的故障。当启动系统时它会停在GRUB >提示上这是完整的GRUB 2命令界面所以不要惊慌。这意味着GRUB 2依旧可以正常启动和加载normal.mod模块和其他模块分别位于/boot/grub/[arch]/但没有找到你的grub.cfg文件。如果你看到grub rescue> 这意味着它无法找到normal.mod因此它有可能找不到你的启动文件。
这是如何发生的因为内核可能改变驱动器分配或您移动您的硬盘驱动器或者你手动改变一些分区或安装一个新的操作系统或者移动一些文件。在这些情况下你的启动文件仍然存在但GRUB不能找到他们。所以你可以看看在GRUB提示符中启动文件设置它们的位置然后启动您的系统和修复您的grub配置。
### GRUB 2 命令行 ###
GRUB 2 命令是一个伟大的财富。你不仅可以用它来发现引导镜像内核和根文件系统。事实上它给你完全访问本地计算机上的所有文件的系统权限。其中有些人可能会认为一个安全漏洞但是你知道古老的UNIX的名言有物理访问机器权限的人就是拥有它的人。
当你在` GRUB > `提示时你有许多类似的功能如命令如历史和tab补全。但是`grub rescue> `模式是有限的没有历史没有tab补全。
如果你是在一个正常运作的系统上练习那就当GRUB菜单打开GRUB命令行时按C。你可以通过向上和向下滚动你的菜单条目箭头键停止启动倒计时。它是安全的在此GRUB命令行下你不会进行永久的修改一切都是暂时的。如果你已经看到`grub > `或`grub rescue> `提示符,那就说明你的表现时刻到了。
接下来的几个命令可以在`grub>`和`grub rescue`模式下运行。同时,你应该第一个运行的命令如下:
grub> set pager=1
等号两侧必须不能出现空格。现在让我们做一点探讨。ls列出的所有分区
grub> ls
(hd0) (hd0,msdos2) (hd0,msdos1)
MSDOS是什么这意味着该系统具有老式的MS-DOS分区表而不是全新的全局唯一标识符的分区表GPT见[Using the New GUID Partition Table in Linux (Goodbye Ancient MBR)][1]。如果你正在运行的GPT它会出现hd0GPT1。使用ls命令查看你的系统文件是什么
grub> ls (hd0,1)/
lost+found/ bin/ boot/ cdrom/ dev/ etc/ home/ lib/
lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/
srv/ sys/ tmp/ usr/ var/ vmlinuz vmlinuz.old
initrd.img initrd.img.old
好的我们已经找到了根文件系统。你可以省略MSDOS和GPT的标签。如果你无视打印的分区信息。你可以用cat命令读取文件系统上的文件
grub> cat (hd0,1)/etc/issue
Ubuntu 14.04 LTS \n \l
从/etc/issue文件中可以看到你的不同的Linux系统
### 从 grub> 中启动###
这是如何设置启动文件和启动从`GRUB>`提示中进入系统。我们知道从运行ls命令有一个Linux根文件系统hd0,1你可以继续寻找直到你找到你的/boot/grub所在位置。然后运行这些命令使用您自己的根分区内核和initrd映像
grub> set root=(hd0,1)
grub> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub> initrd /boot/initrd.img-3.13.0-29-generic
grub> boot
第一行设置分区的根文件系统是。第二行告诉grub您想要使用的内核位置。开始输入/boot/vmli然后使用tab完成填写。输入`root= /dev/sdX`设置根文件系统位置。是的这似乎是多余的但如果你忘记了输入你会得到一个kernel panic。你知道怎么正确的分区hd0,1 = /dev/sda1。hd1,1 = /dev/sdb1。hd3,2 = /开发/ sdd2。我想你可以推出自己的。
第三行设置initrd文件必须是和内核相同的版本号。
最后一行启动系统。
在一些Linux系统上内核和initrds是被符号链接到当前的根文件系统的根目录就像
$ ls -l /
vmlinuz -> boot/vmlinuz-3.13.0-29-generic
initrd.img -> boot/initrd.img-3.13.0-29-generic
所以,你也可以这样输入命令:
grub> set root=(hd0,1)
grub> linux /vmlinuz root=/dev/sda1
grub> initrd /initrd.img
grub> boot
### 从grub-rescue> 中启动 ###
你必须要加载两个模块normal.mod 和 linux.mod如果你的GRUB命令不同于大众。
grub rescue> set prefix=(hd0,1)/boot/grub
grub rescue> set root=(hd0,1)
grub rescue> insmod normal
grub rescue> normal
grub rescue> insmod linux
grub rescue> linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1
grub rescue> initrd /boot/initrd.img-3.13.0-29-generic
grub rescue> boot
tab补全应该在你加载了这几个模块之后开始工作。
### 永久性的修复 ###
当你成功地启动你的系统运行这些命令来永久修复GRUB
# update-grub
Generating grub configuration file ...
Found background: /usr/share/images/grub/Apollo_17_The_Last_Moon_Shot_Edit1.tga
Found background image: /usr/share/images/grub/Apollo_17_The_Last_Moon_Shot_Edit1.tga
Found linux image: /boot/vmlinuz-3.13.0-29-generic
Found initrd image: /boot/initrd.img-3.13.0-29-generic
Found linux image: /boot/vmlinuz-3.13.0-27-generic
Found initrd image: /boot/initrd.img-3.13.0-27-generic
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
# grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
当你运行 `grub-install`记得grub是安装到硬盘驱动器的引导扇区而不是到一个具体分区所以不要加上像/dev/sda1的分区号。
### 如果还是不能使用 ###
如果你的系统是如此的倒霉,而且这个方式没有能起作用,那就尝试[超级GRUB2现场救援磁盘][2]。[官方GNU GRUB手册][3]也应该是有帮助的。
--------------------------------------------------------------------------------
via: http://www.linux.com/learn/tutorials/776643-how-to-rescue-a-non-booting-grub-2-on-linux
译者:[MikeCoder](https://github.com/MikeCoder) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://www.linux.com/learn/tutorials/730440-using-the-new-guid-partition-table-in-linux-good-bye-ancient-mbr-
[2]:http://www.supergrubdisk.org/
[3]:https://www.gnu.org/software/grub/manual/grub.html