For years I have stayed away from ever wanting to mess with grub hoping that with each no os re-install, everything would just work. However, I recently had to face the facts and realize that there is no way for things to just work especially when adding a new 500GB hard drive with windows into the mix. The basic idea of just editing your menu entries just does not seem to be cutting it for me.
Yes I found and read multiple guides but I have yet to ever get grub to actually do what I want by manually editing it. Furthermore, upon a fresh install of linux on a separate hard drive from my windows install, the debian installer decided it a good idea to install grub to sda which is actually a backup drive for my windows 7 install.
There was no way the MBR of that drive could stay that way so I decided it was time to come face to face with grub once and for all…..I conquered.
Basically Grub is the biggest pain-in-the-butt bootloader to setup manually. It uses it’s own drive mapping system (hd0,1 !!??) and everything has to be perfect for it to work. It also runs in stages (stage1 = mbr, stage2 = bootfiles in /boot of hd0, etc…). It’s main configuration lives in /boot/grub/grub.cfg and you are encouraged to not touch this file. Modern versions of grub use scripts in /etc/grub.d to generate the grub.cfg file. You could even do this yourself using the ‘grub-mkconfig’ command.
But lets take my situation. Here’s my drive layout:
sda = Backup Win7 disk
sdb = Main Win7 Disk
sdc = Raid1 Home Dir Disk
sdd = other Raid1 Home Dir Disk
sde = 74GB Raptor With my linux install, one partition /
For me, I wanted to be able to boot to sda, sdb, and obviously sde. Grub stage1 was installed to the MBR of sda. This was eventually overwritten when I ran a dd to sync my windows 7 drives. Therefore, I was no longer able to boot anything at all as grub wasn’t anywhere to be found hence my BIOS would not find a bootloader (I could boot into windows obviously by selecting my boot device but not linux).
My goal was to get grub (and all its stages) installed on my linux drive which I made the first boot device in my BIOS. To the Ubuntu Boot disk we go….
Using my Ubuntu 11.04 boot disk I had, I booted into the live environment and got a root shell ($ sudo su).
I mounted my linux partition containing slash (for me, sde1) to a directory (/mnt) and fiddled with the grub-install command until I finally got it to work! Here’s what I did:
# grub-install –root-directory=/mnt/ /dev/sde
This reinstalled grub to the MBR of sde, and into its living directory on my linux partition in /boot/grub
Basically, it scanned the drives I had, looked for operating environments, and created all the necessary files and configurations for me to be able to boot to them. Now I’m not exactly sure how much reinstalling it actually did as there were already grub files living in there from the Debian install (remember only the MBR of sda was affected while the rest of the grub files still were put on my linux drive in /boot/grub) so it may have just looked over things and fixed problems etc.. but… It Worked!
I rebooted and was greeted with a nice grub boot menu with selection options for all my oss’. I then booted into linux (after some fiddling, look below) and ran
# update-grub
This made sure that everything in the grub.cfg was setup correctly.
(The fiddling)
But there was one more weird problem with a search line in my grub.cfg that disabled me from booting linux and was throwing errors when I booted windows. I kept getting a
error: no argument specified
and was wondering why this not helpful error was popping up. A quick google search returned this which helped me fix the problem manually by editing my grub.cfg (yeah i know, but at this point, I don’t care) basically by making my search line set arguement look like this:
–set=root blah blah blah
instead of this:
–set blah blah blah
So that actually fixed the problem and now I can boot each OS just fine with no problem. Boy has it been a long day….. …… ……
Waking up the next day, I decided that I wanted a custom picture as the backdrop for my grub screen. I found out where the debian splash screen was and identified that it was a png (@ BadxWorse). I found an image I liked that was a jpg and tried that (editing my grub.cfg to point to the new image name). This didn’t work. Was it the resolution or was it the fact that it was a .jpg? I then found a 1080 .png picture and tried that which to my satisfaction, worked a charm!
I might be the happiest person in the world right now…
I knew there was a magical grub install command that would automate the process of setting everything up and I was right. Hopefully this helps people like me who have had trouble with grub and just want stuffs to work.