jump to navigation

How to restore GRUB2 using an Ubuntu Live CD or Thumb Drive 09/02/2010

Posted by muyiscoi in Guides.
Tags: , , ,

If you are a tinkerer like me, you will no doubt run into some problems with grub at one time or another.
Even though you do not tinker, you might still have a problem with grub especially if dual-boot your system with windows. In that case, the windows boot-loader overwrites GRUB in the Master boot record (MBR) (if you install Ubuntu first) thereby rendering your Linux partition not bootable. It has been a major bottleneck for a lot of Ubuntu users when they can no longer boot into their desktop and most times are forced to reinstall.

It is however, relatively easy to restore GRUB on your computer irrespective of how you lost it in the first place.
The only requirements are that you still have a healthy installation of Ubuntu on your machine and a ready live CD or a USB thumb drive with Ubuntu loaded on it.

I will assume that the readers of this post have some level of knowledge on how to get certain things done on Ubuntu so i will not be too specific in some areas. if anything is unclear, you can ask it in the comments and i will be glad to clarify.

First, you have to boot the live CD. If you are using a thumb drive, also boot from it.
After booting, you have to determine which of your hard-disk partitions is the root (/) partition. You can do this by typing

sudo fdisk -l

in the terminal.
Note: If you only have one partition or you already know the address of your root partition, you can skip this step.

The output of the above command on my computer is as shown below

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb21e563c

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       15147   121664576    7  HPFS/NTFS
/dev/sda2           15148       15427     2249100   82  Linux swap / Solaris
/dev/sda3           15428       30401   120277697+   f  W95 Ext'd (LBA)
/dev/sda5           15428       17251    14649344   83  Linux
/dev/sda6           17252       30401   105627343+  83  Linux

Admittedly, this can be a little confusing and might not really tell you which of your partitions is the root partition. Most of the time, what i do is to open up the file manager (nautilus) and check for the partition that resembles my root partition either as a result of the size or maybe a label (if you’re d kinda person that does that). i will then mount that partition from nautilus. After that, i go to the terminal and type the following

$ cat /etc/mtab

Amongst all the text that will be printed, the one containing the address of your root partition will be there. This is the output from my own system. Note that this will not show up if the partition is not mounted so ensure that only the root partiton is mounted so u dont get confused. alternatively, you can use gparted to also know the partiton address of the root partition.

/dev/sda5 /media/a2455o3f539io43pofp342 ext4 rw,errors=remount-ro 0 0
proc /proc proc rw,noexec,nosuid,nodev 0 0
none /sys sysfs rw,noexec,nosuid,nodev 0 0
none /sys/fs/fuse/connections fusectl rw 0 0
none /sys/kernel/debug debugfs rw 0 0
none /sys/kernel/security securityfs rw 0 0
none /dev devtmpfs rw,mode=0755 0 0
none /dev/pts devpts rw,noexec,nosuid,gid=5,mode=0620 0 0
none /dev/shm tmpfs rw,nosuid,nodev 0 0
none /var/run tmpfs rw,nosuid,mode=0755 0 0
none /var/lock tmpfs rw,noexec,nosuid,nodev 0 0
none /lib/init/rw tmpfs rw,nosuid,mode=0755 0

The line showing my root partition is highlighted in bold on d text above. From this, you can deduce the address of your root partition. I can see that mine is /dev/sda5. Once this has been done, the next step is to mount that partiton in a more easily accessible place.  Ubuntu will by default mount the partition according to its UUID (Universally Unique Identifier) in the /media folder as you can see above. However, this makes for a very long file path and makes it very easy to make a mistake.

Go to nautilus again and this time, unmount the previously mounted partition.

Then, use the terminal to mount that partition in the /mnt folder.
In my case, i will use the following command

$ sudo mount /dev/sda5 /mnt

Replace /dev/sda5 with a appropriate address for your root partition gotten above.

after this, it is time to install grub2. To do this, use the following command

$ sudo grub-install --root-directory=/mnt /dev/sda

This command should not be edited if you followed all the steps above. this installs grub2 in the MBR of the Harddisk. This will take a short while after which a confirmatory message will come up.

That is it. To confirm your settings, type in

$ sudo update-grub

in the terminal. However, even if this gives an error message, most of the time, the installation is already done. If you receive an error message though, you might not see other operating systems on your Computer especially if they were installed after the Ubuntu installation. To remedy this, boot into your freshly repaired Ubuntu and run the above command from there. That should sort it out.

So, that’s it. I hope this helps someone out there get out of a bind. Any further questions can be posted on the comments.

Source: Ubuntu Wiki

About these ads


1. DrLuv - 09/02/2010

Great post! I’ve done this several times. This works with most if not all distros. However, I will like to add that should you wish to still continue dual booting after this procedure, you might have to edit your /boot/grub/grub.conf or /boot/grub/menu.lst (which is a symbolic link to /boot/grub/grub.conf anyway).

muyiscoi - 09/02/2010

thanks. This post is for grub2. in grub2, /boot/grub/menu.lst has been replaced with /boot/grub/grub.cfg which is not edited but instead, the file in /etc/defualt/grub is edited and then, running “update-grub” applies the changes to /boot/grub/grub.cfg. Grub2 has been the default in ubuntu since 10.04 i think. however, for any older version of ubuntu (and other distros) running grub legacy, the steps you outlined in your comments would work.

For adding new OSes in grub2, simply running update-grub would suffice most of the time as it will auto detect all the OSes on the computer and let you know the ones it detects. This is an improvement on grub-legacy

2. DrLuv - 09/02/2010

Nice! I didn’t even know that. Great info!

3. 4llerbuntu - 09/03/2010

@ muyi did u actually use this?

becos i wrote this too (the one i was talking abt)
there is a step thats missing….. u need to bind /dev and /proc for grub2 else your changes wont stay.

this is trying to do a fresh install of grub2 in /
i believe you need to bind the specific paths else………..

4. misaac - 09/03/2010

Nawa for you o. Muyiscoi. I am envious of your posting prowess. I wish I had thoughtful topics to post on too. Nice work and keep it up

muyiscoi - 09/03/2010

thank you oh. it’s mostly past experience that gives me d ideas of what to post. things dat have happened to me dat i tink might also affect others

5. Hexen-Brett - 03/26/2012


How to restore GRUB2 using an Ubuntu Live CD or Thumb Drive « Bringing Free and Open source to Nigeria…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: