Triple Boot, Part 5: Reinstalling GRUB

<< Back to Part 4, Windows via VirtualBox

This is the only blog entry in this series that I have not actually performed on my laptop.  Instead, I experimented with the instructions in a virtual environment, using VirtualBox.  The standard disclaimers apply:

  • I am describing a single hard drive system
  • Messing around with the partitions and the Master Boot Record (MBR) on a disk can be dangerous.  Always back up your data first.  If you're really nervous (like me) experiment in a virtual environment first.

The inspiration for this entry came from a comment posted by Luca Morettoni over on Part 2: Install Ubuntu:

I have only one question: when you update the linux os and the system install a new kernel, \*probably\* it overwrite the OpenSolaris grub installation, or not? If yes, there is a workaround or I need to reinstall OpenSolaris grub (eg. from a liveCD)?

In my experience, a typical update of a GNU/Linux distribution does not overwrite whatever GRUB you have installed on your hard drive (although the menu.lst entries might get changed).  For example, on my old laptop I did an online update of Ubuntu from 7.04 to 7.10 and the GRUB was unchanged.

Doing a second installation (in other words, a re-install) of a GNU/Linux distribution, however, will typically overwrite whatever GRUB you have installed.  I believe there are also some situations where installing service packs for Windows will overwrite the current MBR, which would mean that the partition with OpenSolaris would no longer be marked as Active.

So the question remains: if the GRUB installed by OpenSolaris 2008.05 gets overwritten or superseded, how do you restore it?

The process is fairly easy.  I started by booting the LiveCD of OpenSolaris 2008.05.  I opened a terminal window after the desktop is displayed.  The command to use is installgrub.  If you look at the man page for installgrub, you will see that it requires three parameters.  The third parameter is the raw-device name.  Note this important piece of information from the man page about that name: "For disk devices, specify the slice where the GRUB menu file is located."

The slice? What's up with that? Since my laptop is an x86 system, I had thought that partitions are the only subdivisions of the hard drive that matter.  As Johan Hartzenberg explains so well in this blog entry, however, that is not the case. OpenSolaris uses slices to do a further subdivision of the partition on which it is installed.

The GRUB menu file is in the root slice, so you will need to know the number for the root slice. To find that out, I used this command:

$ pfexec prtvtoc /dev/rdsk/c5d0s2
\* /dev/rdsk/c5d0s2 partition map
\* Dimensions:
\*     512 bytes/sector
\*      63 sectors/track
\*     255 tracks/cylinder
\*   16065 sectors/cylinder
\*    9297 cylinders
\*    9295 accessible cylinders
\* Flags:
\*   1: unmountable
\*  10: read-only
\*                          First     Sector    Last
\* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
       0      2    00    4209030 145115145 149324174
       1      3    01      16065   4192965   4209029
       2      5    01          0 149324175 149324174
       8      1    01          0     16065     16064

Notice that the device name that I passed to prtvtoc includes a slice number: s2.  By convention s2 means the "entire disk." And therein lies the potential for confusion.  Within the context of these commands, when run on an x86/x64 system, the "entire disk" means: just the partition of the hard drive that contains OpenSolaris. In the output of prtvtoc the final table has a column heading labeled "Partition."  The "partition" numbers displayed by prtvtoc are not primary or extended partitions on my hard drive - they are instead slices within the primary partition that contains OpenSolaris. 

The Tag value for slice 0 is 2, indicating slice 0 is the root slice.  That means the syntax for the installgrub command would be:

$ pfexec installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c5d0s0 

An important note: by default installgrub does not modify the MBR. And depending on your situation, that might be what you want.  For example, if you are happy with the GRUB that a Linux installation wrote to the MBR then after running installgrub you can chainload the OpenSolaris GRUB by adding an entry to the /boot/grub/menu.lst that is used by your GNU/Linux distribution.  As an example:

title OpenSolaris 2008.05
rootnoverify (hd0,2)
chainloader +1

