notes on installing grub on a disk that is not mounted as root

  • boot the system with a live usb
  • make sure that the system hard drive is mounted. Find out what its block device name is and on what folder it is mounted. For this you might want to use the "df" command.
  • make yourself the super user by issuing the command "sudo su -"
  • use the mount command to mount the /dev and /proc mounts to "mountpoint"/dev and "mountpoint"/proc
  • chroot into "mountpoint"
  • run the following command "grub-install "blockdevname"

Let's assume that your system is booted via live usb, and the partition on which you have your operating system is /dev/sda3, and that partition is mounted as /mnt/hdsystem, "blockdevname" is /dev/sda (note that it is /dev/sda, it is NOT!!! /dev/sda3!!!), and "mountpoint" is /mnt/hdsystem.

Comments

I have been allowed by wmack to update the instructions for repairing GRUB (or GRand Unified Bootloader) on a non-root drive:

In the 2nd bullet point, the df command is mentioned. The most verbose form of this to use is 'df -v'. Regarding the 4th bullet point where it says,

'use the mount command to mount the /dev and /proc mounts to mountpoint"/dev and "mountpoint"/proc',

the form needed is

mount --bind OLDDIR NEWDIR

(note the double dash) or, alternatively,

mount -B OLDDIR NEWDIR

(single dash). The term OLDDIR should be replaced with /dev (then /proc in the second execution) and the NEWDIR term is where the full path name for the "mountpoint"/dev (or "mountpoint"/proc in the second execution) directory should go.

The purpose of this step is to make the information in the /dev and /proc directories of the non-root drive appear local. The grub-install command will then use it to rebuild the master boot record of the non-root drive in the execution of the last step. These mounts are temporary in nature and can be unmounted manually afterwards or they will simply vanish after a reboot.

As a convenience, by the way, while typing in a long "mountpoint" path name, make use of the Tab key. After typing the first few letters of each directory in the path (where the non-root drive is mounted for example), press Tab and the system will finish typing for you from entries found in the directory. Here is an example of how to use this feature:

Say the "mountpoint" is /media/ubuntu/73d8a4b4d7f549429f23fe406052a588 (device IDs are machine generated and will sometimes be used to name the "mountpoint" directory). In this case, the command to be typed in at command line is:

mount --bind /dev /media/ubuntu/73d8a4b4d7f549429f23fe406052a588/dev

If you start typing:

mount --bind /dev /media/ubuntu/73

...and then press Tab. The system will search the /media/ubuntu directory for a file or directory whose name begins with 73. The result will be provided in the command line. If there are multiple entries, they will all be shown so you can further refine your input by adding more characters into the command and pressing Tab again.

Lastly, in the 5th bullet point where it says, 'chroot into "mountpoint" ', the correct format is:

chroot NEWROOT

...where NEWROOT is the "mountpoint" which, in the example above, would be /media/ubuntu/73d8a4b4d7f549429f23fe406052a588. Thus the correct format would be:

chroot /media/ubuntu/73d8a4b4d7f549429f23fe406052a588

~respectfully submitted by gauchocollie on 3/8/2015