Tuesday, November 10, 2009

Rescuing OpenSolaris after installing Windows 7

I recently did a clean install of Windows 7 on my laptop - and lost my OpenSolaris installs on the second partition of the same disk. Having the same problem?

Here's how to make it work again.

Intro
Prior to installing I had two partitons - one with Vista, the other with a bunch of OpenSolaris builds on zfs. W7 will during a clean install repartition its provided space into two partitions - a 100MB boot partition, and the big chunk of "all-the-rest" partition. It will also install its own stuff in the MBR, so any existing grub installs you have will disappear.

Installing Windows 7
Installed W7, connected to wifi, updated - everything in working order there.

Rescuing OpenSolaris
Rescuing the OpenSolaris install(s) requires a series of steps:

1) Make the OpenSolaris partition
active
The easiest way to do this is with a OpenSolaris live-cd. Boot from it, then in a terminal do

pfexec format

This starts format, so be careful. Select the disk containing your missing OpenSolaris install(s). In my case there was only one disk, c4t0d0. Make a note of the disk name, you'll need it later.

Inside format, start fdisk. Select '2' and mark the solaris partition as active. In my case it was the 3rd partition.

Save ('5'), then exit fdisk (quit) and format (quit).

2) Reinstall grub

We also need to reinstall grub in the Master Boot Record (MBR):

pfexec installgrub -m /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c4t0d0s0

The last operand is your root slice - your diskname, prefixed by /dev/rdsk/ and suffixed by s0. Answer 'yes' to overwrite the MBR.

If you reboot now, you should see your old grub menu again. Yippee :)
But you'll only be able to boot the partitions in the grub menu that retained their indexes during the W7 install.

3) Update the grub menu

Since W7 added a new partition - normally at the start of your disk, the revived grub menu will still point to the old partition index. These are now wrong. I had to update my grub menu.lst as all OpenSolaris installs were now on partitions with index+1, due to the added W7 boot partition.

bootadm menu-list

will show you where your current grub menu.lst is located. Mine was at /rpool/boot/grub/menu.lst. Edit the grub menu:

pfexec gedit /rpool/boot/grub/menu.lst

Update the necessary findroot() entries to point to their new partition numbers. I had to update all OpenSolaris partitions from the 2nd to the 3rd partition as follows:

findroot(pool_rpool, 1, a)

to

findroot(pool_rpool, 2, a)

While editing, you can also change the default entry and timeout too if you please. When done rerun 'bootadm menu-list' to see that everything is as desired.

4) Reboot ...
and enjoy your old grub menu with all OpenSolaris installs and W7 :)

That's all there really is to it...

No comments:

Post a Comment