GRUB me the wrong way and I just may lose some data

Earlier this month we released OpenSolaris 2008.05 - a distribution of OpenSolaris that, so far, runs on any modern Intel/AMD/VIA processor.  This past weekend I decided to enter the fray into the
world of multiboot-ability with GRUB and see just how fun prowling the multiboot world can get! 

Thanks to lots of good documentation floating on the 'net  (that our friends at google make so easily accessible at the dyer time of need) - and most importantly thanks to our very own Partition Magician - good colleague Bob Netherton, for offering
some very inquisitive pointers at the very right time ....thus saving me from myself on more then one occasion. Bob - you r0ck!  Additionally this is one good GRUB reference I would recommend anyone beginning to tinker with GRUB.

So - what have I learned through it all?   Don't use parttype
in grub w/out having first jotted down what your disk geometry looks like - for starters.  Grub's parttype command allows you to specify the type of the partition.  Given the original PC's limitations of 4 primary partitions - and only one Solaris parition being available at any given time, it took some whimsical thinking to plow through some of the challenges that I wedged myself with right off the bat ...

What did I start off with ?

I started off with a fairly common entry-level environment - a PC that has 1 physical disk with the following partitions:

WinXP, Recovery Partition (provided by the PC vendor), Solaris Express Developer Edition 1/08 (that I had previously installed), and a FAT32 partition that I have data on, that I use for sharing across the Windows and SXDE partitions.  Without knowing any better, right off the bat, I managed to wedge my PC into thinking that the FAT32 partition is now a ext3 partition...or was it ext2... or was it fat.... and not having known to just be careful about plowing head-in, I almost ran for the recovery DVD's to re-start the entire process from scratch. 

Scratch is what I did, but not the PC but my own head. It hurt quite a bit, to have to realise that the only way forward was to succumb to the fact that with an innocentlly executed parttype command, a partition that was formerly known to be of one type, now could no longer be seen by anything.  OUCH. I guess I could've anticipated that - and in retrospect I am not surprised by my actions.  Thank G-D for Backups! :-)

Now, what did I set out to achieve ?

I wanted to have a partition running with OpenSolaris 2008.05  in such a way that would still allow me to boot into SXDE and Windows XP.  There can only be one Solaris parition on a disk, and so the trickery that is involved is (although well documented by Bob here) still needs to take place. And with the version of GRUB that OpenSolaris comes with, relying on the reviously only-supplied-by-Fedora Core-version-of-Grub on this machine was not necessary.

