Wednesday, October 20, 2010

Grub Problem of installation and uninstalltion

How to uninstall GRUB

Q. How do I uninstall GRUB? I need to uninstall everything before sending this hard disk to someone including GRUB. All I need to keep is windows XP.
A. GNU GRUB ("GRUB" for short) is a boot loader package from the GNU Project. GRUB is the reference implementation of the Multiboot Specification, which allows a user to have several different operating systems on their computer at once, and to choose which one to run when the computer starts.
You can overwrite MBR with standard dd command. You can also use old good MS-DOS fdisk command to overwrite MBR.

Using MS-DOS/Windows 9x boot disk

In order to remove the GRUB bootloader from a Linux and Windows XP machine, boot with a Windows 9x startup disk or CD and execute the MS-DOS command:fdisk /mbr

Using Windows XP boot disk

Boot computer using Windows XP (Windows 2000) setup disc / CD / DVD. Next, type the following commands:# fixmbr
# exit

Using Linux

You can also use dd command from Linux itself (it removes partition table):# dd if=/dev/null of=/dev/sdX bs=512 count=1
Just remove MBR, without the partition table (see comment below):# dd if=/dev/null of=/dev/sdX bs=446 count=1
Replace /dev/hdX with your actual device name such as /dev/hda. Use fdisk -l command to find out device name:# fdisk -l
Output:
Disk /dev/sda: 251.0 GB, 251000193024 bytes
255 heads, 63 sectors/track, 30515 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       30384   243955057+  83  Linux
/dev/sda3           30385       30515     1052257+  82  Linux swap

HOWTO Restore GRUB

You have windows 98 and linux on the same hard disk and you choose GRUB as boot loader.At boot time you see a menu to choose windows or linux.
But one day you reinstall windows 98 and it rewrites your MBR and the menu has gone, now you only can boot windows.
What to do:
Put the redhat boot disk you created on the installation on the floppy drive, boot the system and run grub command
Remember that for grub (hd0,1) means hda (primary controller master), second partition.
Now we need to tell grub where are the grub files:

If you know where they are, type something like:
root (hd0,1)
else if you have no idea, type:
find /boot/grub/stage1


and then the root command with the correct parameters:

setup (hd0)
to install it on hd0, that is MBR of the first HD.

type quit and reboot.
The menu will appear again.
If you want to make some changes to the boot menu, you must edit the file: /boot/grub/menu.lst
A sample menu.lst file is this:
default=0
timeout=5
splashimage=(hd0,1)/boot/grub/splash.xpm.gz

title Red Hat Linux (2.4.18-14)
root (hd0,1)
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/ hdc=ide-scsi
initrd /boot/initrd-2.4.18-14.img
title Red Hat Linux (2.4.18-openmosix3)
root (hd0,1)
kernel /boot/vmlinuz-2.4.18-openmosix3 ro root=/dev/hda2 hdc=ide-scsi
initrd /boot/initrd-2.4.18-openmosix3.img
title WindowsME
rootnoverify (hd0,0)
chainloader +1
Let's see another case
You have windows ME and Red Hat Linux 8.0 with ext3 filesystem on the same hard disk.
But you bought a brand new bigger hard disk and used Norton Ghost to copy the partitions to the new disk. The problem is that when you boot, you could not see the grub menu :[
To repair it:
If you didn't create the boot disk, boot with the Red Hat Linux CD number 1 and choose rescue mode typing:
linux rescue
Now you need to repair the ext3 filesystem because now it's bigger than before and the journal file must be created again
First, check the filesystem:
fsck.ext3 /dev/hda2
Now, create again the journaling ext3 file:
tune2fs -j /dev/hda2
Now mount the root filesystem on /mnt/sysimage and run grub
mount -t ext2 /dev/hda2 /mnt/sysimage
cd /mnt/sysimage
cd sbin
grub

Once started, GRUB will show the command line interface. First, set the GRUB's root device1 to the boot directory, like this:
grub> root (hd0,1)
If you are not sure which partition actually holds these files, use the command find, like this:
grub> find /boot/grub/stage1
This will search for the file name /boot/grub/stage1 and show the devices which contain the file.

Note added by: John Neuhaus
If you are using a separate /boot partition, as the official documentation says:
"... if you have the partition /boot and you install GRUB images into the directory /boot/grub, GRUB recognizes that the images lies under the directory /grub but not /boot/grub"
Then if 'find /boot/grub/stage1' does not find the file, try 'find /grub/stage1'

Once you've set the root device correctly, run the command setup:
grub> setup (hd0)
This command will install GRUB on the MBR in the first drive.
Making a GRUB boot floppy disk
When you need to reinstall GRUB you can boot with your distro CD and enter in rescue mode, but you can avoid this and reinstall GRUB faster by just making a GRUB boot floppy disk.
You can create this disk right now and it will help you in the future, when problems knock your door.
You will need to know where are the files stage1 and stage2, in Red Hat they are on: /usr/share/grub/i386-redhat/
Other distributions keep it on /usr/lib/grub/i386-pc/ and if you don't know where it is, just find it:
find / -name 'stage1'
Once located, enter into the directory, put a floppy disk on the drive (do not mount it) and type:
cd /usr/share/grub/i386-redhat/
dd if=stage1 of=/dev/fd0 bs=512 count=1
dd if=stage2 of=/dev/fd0 bs=512 seek=1
Now your GRUB disk is created. Remember that this disk is not mountable,
it's just a boot image, so if you want to verify it by mounting, errors will appear. Just try to boot with this disk to check if it's working.

No comments:

Post a Comment