If, however, you do want the OpenSolaris GRUB installed to the MBR, specify the -m flag on the installgrub command line:

$ pfexec installgrub -m /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c5d0s0 

After installing to the MBR you will see the OpenSolaris GRUB menu when you boot from the hard drive.  If the reason you went through all this was because the installation of a GNU/Linux distribution replaced your OpenSolaris GRUB, then you need to make sure the entries in the menu.lst that the OpenSolaris GRUB uses are correct for your new GNU/Linux kernel.  At the very least, the UUID will be different, as shown in this example: 

# title        Ubuntu 8.04, kernel 2.6.24-16-generic
# root        (hd0,4)
# kernel        /vmlinuz-2.6.24-16-generic root=UUID=61d0afdc-4e12-4d74-a1ae-388ff74d7630 ro quiet splash
# initrd        /initrd.img-2.6.24-16-generic
# quiet

# title        Ubuntu 8.04, kernel 2.6.24-16-generic (recovery mode)
# root        (hd0,4)
# kernel        /vmlinuz-2.6.24-16-generic root=UUID=61d0afdc-4e12-4d74-a1ae-388ff74d7630 ro single
# initrd        /initrd.img-2.6.24-16-generic 

title		Ubuntu 8.04, kernel 2.6.24-16-generic
root		(hd0,4)
kernel		/vmlinuz-2.6.24-16-generic root=UUID=276561b9-09ea-45e7-9fbc-d2f4a273fcd9 ro quiet splash
initrd		/initrd.img-2.6.24-16-generic

title		Ubuntu 8.04, kernel 2.6.24-16-generic (recovery mode)
root		(hd0,4)
kernel		/vmlinuz-2.6.24-16-generic root=UUID=276561b9-09ea-45e7-9fbc-d2f4a273fcd9 ro single
Ôü×initrd		/initrd.img-2.6.24-16-generic


Very good article!!!

Thank you very much for this very important and interesting article!

Your Blog is very good!

It helped me to solve many of my problems as a Newby-Open-Solaris user!

Posted by Gerry on August 12, 2008 at 02:50 PM GMT #

Great article, I've been playing around with multi boot on my laptop as well and managed to get OpenSolaris, Ubuntu, Fedora and OpenSUSE all running on the machine with all the linux distributions on an exteneded partition.

If I may suggest that you take a look at creating a dedicated GRUB partition, as desribed at

The benefit of this kind of setup is that you don't have to worry about changing OpenSolaris' menu.lst every time Ubuntu has a kernel upgrade. The downside is that you have to specify during the Ubuntu install to only set up GRUB on the 'root' (according to Ubuntu) partition instead of the disk MBR. (Ubuntu, Fedora and OpenSUSE all support this in their installers)

Posted by Srdan Dukic on August 15, 2008 at 11:40 PM GMT #

Observatory rocks. This is a great effort from you guys. Thanks a lot.

Posted by ashwin on August 23, 2008 at 01:20 PM GMT #

You guys rock. This makes our work (Campus Ambassador Tech Lead) so much easier!

Posted by Angad Singh on October 12, 2008 at 12:54 AM GMT #

This is one of the most useful posts! Thanks!

Is it also valid with OpenSolaris 2008.11?

Posted by Maurizio Lombardi on January 10, 2009 at 03:55 AM GMT #

Nowadays, when most of Linux distros permit installing their own boot records (stage 1) into partition where the Linux dostro is going to be installed (unlike putting it into MBR) it's sometimes handy to just chainload such system from within OpenSolaris menu.lst eg:

title YourOS
rootnoverify (hd0,2)
chainloader +1

instead of taking care of manual changes in OpenSolaris' menu.lst each time one upgrades/reinstall such OS

more under:

You may consider even creating a dedicated /boot partition near the beginning of your disc (first sectors) in order to avoid some addressing problems when BIOS does not allow you to install grub (stage 1) on its own partition because it is very far