I ended up deleting (in a planned fashion) a Recovery Partition and shrinking the Windows XP partition, to combine a 11GB worth of disk space to be made available to OpenSolaris. Now, it doesn't really need that much - only about 3GB or so, but I know I'll be installing various types of packages over time so thought may as well have the space available now.  I had formatted that newly created partition into ext3 (Linux) for the purposes of then relying on Grub to act as a switch between ext3 and Solaris.  Because of the limitation that there can only be one Solaris partition (not sure where that comes from - if anyone knows, please feel free to comment - I haven't googled this yet :-), the boot process entails making the Solaris partition that you want to boot into the active one, anytime you want to boot into it.

To install OpenSolaris 2008.05, what I had to do was to, prior to loading the OpenSolaris LiveCD into memory, jump out at the GRUB screen and instruct  GRUB to take the ext3 partition and convert it into a Solaris partition. At the same time, I had to instruct GRUB to convert the existing Solaris partition (that has my SXDE OS image loaded on it) into a ext3 partition.  The syntax for that (as is on my PC) looks like this:

grub> hd0, <HIT TAB>

<you get a screenfull of currently defined partitions, then:>

parttype (hd0,1) 0xbf
parttype (hd0,3) 0x83

What this does is it takes the 1st partition on the 0th disk (everyone starts their counting differently, Grub too - so don't grub it the wrong way else you're in for a treat!)

The geometry (hd0) command comes in handy, too.  My map looked like the following, prior to installing OpenSolaris:

hd0,0 - 0x7 (NTFS) 
hd0,1 - 0x83 (ext2fs)
hd0,3 - 0xbf (Solaris/ufs)
hd0,4 - 0xb (FAT)

After the installation of OpenSolaris into this multiboot environment, what I ended up with is a map that essentially looks like this:

hd0,0 - 0x7 NTFS
hd0,1 - 0x83 OpenSolaris
hd0,3 - 0x83 (zfs)
hd0,4 - 0xb (FAT)

The Grub menu.lst file lives in each respective Solaris partitions that, depending on what environment I want to boot into, needs to be made active.  The syntax for making that happen entails modifying each of the menu.lst files and reversing the order of the previously executed step.

title OpenSolaris 2008.05 Release - snv_86
parttype (hd0,1) 0xbf
parttype (hd0,3) 0x83
root (hd0,1)
chainloader +1

Right now the user experience looks something like this. By default the system comes up and gives me a choice whether to boot into OpenSolaris, Windows or Solaris Express Developer Edition.

If I opt to boot into the Solaris Express Developer Edition, the following command is executed behind the scenes and I am presented with the following screen - which is being read from the other Solaris partition that I have on my PC:

title Solaris Express Developer Edition 3 snv79
parttype (hd0,1) 0x83
parttype (hd0,3) 0xbf
root (hd0,3)
chainloader +1

Of course, bootability into Windows looks familiar and is not modified:

title Windows XP
rootnoverify (hd0,0)
chainloader +1

The unlucky partition that I managed to blow away was that very shareable FAT32
partition. Of course, not figuring out exactly what syntax must apply to FAT32 partitions, it took some thinking. Turns out, the help parttype syntax in Grub does not really reveal acceptable types - only the Hex range is the best I could find in the documentation - and that didn't help me.  At the end of it all, though, parttype (hd0,4) 0xb is what dresses up a partition in the FAT32 armor.  Betcha didn't know that. I didn't either... and still am somewhat not fully convinced I understand the differences between 0x6, 0x1b and 0xc - all of which appear as FAT paritions in GRUB.  But I'll leave that for another day as that lawn that I haven't touched for 2 weeks (having been out of the country on biz travel) is just beggin' for some mowin'...


"Multiboot" is a regretful hack that I hope VirtualBox will make a distant memory soon. terminology like: fdisk, partitions, extended partitions, MBRs, "chainloading", grub, lilo, ext3, UFS, emergency boot/partition CDs, damaging typo's in Solaris bootadm commands, stages, hd0x, wrongly indentified partition types (solaris == linux swap), bizarre rules (only one "solaris2" partition), on and on, till your eyeballs pop out of their sockets due to the complexity, 1980's 8086-era vocabulary, and seemingly random but devious restrictions. I can't imagine how many millions of hours have been lost (and the same number of systems have been trashed) in setting up, debugging, and recovering from botched "multiboot" installations. The mailing lists are bloated with sob stories of multiboot installations gone bad, with many poor saps suffering in agony, having lost everything on their disks. All because they trusted the "multiboot" promise! Surely these folks would rather be doing something else than sitting helplessly at that wretched "grub>" command prompt (and while you're stuck there, how about that rich interactive grub help experience; no wait, you actually get an arcane, stripped-down CLI instead, looking something like the commands entered on the Apollo 13 onboard computer in the early 70s) cursing the day they left EE school or marketing to become a computer hack. Unless someone lost a bet with Satan, or is a glutton for torture, I can't imagine why anyone would travel down the multiboot road.

Posted by Pete on May 31, 2008 at 03:21 PM EDT #

Post a Comment:
Comments are closed for this entry.

Isaac Rozenfeld has been a Principal Product Manager for Oracle Solaris; responsibilities have included bettering the portfolio of networking and installation technologies - all with a focus on easing application deployments

You can follow Isaac on Twitter @izfromsun


« February 2015
Tech Reference

No bookmarks in folder