Reinstalling Grub from a Live CD
June 19th, 2009
Repost: This happened back in Feburary 2009 and was posted as “Disaster Averted” mainly to annoy my students with the fact that class was *almost* cancelled that night. I’m reposting it with a more accurate title for searching purposes (read: I needed to find this again but couldn’t because of my annoying title).
When I got to campus today and turned on my laptop, I was greeted with an all black screen and just the word “GRUB”.
Shit.
Some quick background for my students… GRUB is one of the bootloaders available for Fedora. In short, a bootloader is what takes control from the BIOS at boot time and passes it to the operating system. No bootloader = no operating system. So here I found myself, on campus needing my laptop for class tonight, without anything to help me.
That last part needs some elaboration. Fedora added a really cool feature where the Fedora installation can be installed to a USB drive. While I was at Red Hat Summit last year, I got Fedora 9 installed to the USB drive they gave out as swag. That doesn’t really help much since I kept forgetting to swap out the USB drive on my keys with my newly pimped out Fedora install stick.
My forgetfulness came back to bite me, since when I needed it most, what should have been an extremely conveniently located live Fedora install is sitting in my office at home, a few feet away from half a dozen Live CDs of various Linux distros that also would have been helpful to have around.
That aside, this was actually sort of cool in a way. While studying for my RHCE, I found new and creative ways to destroy a Red Hat installation to practice for the exam. I had managed to run into this exact issue and knew how to fix it, I just needed some form of rescue CD to do it.
The first half of that was easy, I logged into a machine in the lab and downloaded the Fedora 10 ISO from fedoraproject.org (insert generic “Try that with Windows” comment here). Thankfully, the lab machines have CD burners. However, I needed to find a CD first. Having no luck digging around the lab, I went downstairs to the university IT department’s tech helpdesk.
“Are you a student?”
Ok, so it was a fair question to ask me. It’s the last class before Spring Break and I’m not feeling well, so I’m here in a Villanova sweatshirt, jeans, and sneakers.
“No, I’m a professor. I need the CD for class tonight.”
“Really?”
“I assure you, I’m not a student.”
Thankfully, one of my students last semester had introduced me to one of the IT guys in the room who recognized me and vouched for my employment. I can’t really fault them for asking; I’d get annoyed too if a student bust in the helpdesk asking for free stuff.
One burnt CD later and I was into the Live CD. A few commands after that, I rebooted sans CD and was up and running.
Which brings me to the meat of this post, how to reinstall GRUB from a Live CD. It’s actually pretty simple. After booting into rescue mode, run:
grub
That’ll bring you into the interactive GRUB shell (notice the prompt changes to “grub>”).
grub> find /grub/grub.conf (hd0,0) grub> root (hd0,0) grub> setup (hd0)
The find command was just to verify the hard drive where the boot files are located. The setup command completed almost instantly, which actually had me a bit worried that it did nothing. But the output looked pretty convincing:
Checking if "/boot/grub/stage1" exists... no Checking if "/grub/stage1" exists... yes Checking if "/grub/stage2" exists... yes Checking if "/grub/e2fs_stage1_5" exists... yes Running "embed /grub/e2fs_stage1_5 (hd0)"... 16 sectors are embedded... succeeded Running "install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded Done.
After that, it was as simple as rebooting without the CD. I’ll still need to look around to make sure nothing else is messed up, and even more disconcerting is what caused this in the first place. But for now, at least I’m not stranded on campus with a dead laptop.
In the meantime, hopefully now I’ll remember to put the damn bootable USB stick on my keys… (Update: I put it on my keys that night when I got home from class)
I can’t help but think of this xkcd comic which feels kinda relevant right now.


You
June 19th, 2009 at 4:51 pm
I needed to do something similar recently. However the one step that I could not figure out has not been elaborated on:
“…After booting into rescue mode, run…”
How do you boot into rescue mode from a live cd? (I had to rummage around and find an old install dvd from which I was able to follow an online tutorial, but that was not too convenient.)
Jay
June 19th, 2009 at 9:04 pm
Ahh, that was a typo on my part. I did actually mean install CD. Thanks for the pick up.
I suspect you could just open a terminal from within the OS instance started by the live CD, but I’m not 100% sure on that one (will have to give it a shot to see).