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
   (hd0,1)

> 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


[via ubuntuforums.org]

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
OR
$ 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. :)

Wednesday, February 21, 2007

Ubuntu hack for waking up your monitor

Sometimes, when I close the lid of my Dell E1505 laptop and open it again, the monitor doesn't resume and stays black instead. Today, I discovered a little hack to get the monitor working again instead of just doing a hard reboot. Press [Fn] + [Esc / Stand By] which suspends the computer, close the lid, open it, and bam...the monitor works and it decreases the chances of corrupt system files.

Wednesday, February 14, 2007

Google Pages Static Link rewriter script

On my Google Pages site, the links to my uploaded files suddenly stopped working. They changed from http://<myusername>.googlepages.com/theFile.ext to http://pages.google.com/-/static_files/theFile.ext where they would give me a 404 Not Found Error. This script is devoted to changing the links back so I can access my files.


// ==UserScript==
// @name Google Pages Static Files
// @description Rewrite "static files" on GooglePages to point to correct locations
// @include http://*.googlepages.com/*
// @version 0.1
// ==/UserScript==


//Get googlepages user to use in rewriting the links
var user = window.location.href.split(".")[0].replace("http://", "");


window.addEventListener('load',
function() {
//Use XPath to find all <a> elements with href attrib
var links = document.evaluate('//a[@href]',document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);


//Rewrite all links with "http://pages.google.com/-/static_files" to <user>.googlepages.com
for (i = 0; i < links.snapshotLength; i++) {
if ( links.snapshotItem(i).href.indexOf("http://pages.google.com/-/static_files") != -1 )
links.snapshotItem(i).href = links.snapshotItem(i).href.replace("pages.google.com/-/static_files", user + ".googlepages.com");
}
}, true);

Install Google Pages Static Files script (userscripts.org | mirror)

Saturday, February 3, 2007

Windows Live Mail Autofill script

Firefox 2 apparently can't fill in the username/password on the Windows Live Mail sign-in page so I wrote a short greasemonkey script to do so.

here is the source:
// ==UserScript==
// @name Windows Live Sign In
// @description Automatically sign in to Windows Live Mail cause Firefox can't
// @include http://login.live.com/*
// @include https://login.live.com/*
// @version 0.1
// ==/UserScript==

//add event listener to call my anonymous function after the page loads
window.addEventListener('load',
function() {
//Get email address box and fill it
document.getElementById("i0116").value = "YOUR_USERNAME";

//Get password box and fill it
document.getElementById("i0118").value = "YOUR_PASSWORD";
}, true);


Install Windows Live Mail Autofill script (from userscripts.org)
Install Windows Live Mail Autofill script (from mirror -- if userscripts.org is down)

To get the script to work, change the values for YOUR_USERNAME and YOUR_PASSWORD to their correct values. Then go to mail.live.com and test it out