Here I write a little bit about my experiences running GRUB2 with a PowerPCMac (actually, an iBook G4), since the current documentation is lacking inmany places (outdated, incorrect, etc.).
This release adds a configuration option for the default boot choice, fixes the Linux/GRUB detection issue, and fixes Snow Leopard 64-bit issues. The current release is 0.14. It is available in various forms. Both disk image distributions include the Installer package and can be burned as a bootable CD as well. If you have just created a dual-boot system with Mac Snow Leopard and Ubuntu Karmic and find that the Grub2 does not boot up your Mac, you can follow the instruction below to add the correct boot entry in Grub2. Boot into Ubuntu Karmic. Open a terminal and type: sudo gedit /etc/grub.d/40custom Add the following. See how well Ubuntu Linux runs on your Mac. You needn't throw out the baby with the bathwater and wipe your old Mac's hard drive clean before trying it out. All you need is a USB drive of a least 2GB in size and an internet connection to get started. Here's how to do it. Get your USB drive ready. Backup your Mac. Launch Disk Utility.
Grub For Arm
Some of what I say is platform agnostic, though, and may be of interest tousers of GRUB in general.
First of all, it is important to understand (at least superficially) howbotting on a Mac works. Download adobe illustrator mac.
One of the first programs that run in your Mac is the OpenFirmware. It workswith more or less the same purpose of a BIOS in a regular x86 system. Thebasic idea is the same: get the computer running with whatever programs youwant it to run. The implementation, though, differs quite a bit.
First of all, OpenFirmware (OF) usually presents itself as a command-lineinterface that is programmable, differently from the common day BIOSes fromx86 boxes. As it is programmable, it is more flexible, but this flexibilitycomes at the price of an increased complexity.
I may write some things more in a future article, if there is anyinterest.
For now, it just suffices to say that to get to the OF prompt in a Mac, youhave to press a combination keys during the time that your Mac gives a chimewhen you turn it on. At that moment, you have to press (simulaneously) Cmd +Option + O + F. (Note: the Cmd key is the key that has an Apple drawn on it,usually on the side of the space bar).
Differently from usual BIOSes of x86 computers, Open Firmware can read thecontents of a partition in your HD (or other devices), as long as it isformatted in the original HFS format (not in HFS+ or one of itsdescendents).
This is the reason why some older versions of Linux create an HFS partitionin your HD, even if you don't intent to run or use anything besides Linux.The yaboot
bootloader consists of, among other things, one binary that isunderstandable by OpenFirmware. That binary is a file called yaboot
, afterthe name of the booloader.
As an aside, you have to indicate to OF what is the file that you want it toload during the boot process, so that it knows what to do. The way toindicate this is to 'bless' the file (and the folder that contains it).Some ways to bless a file are to, for example, use the bless
command inMacOS X or the hattrib -b
command from hfsutils.
Files in an HFS filesystem have two attributes that many other filesystemsdon't: a creator ID (the 'application' that created the file) and the typeID (which determines what kind of file it is).
OpenFirmware, in particular, looks for files with the type tbxi
for thebootstrap process.
The yaboot
binary is loaded by OF into memory and, then, control is passedto the yaboot program, which then reads its configuration file(yaboot.conf
) from the same folder where the binary was in. The fileyaboot.conf
contains instructions for yaboot to do its job. The fileyaboot.conf is very similar in construction to configurations of an olderbootloader for x86 computers, lilo.conf
.
Also, in a way similar to what LILO requires, after you install some newkernel, change some parameter in the configuration file, etc., you have torun a program that will set up everything so that the boot process can knowof your new configuration. With LILO, this command was called lilo
, whilewith yaboot the command is called ybin
(which, essentially, takes care ofputting yaboot.conf
in the bootstrap/HFS partition and blesses theyaboot
binary).
One of the characteristics of yaboot (which is left as an exercise to thereader to determine if it is a drawback or not) is exactly the way thatchanges in the configuration have to be copied to the special HFS partition:the step of running ybin
.
GRUB2 (and its older sibling, GRUB legacy) do away with that: duringboot-time, it can understand the filesystems that you have in your computerand interactively load whatever you want from there, also from acommand-line like OF, before any (regular) operating system has even beenstarted.
But how do you start GRUB2? Well, the way that this is performed iscopying a binary to that special HFS partition. Here things start to behairy, because GRUB2 has a lot of functionality, but it comes at the priceof it consuming a lot of space (especially if you are using encryptedpartitions or some kind of logical volume managements with some journallingfilesystem that allows files to be compressed etc. on top of it). The listgoes on.
Choose the drive letter to be assigned and click Next. Select FAT32 from the File System drop down menu, label the volume however you like, check the box next to Perform a quick format, and click Next. External optical drive for mac and pc. The resulting window tells you that you have successfully completed creating the volume.
Usually, that special HFS partition only has 800KB, which, BTW, is the sizeof an old 3.5' floppy used with older Macs (note: due to some contraints onpartitions and aligments of such partitions on cylinders, it is not uncommonfor disk partitioning software to create partitions slighly larger than800KB, but not much larger than that).
A full-featured binary of GRUB2 to be placed on that HFS partition can havemuch more than those 800KB. But how do you get that binary, in the firstplace? And how do you fit that in the HFS partition?
Creating the GRUB2 binary
To answer the first question, you have to construct it from yourgrub-ieee1275
package (I'm assuming here that you are using Debian orUbuntu, but similar instructions may apply to other distributions). Then, afirst step would be to create such binary with:
The last command of these create an executable named grub.img
that iscallable from OF and which contains every module from grub-ieee1275
. Thisexecutable that I call here grub.img
is called, in GRUB2 parlance,the core image and it it seems to be named core.img
in many systems.
On my system, with those commands, the binary grub.img
is about 1208KB,which is 50% larger than that 800KB partition. And you would like it to bemuch smaller, becase you want to still have your yaboot
bootloader bydefault while you are evaluating your bootloaders (or using it as a backupplan).
As GRUB2 follow a modular design, you can mix and match the features thatyou want. This already hints you to the way we can fit it in the HFSpartition, and it is always the same story: just trim the fat.
Creating the configuration file
You will also have to have GRUB2 configuration's file (or you will have toplay with way more commands than you'd want to). An important distinctionhere is that you usually have 2 or more partitions on your Mac:
- the special bootstrap/HFS partition where OF is going to look at (I'llcall it
/dev/hda2
here); - the partition where your
/
filesystem resides (denoted by/dev/hda3
here); - some partition to hold
/boot
(I don't have one of these, but let's saythat it is/dev/hda7
for our discussion purposes), usually containingyour kernels and initial ramdisks. - other partitions.
With this in mind, you can With Let's say that this last one, in Linuxparlance, is /dev/hda3
(as is the case of this author), and optionally apartition where your Linux kernel resides (people usually use it to storethe /boot
subtree of a Linux filesystem). Let's say that this last one is/dev/hda7
.
Then, you would compose something like the following as a configuration filefor GRUB2 (named grub.cfg
):
There are one two important points here that deserve more comments:
Note that, differently from a regular x86 system, in a Mac system withonly one HD the way that you specify an HD does not have a trailingzero. For instance, in the case above of the variable
root
, we have(hd,apple7)
, while in a 'common PC' we would have the(hd
partreplaced with(hd0
.That's something that you should make your distribution aware of, if theyaren't yet.
As an addendum, I don't know how it works with systems with more than oneHD, as I only have (PowerPC) Macs that are notebooks. If you can share anyexperiences, please do.
One point of caution here: what GRUB2 calls
root
is not necessarily theroot of your filesystem (i.e., the partition that holds/
), but thedevice that everything that is 'not fully qualified' is interpreted asbeing relative to.The 'not fully qualified' above means anything that is not prefixed withGRUB's device notation.As an example,
(hd,apple2)/boot/vmlinux
if fully qualified for GRUB'spurpose, while/boot/vmlinux
is not.
Putting it all together
The next step is to just copy the files grub.img
and grub.cfg
to thespecial HFS partition. You can do that using hmount
, hcopy
, andhumount
or you can use the regular Linux hfs
module to copy to thatpartition.
Then, boot your system, get into the OF prompt and execute:
Here, the 2
above is a reference to my HFS partition. Substitute that withyours, appropriately. You will then see the common (familiar?) GRUB promptand, from there, everything else that you know will (hopefully) work.
As I mentioned above, I use a subset of all modules that come withgrub-ieee1275
to create my grub.img
binary. Here is the list of modulesthat I use and that gives me a reasonably sized bootloader:
Just for the record, my grub.img
file has 624KB, and that can certainly beshrunk.
Centos 7 Grub2 Configuration
Actually, I lied when I told you that I used the lines above to create mygrub.img
file, because I'm lazy and I don't want to type the .img
extension. I also embed my configuration file in the binary that I createwith GRUB2, so that I don't have two files to copy to my HFS partition, butonly one. I do that with:
OK. No more lies here.
The nice aspect of GRUB is that one you install that image, you don't haveto touch that HFS partition anymore: you simply update your regularfilesystem's /boot/grub/grub.cfg
file (which is usually performed when youinstall a new kernel, at least with Debian) and you're ready to go.
The good way to do that is to use a minimal configuration file embedded inyour grub
binary in your HFS partition that will hook into the system's/boot/grub/grub.cfg
to read newer kernels and leave the HFS partition (andyour system's NVRAM) alone.
Here is what I am using right now:
You will, of course, want to modify the file above as you install newerkernels (perhaps even that unsupported operating system from that fruitycompany, who knows?). Don't forget to change the UUID's, and partitionnumbers to fit your needs.
Well, that's it. I hope that it helps somebody out there, as the informationthat I got otherwise was way outdated, incomplete, etc. to keep up withGRUB2 from these days. Now, let's go patch the tools that we have so thatnot everybody who wants to use GRUB2 have to learn about its workings.
Grib Format
Oh, of course, you can now have your kernels in ext4, btrfs, xfsetc. partitions without the fear that your bootloader won't load them.