Reinstalling GRUB 1.99 in Ubuntu 11.04 from LiveCD - Command change

In the new version of GRUB2 that comes with Ubuntu 11.04 (GRUB 1.99) there has been a change in the commands needed to reinstall GRUB2 from the LiveCD.

Firstly, if you are using these instructions to reinstall GRUB2 (1.99) from a LiveCD for an Ubuntu 11.04 (Natty) installation, you must do it from an Ubuntu 11.04 LiveCD.

  1. Boot from the LiveCD, open a terminal and enter:
sudo fdisk -l

You will get an output similar to:

Device Boot Start End Blocks Id System /dev/sda1 * 1 23620 189727618 83 Linux /dev/sda2 23620 24322 5638815 5 Extended /dev/sda5 23620 24322 5638815 82 Linux swap

Now look for a linux partition with the appropriate size (/dev/sda1 in above example).

Note: The device/drive is designated by sdX, with X being the device designation. sda is the first device, sdb is the second, etc. For most users the MBR will be installed to sda, the first drive on their system. The partition is designated by the Y. The first partition is 1, the second is 2. Note the devices and partitions are counted differently.

When you know the device and partition…

  1. Mount the partition containing the Ubuntu installation:
sudo mount /dev/sdXY /mnt

(where XY are the drive/partition… /dev/sda1 in above example, but be SURE to use YOUR drive/partition)

Note: If the user has a separate /boot partition, this must be mounted to /mnt/boot
Note: If the user has a separate /home partition, this must be mounted to /mnt/home.
Encrypted home partitions should work.

The next command is the one that has changed for Ubuntu 11.04 with GRUB2 1.99
“In Grub 1.99, introduced with Ubuntu 11.04, Natty Narwhal, a new switch is available which more clearly defines where the grub folder is placed”

3) Run the grub-install command to reinstall the GRUB2 files from the mounted partition to the proper location and to the MBR of the designated drive:

sudo grub-install --boot-directory=/mnt/boot /dev/sdX

(where X is the drive who’s MBR will be overwritten by the new (stage 1) GRUB bootloader).

  1. Reboot

  2. Open a terminal and enter:

sudo update-grub

(to update the GRUB menu and configuration with any detected OS’s)


For GRUB2 versions prior to 1.99 (ie. as used in Karmic, Lucid, and Maverick), the command in Step 3) should read:

sudo grub-install --root-directory=/mnt /dev/sdX

Further information here:
https://help.ubuntu.com/community/Grub2#Copy_LiveCD_Files

i lost my grub after deleting a windows partition…
now am not able to restore the grub
while following ur steps it is showing like that…
please help me

root@ubuntu:~# fdisk -l

Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 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: 0xb59c4902

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 7 HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2 13 6387 51200000 7 HPFS/NTFS
/dev/sda3 6387 12762 51200000 7 HPFS/NTFS
/dev/sda4 12762 21689 71707649 f W95 Ext’d (LBA)
/dev/sda5 19136 20959 14647296 83 Linux
/dev/sda6 20960 21689 5858304 82 Linux swap / Solaris
root@ubuntu:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
aufs 1477476 97232 1380244 7% /
none 1470588 724 1469864 1% /dev
/dev/sr0 701742 701742 0 100% /cdrom
/dev/loop0 673664 673664 0 100% /rofs
none 1477476 216 1477260 1% /dev/shm
tmpfs 1477476 28 1477448 1% /tmp
none 1477476 104 1477372 1% /var/run
none 1477476 4 1477472 1% /var/lock
/dev/sda3 51199996 10805720 40394276 22% /media/New Volume
/dev/sda2 51199996 32258248 18941748 64% /media/3C822CD1822C9186
/dev/sda1 102396 27552 74844 27% /media/System Reserved
/dev/sda5 14417392 13583680 101348 100% /mnt
root@ubuntu:~# sudo grub-install --boot-directory=/mnt/boot /dev/sda
Unrecognized option `–boot-directory=/mnt/boot’
Usage: grub-install [OPTION] install_device
Install GRUB on your drive.

-h, --help print this message and exit
-v, --version print the version information and exit
–root-directory=DIR install GRUB images under the directory DIR
instead of the root directory
–grub-shell=FILE use FILE as the grub shell
–no-floppy do not probe any floppy drive
–force-lba force GRUB to use LBA mode even for a buggy
BIOS
–recheck probe a device map even if it already exists

INSTALL_DEVICE can be a GRUB device name or a system device filename.

grub-install copies GRUB images into the DIR/boot directory specfied by
–root-directory, and uses the grub shell to install grub into the boot
sector.

Report bugs to bug-grub@gnu.org.
root@ubuntu:~#

Ooops, I must have missed this posting somehow…

Anyway, you missed out the first command, to mount the Linux partition to /mnt:

sudo mount /dev/sda5 /mnt

for your particular setup.