Another advantage (apart that such system always stays up to dated in terms of its own menu.lst contents so you can trust/rely on it when it comes to kernel and initrd strings) is that you avoid some GRUB incompatibilities from OS to OS like the one described in the comments for article:

about OpenSolaris and Debian coexistence and replied by Gregg Sporar saying:

"install Debian's GRUB on the partition that you use for Debian (instead of installing Debian's GRUB on the Master Boot Record)"

which simply off-loads from (sometimes constant) changes in YourOS kernel

Posted by Jacek Laska on April 21, 2009 at 06:54 AM GMT #

Unfortunately, this does not work for me (in 2009.06).
According to prtvtoc, my root slice is c9d0s0, so I do the following:

$ pfexec installgrub -m /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c9d0s0

With the following output:
Updating master boot sector destroys existing boot managers (if any).
continue (y/n)?y
stage1 written to partition 2 sector 0 (abs 419425020)
stage2 read/write error: read 512 bytes, wrote -1 bytes
stage2 written to partition 2, 216 sectors starting at 50 (abs 519425070)
cannot open/stat device /dev/rdsk/c9d0p0

(note the p0 in the last line, even though I have no clue myself, what it means)

After that, the system is pretty much dead. Menues don't work, programs won't start up, even an "ls" in the current terminal does nothing.

Note: This is a new computer, so it shouldn't be a hardware problem. Furthermore, I have the following partition setup: Win7 in primary1, WinXP on primary2, OpenS on primary3, Ubuntu 9.04 in extended.

After I had to reinstall Windows, I couldn't get GRUB installed any more (OpenSolaris with the issue at hand, Ubuntu has some Inodesize issues).
BUT, if I fire up the OpenSolaris LiveCD, and as soon as the CD GRUB comes up, I go to manual, and rootnoverify (hd0,2) with chainloader +1, I will get the menu.lst which belongs to my installed OpenSolaris -_-

Posted by Harry on June 24, 2009 at 03:08 PM GMT #

I have partitions of Ubuntu, 64 bit Ubuntu and PC-BSD on the same disk as OpenSolaris. Initially I could not get OS to act like a bootable partition as it required its own MBR. After reading this and other stuff I was able to get OS to behave. Ask Google about Solaris and menu.lst and it will lead to a Sun page on planning to install Solaris. Use "bootadm menu-list" to find menu.lst. Running installgrub as explained above will get a report of where it has put the two stages. The unspoken requirement is that most of this stuff has to be run as "su"! The Sun naming conventions for devices are so different that one has to be careful after using others. ;-(

I noticed that the initial OS install would work without its MBR if it was started from another GRUB but I wanted the partitions to be independent so that I can delete them without worrying that another will start to fail when i try something else. GAG can start all the bootable partitions although I would be happier if it had slightly better graphics. But it fits in a small space and works.

Posted by Gordon Sande on August 02, 2009 at 08:17 AM GMT #

thanks for all info. what i'm \*still\* not clear on is:
how to properly proceed in the case of 2 separate drives?
could i simply install each respective grub (opensol/linux) to the beginning of the respective drive?
(i.e. opensol 'grub-ver' = opensol disk(2), and linux 'grub' to mbr (beginning) of linux disk (1). IOW: i wish to have linux occupy 1st disk (total disk), and opensol (only) on total 2nd disk; choosing preferred os at boot. can this be done smoothly and stable??
TIA.. .. ..
Have A Healthy, Prosperous Day!

Posted by robert h. williams on September 21, 2009 at 05:50 PM GMT #

Thank you!! This blog entry saved my computer! I wasn't sure if I'd be able to boot into it again, or if I'd have to wipe the drive and re-install. Back to normal. Phew!

Posted by Ryan on November 08, 2009 at 09:12 PM GMT #

Post a Comment:
  • HTML Syntax: NOT allowed

The Observatory is a blog for users of Oracle Solaris. Tune in here for tips, tricks and more as we explore the Solaris operating system from Oracle.


« July 2016