Page 1 of 1
Testing hobby OS with mac machine
Posted: Tue Apr 10, 2012 12:33 pm
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
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.
Re: Testing hobby OS with mac machine
Posted: Wed Apr 11, 2012 9:16 am
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!).
Re: Testing hobby OS with mac machine
Posted: Wed Apr 11, 2012 9:48 am
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
Anyway, my kernel fault at LTR, I may need to re-check my task content later, but it should be minor issue.
Re: Testing hobby OS with mac machine
Posted: Wed Apr 11, 2012 9:57 am
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
Re: Testing hobby OS with mac machine
Posted: Thu Apr 12, 2012 2:07 am
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
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?
Re: Testing hobby OS with mac machine
Posted: Thu Apr 12, 2012 2:42 am
by ACcurrent
Well if you are booting from a disk, the standard floppy image works too.
Re: Testing hobby OS with mac machine
Posted: Thu Apr 12, 2012 3:39 am
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.
Re: Testing hobby OS with mac machine
Posted: Fri Apr 13, 2012 10:35 am
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.