Testing hobby OS with mac machine

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Testing hobby OS with mac machine

Post by bluemoon »

Brendan wrote:For me, except for curiosity, the biggest reason to buy an Apple machine is to test my OS on their "not quite compliant" UEFI firmware.
Out of curiosity I just attempted to drop my OS image into USB stick and see if it boot on my ancient macbook1,1; and sure it don't :oops:

I share the founding here:

1. According to apple site, intel mac support boot from USB storage, only with GUID partition
2. It seems that *some* apple EFI only boot from USB with HFS partition and refuse to boot with FAT.
3. I'm not sure if installing rEFIt works for it, may try it later.
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Testing hobby OS with mac machine

Post by turdus »

Mac EFI does not use EFI boot mechanism by default. Instead it looks for a "blessed" file on a HFS+ partition. MacOSX uses EFI System partition only if specific nvram variable set, and deletes the file after execution (typically used by firmware updates).

By pressing C during post logo, you can force ISO9660 boot (only tested no-emulation images), and by pressing Option it will list bootable devices (you can boot EFI GRUB on usb key with this for example). Finally, if no blessed file found, and no firmware update on EFI partition, it will use normal MBR boot. There're several retries and considerable timeout for each, so it may took for a while, but finally it will do BIOS boot (well, subset of).

I managed to use legacy GRUB with hybrid MBR on my MacBook (without BootCamp or rEFIt or the forementioned EFI GRUB). The only trick is you have to build an MBR partitioning table which maps exactly the same partitions as the GPT (yes, GPT is a must). Also, make sure GPT entry (0xEE) is the first partition. Downside of this that limits bootable storage size to 32 bit LBA, and you have to wait minutes before the OS began to boot, so I would not recommend for daily use.

Conclusion:
1. fast and lazy method: build a CD, and press C during boot.
2. the right way: use EFI GRUB or write your own EFI loader, and press Option during boot.
3. fallback: with synchronized MBR and GPT partitions, you can use hybrid BIOS boot (terribly slow!).
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Testing hobby OS with mac machine

Post by bluemoon »

turdus, Option key will works for CD or harddisk, but for usb stick some mac(but not all, no one know why) refuse to boot non GPT, non-HFS partition.

Anyway, I installed rEFIt and it successfully booted my OS, but my 1MiB initrd took minutes to load from usb stick, since my boot loader do no animation I actually thought it hanged and spent half an hour to put checkpoints and debug, and figure out I just need to wait :lol:

Anyway, my kernel fault at LTR, I may need to re-check my task content later, but it should be minor issue.
Last edited by bluemoon on Wed Apr 11, 2012 10:00 am, edited 1 time in total.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Testing hobby OS with mac machine

Post by bluemoon »

And if anyone interested, this is the step to write usb stick on mac:

1. diskutil list

Code: Select all

/dev/disk5
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *2.1 GB     disk5
   1:                 DOS_FAT_16 BLUEMOON                10.5 MB    disk5s1
For me, the usb is disk5

2. diskutil unmountDisk /dev/diskX

Code: Select all

Unmount of all volumes on disk5 was successful
3. dd if=[disk image] of=/dev/diskX
Be careful not to wipe your local disk!

4. The usb will be auto mounted, eject it and you're done.

Once the boot record and file systems are there, you may update files as usual using cp or Finder
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Testing hobby OS with mac machine

Post by turdus »

bluemoon wrote:turdus, Option key will works for CD or harddisk, but for usb stick some mac(but not all, no one know why) refuse to boot non GPT, non-HFS partition.
My machine has no problems with booting from non-HPS partition, but I can confirm GPT is a must.
Anyway, I installed rEFIt and it successfully booted my OS, but my 1MiB initrd took minutes to load from usb stick, since my boot loader do no animation I actually thought it hanged and spent half an hour to put checkpoints and debug, and figure out I just need to wait :lol:
Yes, rEFIt is the most common way. As I say booting other than MacOSX (any kernel that's not on a HPS and blessed) is terribly slow, you have to wait a lot! :-(
Anyway, good that you managed to boot your OS on a Mac! Well done!
Anyway, my kernel fault at LTR, I may need to re-check my task content later, but it should be minor issue.
Those minor issues tend to turn into several day long nightmares to my findings :-)
Pure curiousity: what kind of loader are you booting with rEFIt? GRUB, EFI GRUB or your own loader?
ACcurrent
Member
Member
Posts: 125
Joined: Thu Aug 11, 2011 12:04 am
Location: Watching You

Re: Testing hobby OS with mac machine

Post by ACcurrent »

Well if you are booting from a disk, the standard floppy image works too.
Get back to work!
Github
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Testing hobby OS with mac machine

Post by bluemoon »

turdus wrote: Yes, rEFIt is the most common way. As I say booting other than MacOSX (any kernel that's not on a HPS and blessed) is terribly slow, you have to wait a lot! :-(
Anyway, good that you managed to boot your OS on a Mac! Well done!
Indeed it's not too slow, comparing to the load time of my 1Mib initrd using BIOS read function, it took about one minute.
And thanks, I feel good to have my OS runs on a real machine :p
turdus wrote:Pure curiousity: what kind of loader are you booting with rEFIt? GRUB, EFI GRUB or your own loader?
I wrote a standard MBR to install only for blank disk, and I wrote a VBR for FAT16 partition which do nothing but loads boot.bin
and boot.bin is the actual loader that do the pre-kernel stuff.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Testing hobby OS with mac machine

Post by bluemoon »

I finally fixed the process switching bug, it is that when I jump to ring3 I forget to set DS/ES/FS/GS to DPL=3, while having CS/SS to 3.

I'm disappointed that qemu did not cause #GP on this.
Post Reply