Help - Search - Members - Calendar
Full Version: [HOW TO] Get Your *nix Bootloader Back
Neowin Forums > *nix Customization & Support > Completed *nix HOWTO & FAQs
Hurmoth
I saw where Aaron had written the HOWTO Guide for getting the Windows bootloader back, but what if you're someone who needs their GRUB or LILO back? What then? Well, I found the answer for anyone who might need it biggrin.gif

GRUB
  1. Boot into the first CD
  2. Type linux rescue when asked what to boot.
  3. After you have chosen Language and Keyboard layout, you are asked if you want to mount your harddisk system. Say yes to this.
  4. Now you system is mounted as /mnt/sysimage. Say 'OK'. Now type: chroot /mnt/sysimage. This will make you run on your already installed system, instead of the CD-ROM
  5. Type /sbin/grub-install /dev/hda (change hda to sda if you're using an SATA hard drive)

LILO
  1. Boot into the first CD
  2. Type linux rescue when asked what to boot.
  3. After you have chosen Language and Keyboard layout, you are asked if you want to mount your harddisk system. Say yes to this.
  4. Now you system is mounted as /mnt/sysimage. Say 'OK'. Now type: chroot /mnt/sysimage. This will make you run on your already installed system, instead of the CD-ROM. Now you can edit /etc/lilo.conf if something was wrong (vi /etc/lilo.conf and run lilo), or if you need to reinstall LILO just type lilo. The LILO installation process should now run.
This may be different for different distros and how you may have your system setup. I do not issue any guarantees with this HOWTO. Neowin, nor myself, is responsible if you bork your system. If you have any problems post them here wink.gif
markjensen
Good idea to have this posted thumbs_up.gif I have never had to do this, but many others have had to and have posted questions on it.

Anyone have an addition for doing this for LILO users?
MrA
Just an addendeum. You can install GRUB from within GRUB (this is how I like to do it).
1. Boot from a floppy or CD which uses GRUB as it's bootloader.
2. When you see GRUB's boot-menu, hit 'c'. You should see a "grub>" prompt
3. Type the following commands:
CODE
grub> root (hd0, 0)
grub> setup (hd0)


Commands explained:
"root (hd0, 0)" - This tells grub where it can find grub's files which are normally located in "/boot/grub/". The sample command tells grub that the files are located on the first hard drive, on partition 0 (first partition). If you don't know which drive/partition hold grub's files, you can do a:
CODE
grub> find /boot/grub/stage1

"setup (hd0)" - Tells grub to install itself on the Master Boot Record (MBR) of the first hard drive. You can also tell grub to install onto a partition by doing a "setup (hd0, 1)". This will tell grub to install to the second partition of the first hard drive.

Tips:
- Grub has a "help" command. Use it.
- Grub supports "bash-like" auto-completing. Say you don't quite know the partition number of your linux partition, but you know it's on the first hard drive and you know it's an ext2 partition. You can type:
CODE
grub> root (hd0,
and hit [tab]
This gives me:
CODE
Possible partitions are:
  Partition num: 0,  Filesystem type is reiserfs, partition type 0x83
  Partition num: 1,  Filesystem type is ext2fs, partition type 0x83
  Partition num: 2,  Filesystem type is reiserfs, partition type 0x83

Voila! It's partition number 1. Auto-completeing also works for other grub commands.
Hurmoth
QUOTE(markjensen @ May 26 2005, 15:56)
Anyone have an addition for doing this for LILO users?
[right][snapback]585974127[/snapback][/right]

If anyone adds it, I'll change the title and add it to my first post (giving the person credit of course) wink.gif

QUOTE(markjensen @ May 26 2005, 15:56)
Good idea to have this posted thumbs_up.gif  I have never had to do this, but many others have had to and have posted questions on it.

My boss' GRUB got messed up and wouldn't boot so I had to research how to fix it. The first place I looked was here and all I saw was Armeck's guide to getting the Windows bootloader back.
Kreuger
Yes this is a good post. My grub was messed too (error 18) and I couldn't fix it because Linspire Live couldn't detect my damn hard drive for some reason so I couldn't fix it. Also, when I attempted to go into linuxrecovery of the Debian cd, it wouldn't let me reinstall grub from there.
Hurmoth
I added a way to reinstall LILO using the first installation disc, this can also be done with a Rescue Disc or Floppy Disk. I have never used LILO, so early this morning I installed a fresh copy of FC3 and used LILO instead of GRUB and messed it up on purpose to try and find out how to reinstall LILO... and that is what I came up with. Let me know if I have any typos biggrin.gif
invalidbuffalo
I get the error:
/dev/hda: Not found or not a block device.
when I try to reinstall GRUB.
markjensen
QUOTE(invalidbuffalo @ Jan 18 2006, 15:24) [snapback]587083209[/snapback]

I get the error:
/dev/hda: Not found or not a block device.
when I try to reinstall GRUB.

If you do an fdisk -l (that is a lowercase letter "L", not the number one), what do you get for drives listed? Do you have SATA drives?
invalidbuffalo
QUOTE(markjensen @ Jan 18 2006, 13:52) [snapback]587083354[/snapback]

If you do an fdisk -l (that is a lowercase letter "L", not the number one), what do you get for drives listed? Do you have SATA drives?


Fixed- I guess for SATA drives replace 'hda' with 'sda.' And now I have linux again! w00t!
wildworld_ammsa
hi every one,

i think this topic needs to be a Sticky. if some admin agrees, can he/she plz add it?

Thanx,

Ammsa
Barney
Quote - (wildworld_ammsa @ Jun 16 2006, 06:03) [snapback]587611121[/snapback]


i think this topic needs to be a Sticky. if some admin agrees, can he/she plz add it?



[Pinned]

This may not stay, but we'll see. There is a limit as to how many topics we can "pin". This is a good topic to have handy. w00t.gif

Barney
wildworld_ammsa
from time to time i had to search this topic to link for other ppl so i thought maybe it's a good idea to pin it.

thanx barney,
Hurmoth
Quote - (invalidbuffalo @ Jan 18 2006, 18:10) [snapback]587083474[/snapback]


Fixed- I guess for SATA drives replace 'hda' with 'sda.' And now I have linux again! w00t!

I updated the first post to reflect that. Thanks for pointing that out thumbs_up.gif
gary4gar
i got a error that
Quote -
/boot/grub/stage1 couls not be read
also when i do
Quote -
chroot /mnt/sysimage
it says Not found.i have a sata hdd & ubuntu 5.10.
Rob2687
Which cd are you booting from? I've tried the ubuntu installers and none of them have the linux rescue thing.
stylemessiah
Why lose it in the first place?

Its easy to avoid the entire unpleasantness when installing Linux onto a PC thats already hosts Windows, you just have to think about not upsetting precious windows, after all, its more finicky about its bootsector than Linux is.

Here's what i do:

Install linux.....wait until bootloader setup

Then

* Modify setting if needed to put bootloader on root partition (the partition that hosts \)

Then AFTER bootloader is written and anytime BEFORE you complete installation reboot:

* Switch to a terminal window form the setup GUI, on SuSE 10.1 for example i use CRTL ALT + F5.

* Put a floppy disk in your floppy drive

* Make a folder under /mnt, e.g. md /mnt/floppy (on some linuces, you may need to make an entirely different folder than floppy, as one may already exist and not be able to be written to - dont ask why, ive seen it, in this case try md /mnt/fdtemp etc.)

* Mount your floppy disk, e.g. mount -t vfat /dev/fd0 /mnt/floppy

* Type: dd if=/dev/hdaX of=/mnt/floppy/bootsec.lnx bs=512 count=1

Where X = the root partition number (e.g. /dev/hda11 as it is on mine)

* Browse to the floppy and make sure the bootsec.lnx file is there.

* Complete linux install and reboot into Windows

* Copy bootsec.lnx to c:\

* Keep floppy in a safe place, or copy the bootsec.lnx to a safe place.

* Open boot.ini in notepad

* Add "XXXX Linux" = c:\bootsec.lnx in the OS list under windows.

Where XXXX is the name of the linux or something witty and anti MS

* Save the file.

* Enjoy.

A few seconds work and thinking intelligently means you can avoid the whole bootsector drama completely and not upset either. I havent met a linux yet this isnt possible to use on.

As i said ive been using this since my first forays into Red Hat and Windows 2000, hasnt failed me yet.


Why lose it in the first place?

Its easy to avoid the entire unpleasantness when installing Linux onto a PC thats already hosts Windows, you just have to think about not upsetting precious windows, after all, its more finicky about its bootsector than Linux is.

Here's what i do:

Install linux.....wait until bootloader setup

Then

* Modify setting if needed to put bootloader on root partition (the partition that hosts \)

Then AFTER bootloader is written and anytime BEFORE you complete installation reboot:

* Switch to a terminal window form the setup GUI, on SuSE 10.1 for example i use CRTL ALT + F5.

* Put a floppy disk in your floppy drive

* Make a folder under /mnt, e.g. md /mnt/floppy (on some linuces, you may need to make an entirely different folder than floppy, as one may already exist and not be able to be written to - dont ask why, ive seen it, in this case try md /mnt/fdtemp etc.)

* Mount your floppy disk, e.g. mount -t vfat /dev/fd0 /mnt/floppy

* Type: dd if=/dev/hdaX of=/mnt/floppy/bootsec.lnx bs=512 count=1

Where X = the root partition number (e.g. /dev/hda11 as it is on mine)

* Browse to the floppy and make sure the bootsec.lnx file is there.

* Reboot into Windows

* Copy bootsec.lnx to c:\

* Keep floppy in a safe place, or copy the bootsec.lnx to a safe place.

* Open boot.ini in notepad

* Add "XXXX Linux" = c:\bootsec.lnx in the OS list under windows.

Where XXXX is the name of the linux or something witty and anti MS

* Save the file.

* Enjoy.

A few seconds work and thinking intelligently means you can avoid the whole bootsector drama completely and not upset either. I havent met a linux yet this isnt possible to use on.

As i said ive been using this since my first forays into Red Hat and Windows 2000, hasnt failed me yet.
Omegatron
You can also use a LIVECD distro like Knoppix and install GRUB.. grub-install
HT2791
i really didn't understand the first post (i'm new to linux).
i had to reinstall winxp because dual booting Ubuntu corrupted winxp files.
I got it back by:


Boot the livecd.
Start a terminal.

sudo -i
grub
find /boot/grub/stage1 // Will print something like (hd0,1)
root (hd0,1)
setup (hd0)
quit

was easy for me smile.gif
Biffa001
Hi,

Quote -
Boot the livecd.
Start a terminal.

sudo -i
grub
find /boot/grub/stage1 // Will print something like (hd0,1)
root (hd0,1)
setup (hd0)
quit


I already had winxp installed on my PC and have just installed the latest Ubuntu 7.04, immediately upon reboot I received a grub error 22 and nothing booted! Thanks to my PDA net access and this forum I got my windows bootloader back and then have just followed the above info to try and get a boot screen back to be able to choose either winxp or ubuntu but with no joy.

I just tried the above and it all seemed to go ok (no errors within the terminal window), but when I rebooted my PC it just started up straight into windows xp again....!

Help!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.