School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,151 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,683 people online right now. Registration is fast and FREE... Join Now!




How to recover GRUB after Windows re-install

 
Reply to this topicStart new topic

> How to recover GRUB after Windows re-install

CBart21
Group Icon



post 15 Oct, 2009 - 02:53 PM
Post #1


Have you ever attempted to reinstall Windows Vista on a Windows/Linux dual boot only to find yourself only booting into windows? I recently did! How frustrating! I finally found out how exactly to go about fixing the problem. If you ever find yourself in this situation, I hope these next steps will get you to where you need to be.

NOTE: I am using Windows Vista / Kubuntu 9.04 Dual Boot in this example.

The first thing you need to do is find a Live CD you can boot into. This can be just about any Live CD, but for optimum results use one that shares the same Linux distribution that you use. Boot into this CD and open up a prompt.

The next thing you have to do is find out what device your Linux partition is running on. This can easily be accomplished using the following commands:

CODE
fdisk /dev/xxx


xxx is equal to any of the following directly from fdisk(8) man pages:

(/dev/hd[a-h] for IDE disks, /dev/sd[a-p] for SCSI disks, /dev/ed[a-d] for ESDI disks, /dev/xd[ab] for XT disks)

You will be given a list of options and a prompt to type in your choice. Use the choice 'p' to print your partition table and hit "Enter".

The table will be printed to the screen in which you can deduce which device your Bootable Linux Partition resides in. Once you figure out the device, make a note of the device string. Mine is: "/dev/sda5"

NOTE: There will be two or more Linux Partitions on a simple partition table. One is the root partition and the other will most likely be the Linux Swap partition. Make sure you note the correct device.

Good job! Now you're ready for the meat of the process.

You will need to make a new directory to hold the mounted partition that will be your Linux partition. This will make more sense to you as we progress through the rest of the process. The command is:

CODE
sudo mkdir /mnt/system


Next, you need to mount your Linux partition to this new directory so we can access all the files on your Linux Operating System.

CODE
sudo mount /dev/xxxx /mnt/system


In my case, 'xxxx' would be 'sda5'. You're Linux partition may be different.

The next few steps involve "chroot'ing" into this new mounting partition. When you 'chroot' to a mounted device, you are literally changing the root directory of the LiveCD system to the root directory of the mounted device. What this does is it allows you to run commands directly on the Linux partition that you specify instead of running the commands on the LiveCD.

The first thing you need to do is take control of the root user.

CODE
sudo -i


You do this so you can run the 'chroot' command.

Now, you need to bind the /dev tree from the LiveCD file tree to the mounted Linux Partition using the following command:

CODE
mount -o bind /dev /mnt/system/dev


Now, chroot into our partition.

CODE
chroot /mnt/system


Finally! We are inside our Linux partition. We have one more command left. What this command does is reinstall and configure our Grub Bootloader so that we can boot into either Windows or Linux when we restart.

CODE
grub-install /dev/xxx


'xxx' refers to the three character description representing our hard-drive.

We are finally finished!

All you have to do is restart! We now have choices when we boot up our computer!


**Please note: This post is for my own reference. However, if do find yourself stuck with this little situation, I hope this helps you out!**


P.S. If you want to change the default choices in the bootloader you can edit the file "/boot/grub/menu.lst"


Thanks for reading!


--Chris
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 04:36PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month