# GRUB

<div id="bkmrk-published-on%C2%A0linux.c" style="margin-left:0cm;margin-right:0cm;"><span style="color:#000000;">Published on </span><span style="color:#000000;">Linux.com | The source for Linux information</span><span style="color:#000000;"> (</span>[<span>https://www.linux.com</span>](https://www.linux.com/)<span style="color:#000000;">)</span>

</div><div id="bkmrk-home%C2%A0%3E-how-to-rescue" style="margin-left:0cm;margin-right:0cm;">[Home](https://www.linux.com/)<span style="color:#000000;"> &gt; How to Rescue a Non-booting GRUB 2 on Linux</span>

</div>## [How to Rescue a Non-booting GRUB 2 on Linux](https://www.linux.com/learn/how-rescue-non-booting-grub-2-Linux)<span style="color:#000000;"> \[1\]</span>

<span style="color:#000000;">Submitted by </span>[cschroder](https://www.linux.com/users/cschroder)<span style="color:#000000;"> \[2\] on </span>

<div id="bkmrk-afbeelding2.png" style="color:#000000;"><figure>![](Afbeelding2.png "Afbeelding2.png")<figcaption>Afbeelding2.png</figcaption></figure></div><div id="bkmrk-once-upon-a-time-we-" style="color:#000000;">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.

</div><span style="color:#000000;">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 </span><span style="color:#000000;">/boot/grub/menu.lst</span><span style="color:#000000;"> file with all configurations in one place, the default is </span><span style="color:#000000;">/boot/grub/grub.cfg</span><span style="color:#000000;">. 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 </span><span style="color:#000000;">/etc/default/grub</span><span style="color:#000000;">, which controls mainly the appearance of the GRUB menu. We may also edit the scripts in </span><span style="color:#000000;">/etc/grub.d/</span><span style="color:#000000;">. These are the scripts that boot your operating systems, control external applications such as </span><span style="color:#000000;">memtest</span><span style="color:#000000;"> and </span><span style="color:#000000;">os\_prober</span><span style="color:#000000;">, and theming.</span><span style="color:#000000;">/boot/grub/grub.cfg</span><span style="color:#000000;"> is built from </span><span style="color:#000000;">/etc/default/grub</span><span style="color:#000000;"> and </span><span style="color:#000000;">/etc/grub.d/\*</span><span style="color:#000000;"> when you run the </span><span style="color:#000000;">update-grub</span><span style="color:#000000;"> command, which you must run every time you make changes.</span>

<span style="color:#000000;">The good news is that the </span><span style="color:#000000;">update-grub</span><span style="color:#000000;"> 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.</span>

<span style="color:#000000;">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 </span><span style="color:#000000;">grub&gt;</span><span style="color:#000000;"> prompt, that is the full GRUB 2 command shell. That means GRUB 2 started normally and loaded the </span><span style="color:#000000;">normal.mod</span><span style="color:#000000;"> module (and other modules which are located in </span><span style="color:#000000;">/boot/grub/\[arch\]/</span><span style="color:#000000;">), but it didn't find your </span><span style="color:#000000;">grub.cfg</span><span style="color:#000000;"> file. If you see </span><span style="color:#000000;">grub rescue&gt;</span><span style="color:#000000;"> that means it couldn't find </span><span style="color:#000000;">normal.mod</span><span style="color:#000000;">, so it probably couldn't find any of your boot files.</span>

<div id="bkmrk-how-does-this-happen" style="color:#000000;">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.

</div>### GRUB 2 Command Shell

<div id="bkmrk-the-grub-2-command-s" style="color:#000000;">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.

</div><span style="color:#000000;">When you're at the </span><span style="color:#000000;">grub&gt;</span><span style="color:#000000;"> prompt, you have a lot of functionality similar to any command shell such as history and tab-completion. The </span><span style="color:#000000;">grub rescue&gt;</span><span style="color:#000000;"> mode is more limited, with no history and no tab-completion.</span>

<span style="color:#000000;">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 </span><span style="color:#000000;">grub&gt;</span><span style="color:#000000;"> or </span><span style="color:#000000;">grub rescue&gt;</span><span style="color:#000000;">prompt then you're ready to rock.</span>

<span style="color:#000000;">The next few commands work with both </span><span style="color:#000000;">grub&gt;</span><span style="color:#000000;"> and </span><span style="color:#000000;">grub rescue&gt;</span><span style="color:#000000;">. The first command you should run invokes the pager, for paging long command outputs:</span>

<div id="bkmrk-grub%3E-set-pager%3D1" style="color:#000000;">grub&gt; set pager=1

</div><span style="color:#000000;">There must be no spaces on either side of the equals sign. Now let's do a little exploring. Type </span><span style="color:#000000;">ls</span><span style="color:#000000;"> to list all partitions that GRUB sees:</span>

<div id="bkmrk-grub%3E-ls" style="color:#000000;">grub&gt; ls

</div><div id="bkmrk-%28hd0%29-%28hd0%2Cmsdos2%29-%28" style="color:#000000;">(hd0) (hd0,msdos2) (hd0,msdos1)

</div><span style="color:#000000;">What's all this </span><span style="color:#000000;">msdos stuff</span><span style="color:#000000;">? That means this system has the old-style MS-DOS partition table, rather than the shiny new Globally Unique Identifiers partition table (GPT). (See </span>[Using the New GUID Partition Table in Linux (Goodbye Ancient MBR)](https://www.linux.com/learn/tutorials/730440-using-the-new-guid-partition-table-in-linux-good-bye-ancient-mbr-)<span style="color:#000000;"> \[3\]. If you're running GPT it will say </span><span style="color:#000000;">(hd0,gpt1)</span><span style="color:#000000;">. Now let's snoop. Use the </span><span style="color:#000000;">ls</span><span style="color:#000000;"> command to see what files are on your system:</span>

<div id="bkmrk-grub%3E-ls-%28hd0%2C1%29%2F" style="color:#000000;">grub&gt; ls (hd0,1)/

</div><div id="bkmrk-lost%2Bfound%2F-bin%2F-boo" style="color:#000000;">lost+found/ bin/ boot/ cdrom/ dev/ etc/ home/ lib/

</div><div id="bkmrk-lib64%2F-media%2F-mnt%2F-o" style="color:#000000;">lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/

</div><div id="bkmrk-srv%2F-sys%2F-tmp%2F-usr%2F-" style="color:#000000;">srv/ sys/ tmp/ usr/ var/ vmlinuz vmlinuz.old

</div><div id="bkmrk-initrd.img-initrd.im" style="color:#000000;">initrd.img initrd.img.old

</div><span style="color:#000000;">Hurrah, we have found the root filesystem. You can omit the </span><span style="color:#000000;">msdos</span><span style="color:#000000;"> and </span><span style="color:#000000;">gpt</span><span style="color:#000000;"> labels. If you leave off the slash it will print information about the partition. You can read any file on the system with the </span><span style="color:#000000;">cat</span><span style="color:#000000;"> command:</span>

<div id="bkmrk-grub%3E-cat-%28hd0%2C1%29%2Fet" style="color:#000000;">grub&gt; cat (hd0,1)/etc/issue

</div><div id="bkmrk-ubuntu-14.04-lts-%5Cn-" style="color:#000000;">Ubuntu 14.04 LTS \\n \\l

</div><span style="color:#000000;">Reading </span><span style="color:#000000;">/etc/issue</span><span style="color:#000000;"> could be useful on a multi-boot system for identifying your various Linuxes.</span>

### Booting From grub&gt;

<span style="color:#000000;">This is how to set the boot files and boot the system from the </span><span style="color:#000000;">grub&gt;</span><span style="color:#000000;"> prompt. We know from running the </span><span style="color:#000000;">ls</span><span style="color:#000000;"> command that there is a Linux root filesystem on </span><span style="color:#000000;">(hd0,1)</span><span style="color:#000000;">, and you can keep searching until you verify where </span><span style="color:#000000;">/boot/grub</span><span style="color:#000000;"> is. Then run these commands, using your own root partition, kernel, and initrd image:</span>

<div id="bkmrk-grub%3E-set-root%3D%28hd0%2C" style="color:#000000;">grub&gt; set root=(hd0,1)

</div><div id="bkmrk-grub%3E-linux-%2Fboot%2Fvm" style="color:#000000;">grub&gt; linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1

</div><div id="bkmrk-grub%3E-initrd-%2Fboot%2Fi" style="color:#000000;">grub&gt; initrd /boot/initrd.img-3.13.0-29-generic

</div><div id="bkmrk-grub%3E-boot" style="color:#000000;">grub&gt; boot

</div><span style="color:#000000;">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 </span><span style="color:#000000;">/boot/vmli</span><span style="color:#000000;">, and then use tab-completion to fill in the rest. Type </span><span style="color:#000000;">root=/dev/sd</span><span style="color:#000000;">*X*</span><span style="color:#000000;"> 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.</span>

<span style="color:#000000;">The third line sets the </span><span style="color:#000000;">initrd</span><span style="color:#000000;"> file, which must be the same version number as the kernel.</span>

<div id="bkmrk-the-fourth-line-boot" style="color:#000000;">The fourth line boots your system.

</div><div id="bkmrk-on-some-linux-system" style="color:#000000;">On some Linux systems the current kernels and initrds are symlinked into the top level of the root filesystem:

</div><div id="bkmrk-%24-ls--l-%2F" style="color:#000000;">$ ls -l /

</div><div id="bkmrk-vmlinuz--%3E-boot%2Fvmli" style="color:#000000;">vmlinuz -&gt; boot/vmlinuz-3.13.0-29-generic

</div><div id="bkmrk-initrd.img--%3E-boot%2Fi" style="color:#000000;">initrd.img -&gt; boot/initrd.img-3.13.0-29-generic

</div><span style="color:#000000;">So you could boot from </span><span style="color:#000000;">grub&gt;</span><span style="color:#000000;"> like this:</span>

<div id="bkmrk-grub%3E-set-root%3D%28hd0%2C-1" style="color:#000000;">grub&gt; set root=(hd0,1)

</div><div id="bkmrk-grub%3E-linux-%2Fvmlinuz" style="color:#000000;">grub&gt; linux /vmlinuz root=/dev/sda1

</div><div id="bkmrk-grub%3E-initrd-%2Finitrd" style="color:#000000;">grub&gt; initrd /initrd.img

</div><div id="bkmrk-grub%3E-boot-1" style="color:#000000;">grub&gt; boot

</div>### Booting From grub-rescue&gt;

<span style="color:#000000;">If you're in the GRUB rescue shell the commands are different, and you have to load the </span><span style="color:#000000;">normal.mod </span><span style="color:#000000;">and</span><span style="color:#000000;">linux.mod </span><span style="color:#000000;">modules:</span>

<div id="bkmrk-grub-rescue%3E-set-pre" style="color:#000000;">grub rescue&gt; set prefix=(hd0,1)/boot/grub

</div><div id="bkmrk-grub-rescue%3E-set-roo" style="color:#000000;">grub rescue&gt; set root=(hd0,1)

</div><div id="bkmrk-grub-rescue%3E-insmod-" style="color:#000000;">grub rescue&gt; insmod normal

</div><div id="bkmrk-grub-rescue%3E-normal" style="color:#000000;">grub rescue&gt; normal

</div><div id="bkmrk-grub-rescue%3E-insmod--1" style="color:#000000;">grub rescue&gt; insmod linux

</div><div id="bkmrk-grub-rescue%3E-linux-%2F" style="color:#000000;">grub rescue&gt; linux /boot/vmlinuz-3.13.0-29-generic root=/dev/sda1

</div><div id="bkmrk-grub-rescue%3E-initrd-" style="color:#000000;">grub rescue&gt; initrd /boot/initrd.img-3.13.0-29-generic

</div><div id="bkmrk-grub-rescue%3E-boot" style="color:#000000;">grub rescue&gt; boot

</div><div id="bkmrk-tab-completion-shoul" style="color:#000000;">Tab-completion should start working after you load both modules.

</div>### Making Permanent Repairs

<div id="bkmrk-when-you-have-succes" style="color:#000000;">When you have successfully booted your system, run these commands to fix GRUB permanently:

</div><div id="bkmrk-%23-update-grub" style="color:#000000;">\# update-grub

</div><div id="bkmrk-generating-grub-conf" style="color:#000000;">Generating grub configuration file ...

</div><div id="bkmrk-found-background%3A-%2Fu" style="color:#000000;">Found background: /usr/share/images/grub/Apollo\_17\_The\_Last\_Moon\_Shot\_Edit1.tga

</div><div id="bkmrk-found-background-ima" style="color:#000000;">Found background image: /usr/share/images/grub/Apollo\_17\_The\_Last\_Moon\_Shot\_Edit1.tga

</div><div id="bkmrk-found-linux-image%3A-%2F" style="color:#000000;">Found linux image: /boot/vmlinuz-3.13.0-29-generic

</div><div id="bkmrk-found-initrd-image%3A-" style="color:#000000;">Found initrd image: /boot/initrd.img-3.13.0-29-generic

</div><div id="bkmrk-found-linux-image%3A-%2F-1" style="color:#000000;">Found linux image: /boot/vmlinuz-3.13.0-27-generic

</div><div id="bkmrk-found-initrd-image%3A--1" style="color:#000000;">Found initrd image: /boot/initrd.img-3.13.0-27-generic

</div><div id="bkmrk-found-linux-image%3A-%2F-2" style="color:#000000;">Found linux image: /boot/vmlinuz-3.13.0-24-generic

</div><div id="bkmrk-found-initrd-image%3A--2" style="color:#000000;">Found initrd image: /boot/initrd.img-3.13.0-24-generic

</div><div id="bkmrk-found-memtest86%2B-ima" style="color:#000000;">Found memtest86+ image: /boot/memtest86+.elf

</div><div id="bkmrk-found-memtest86%2B-ima-1" style="color:#000000;">Found memtest86+ image: /boot/memtest86+.bin

</div><div id="bkmrk-done" style="color:#000000;">done

</div><div id="bkmrk-%23-grub-install-%2Fdev%2F" style="color:#000000;">\# grub-install /dev/sda

</div><div id="bkmrk-installing-for-i386-" style="color:#000000;">Installing for i386-pc platform.

</div><div id="bkmrk-installation-finishe" style="color:#000000;">Installation finished. No error reported.

</div><span style="color:#000000;">When you run </span><span style="color:#000000;">grub-install</span><span style="color:#000000;"> 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 </span><span style="color:#000000;">/dev/sda1</span><span style="color:#000000;">.</span>

### But It Still Doesn't Work

<span style="color:#000000;">If your system is so messed up that none of this works, try the </span>[Super GRUB2 live rescue disk](http://www.supergrubdisk.org/)<span style="color:#000000;"> \[4\]. The official </span>[GNU GRUB Manual 2.00](https://www.gnu.org/software/grub/manual/grub.html)<span style="color:#000000;"> \[5\] should also be helpful.</span>

<div id="bkmrk-tutorial-category%3A%C2%A0" style="color:#000000;">**Tutorial Category:**

</div>[Tutorials](https://www.linux.com/tutorials/category/tutorials)<span style="color:#000000;"> \[6\]</span>

<div id="bkmrk-source-url%3A%C2%A0https%3A%2F%2F" style="margin-left:0cm;margin-right:0cm;"><span style="color:#000000;">Source URL:</span><span style="color:#000000;"> </span>[<span>https://www.linux.com/learn/how-rescue-non-booting-grub-2-Linux</span>](https://www.linux.com/learn/how-rescue-non-booting-grub-2-Linux)

</div><div id="bkmrk-links%3A%5B1%5D-https%3A%2F%2Fww" style="margin-left:0cm;margin-right:0cm;"><span style="color:#000000;">Links:</span><span style="color:#000000;">\[1\] [https://www.linux.com/learn/how-rescue-non-booting-grub-2-Linux](https://www.linux.com/learn/how-rescue-non-booting-grub-2-Linux)</span><span style="color:#000000;">\[2\] [https://www.linux.com/users/cschroder\[3\]](https://www.linux.com/users/cschroder%5B3%5D)[https://www.linux.com/learn/tutorials/730440-using-the-new-guid-partition-table-in-linux-good-bye-ancient-mbr-\[4\]](https://www.linux.com/learn/tutorials/730440-using-the-new-guid-partition-table-in-linux-good-bye-ancient-mbr-%5B4%5D)[http://www.supergrubdisk.org/\[5\]](http://www.supergrubdisk.org/%5B5%5D)[https://www.gnu.org/software/grub/manual/grub.html\[6\]](https://www.gnu.org/software/grub/manual/grub.html%5B6%5D)[https://www.linux.com/tutorials/category/tutorials](https://www.linux.com/tutorials/category/tutorials)</span>

</div>