Sunday, July 22, 2007

Re-install GRUB after Windows install deletes it

Dual booting Windows and Linux gone wrong

When websites have tutorials about dual-booting Windows and Linux, they usually say to install Windows first and then install Linux after it. The reason for this is because Linux's bootloader detects your Windows partition and allows you to boot into it whereas Windows overwrites Linux's bootloader and replaces it with its own which only allows you to boot Windows. So that's why I install Windows first.

However, my Windows installation started acting unstable and I decided to reinstall it. Afterwards, I couldn't boot into Ubuntu (and Windows couldn't connect to the Internet, have the right resolution, etc. because I needed to reinstall the drivers...and everyone always talks about how everything "just works" after an install).

Reinstall GRUB

So this little tutorial tells you how to reinstall GRUB so you could choose your OS instead of being locked into one (and so you could reinstall Windows as necessary without worrying about breaking Linux).

If you use LILO or another bootloader, you could probably just google it. However, some suggestions don't work if you're repairing the MBR (Master Boot Record) from a LiveCD.

The Code

The following steps worked when I booted off the Ubuntu 6.10 LiveCD to repair the MBR but they should work on any CD that has GRUB.

Open a terminal and type the following in. The "#" is the prompt for root.

# grub
> find /boot/grub/stage1

> root (hd0, 1)
> setup (hd0)


> quit

How it works

The grub command takes you into the grub shell

  • the first line finds out on which hard drive and partition grub is installed on. In my case (hd0, 1), grub is installed on the first (and only) hd0 hard drive on the second partition (0 is the first)

  • the second line switches to the hdd and partition where grub is installed

  • setup tells grub to install itself onto the MBR so that grub becomes your default bootloader when booting off that hard drive


Turn off system beep in Linux terminal

There are a variety of ways to turn of the system beep. I have tried three of them on my Ubuntu Feisty laptop and they both work in terminal emulators like gnome-terminal, etc. and in the virtual terminals.

Temporarily turn it off
$ xset b off
$ setterm -blength 0

Permanently (although you could change it later) turn it off
- uncomment(as root) "# set bell-style none" in /etc/inputrc

- Or to change it to a visual bell (blinking the screen), change it to "set bell-style visual"
- If you only want to do it for the current user instead of for everyone, create an "~/.inputrc" file and add the set bell-style line to that file.

Some of the other ways include deleting or blacklisting your internal speaker. Or if you prefer the hardware/cross-platform approach, take it out manually. :)