📜 ⬆️ ⬇️

FreeBSD on Mac

Published on behalf of and at the request of fellow mrTuborg

A year ago, I picked up a server on Mac mini running Leopard (Mac OS X 10.5), like all decent people, having discovered FreeBSD rudiments / stumps, downloaded and installed fink ports (finkproject.org). Played for a year ... put the WiFi adapter in Infrastructure mode ... now he and the Internet began to send to the laptop ... Shakes torrents in 24/7 mode, forwards the VNC stream from LAN to external Internet (for access from the same laptop when staying far from his home) ... provides, again, for my beloved, a 500G SFTP floppy diskette, holds a transport for a jabber ...

And it became boring ...
But what if you take and put a real FreeBSD on it? The boy said - the boy did? .. But no ... this is where the fun begins.
')
I burned the FreeBSD 7.0 PowerPC image. Mack started from the disk normally. We start the installation ... oops ... and where is fdisk ?? Nope fdisk'a. There is a Label Editor. But as he begins to find out, he can do nothing with the partition table ... And it started. As a result of 2 weeks of digging, I got a small ToDo “How to put FreeBSD on a Mac” ... which I am going to bring to your attention.

So, the problems I encountered:

1) FreeBSD Installation DVD does not have fdisk. Only LabelEditor which in principle cannot help with sections.
And nowhere will you find a port of fdisk on a Mac (at least a working version). The problem lies in the "special" gland and special
Open-firmware (about this below) by Apple.

2) “Special” Open-Firmware
All progressive humanity has already abandoned the BIOS system, replacing them gradually (as I understand it while in theory, and on Macs already in practice) with Open Firmware. Hardware preloader with self-test functions. In poppies, although it is stated that this is Open Firmware, but based on the set of commands, this is still your Open Firmware. And this Open Firmware understands loading only from Makovsky sections HFS +. Actually all further dances with a tambourine and occur around this Open Firmware.
What it is written here - en.wikipedia.org/wiki/Open_Firmware . The new-fashioned technology which replaced the morally deceased BIOS. A set of commands for management can be read here - www.firmworks.com/QuickRef.html . But the peculiarity of Apple's OpenFirmware is that it practically does not intersect with the described things. Here, a slightly modified set of commands (most of the commands from the specified Reference do not work) and the behavior of these commands is slightly unpredictable. Very often the same teams stop working or work like that differently. Only one way out - reboot.
So, the entrance to Mac's OpenFirmware is Alt + Cmd + O + F. After a short workout, this combination is easily pressed with one right (the left will not work - I tried =)).
The most useful of the commands found:

mac-boot - continue loading
shut-down - turn poppy off
reset-all - reboot the system
eject cd - spit out a disk
boot <bootloader> <kernel> - boot the system

devalias — displays a list of all assigned symbolic abbreviations for devices.
(write alias for hd and cd)

Displaying the entire device tree:
1) dev / - mount the device tree to the root
2) ls

printenv - output environment variables.
(the most interesting variable for us is the boot-device)
setenv <variable> <value> - Assign an environment variable

To reset all settings to factory defaults — you must hold the power button in the off state until you see a characteristic sound and a home reaction a la “are you okay? 0_o »In general, the signal is recognizable.

It seems everything is crystal clear. But! OpenFirmware can not boot from anything other than HFS +, and at the same time ...

3) FreeBSD does not see Makovsky HFS + partitions.
The principle of this and is not required. All that is required is to create using the Mac OS tools to prepare the HFS + partition and not to touch it already from
FreeBSD, so as not to spoil.

4) Mac OS at the first opportunity "rushes to improve" partitions on the hard disk.
The problem is the reverse of that described in Section 3. When we have already installed FreeBSD, in no case will you allow Mac OS X to boot (from the installation disk). The entire BSD installation procedure will have to start over.

So. This was the theoretical part. Now let's get down to practice - to prepare the patient.

Instruments:
1) FreeBSD installation disk.
2) Mac OS X installation disk (Tiger or Leopard).
3) USB flash drive.

0. Definition of equipment.

Further, we will always indicate the symbolic names of devices, but just in case, if they do not work, we need to elicit the full name of the devices we need at this stage.
Enter Open Firmware (by clamping the Cmd + Alt + O + F keys) ...

write the following commands:

0> dev /
0> ls

pagination of the device tree built at the initial stage of downloading Open Firmware will begin. This requires attentiveness.
The name requires the entire branch ... which is not actually indicated there ... but is only indicated by indents.

My ATA controller (where the hard drive and cd-rom are connected to) looks like this:

/ pci @ f4000000 / ata-6 @ d / disk

(through slash separated tree branches).

How to find out if a tree branch was correctly identified?

Boot further - into boot2 / EFI (provided that the Free BSD installation disk is inserted). There we have a more advanced (but the same buggy) set of commands from FreeBSD where you can check all our guesses:

How to boot boot2 / EFI. While in OpenFirmware, enter the command (the second parameter is omitted - the kernel will not boot)
boot cd:, \ boot \ loader

So we are in boot2 / EFI.

all the guesses are driving into the “currdev” environment variable:
After the name of the ata-disk controller (pci @ f4000000 / ata-6 @ d / disk), you must specify the disk number and partition number
set currdev = / pci @ f4000000 / ata-6 @ d / disk @ 1: 0

in my case it is cdrom. since there is only one section, then the section number can be omitted, leaving:
set currdev = / pci @ f4000000 / ata-6 @ d / disk @ 1

further check our hunch with the ls command.
If you received a listing of files and disk directories - the guess was correct.

The hard disk in my case will appear as: / pci @ f4000000 / ata-6 @ d / disk @ 0

If we make a mistake, then finding the required sections is solved by a simple search =).

1. Bootloader preparation (on a nearby computer )

We take a flash drive and copy the loader and boot.tbxi onto it (to any folder, a flash drive - as a tool for carrying, no more)
What files ... and where to get them? loader - located on the FreeBSD installation disk (\ boot \ loader), boot.tbxi in the same place, but you need to fix it or recreate it if you don’t find it.
This is the Forth boot script for Open Firmware, looks like this:

<boot-script>
"screen" output
boot hd: ???, \ boot \ loader hd: ???
</ boot-script>

We are interested in the boot command. Let's look at its syntax:
Parameter 1 is the location of the boot loader (in this case, the boot2 / EFI boot loader from FreeBSD). In this example, there is a symbolic substitution, hd - hard disk (cd - compact disk), a colon number after the colon (about the partition number just below) and through the clogged path on this partition to the bootloader file. HFS + file system.

The 2nd parameter is the location of the kernel of the bootable system. It's easier here - just the partition number. The parameter is passed to the input of the file loader, so there are no requirements for the file system format.

How to find out the necessary section numbers, we will find out accordingly at the moment when these sections are created. Therefore, editing the script on a nearby computer does not end there ...

2. Preparation of the hard disk.

The MAC OS X installation disc is needed once (see problem number 4), so we’ll start with it.

After downloading the MAC OS X installation disc, the following tools are available to us: Disk Utilities and Terminal

2.1 Split the disk using Disk Utilities.

Why not make one section and not divide it into slices using the Label Editor? Will not work. The Label Editor can only use the sections created for it, but not interfere with the partition table in any way - it will not work. That's why it is better to make your own section for each slice ...
Before partitioning a disk, you need to select the type of the partition table. GUID, Apple Partition Map or MBR. Choose for PowerPC mac - APM, for Intel mac - GUID.

I did the following sections:
as root - 4 Gb
under swap - 2 Gb
under var - 2 Gb
under usr - 8 Gb
under the home - all that remains, namely 22 Gb.

in order to make it easier to identify them in the terminal in the terminal, we will give these sections labels like root, swap ..., etc.

In general, every forum of bourgeois is not advised to play with Disk Utilities for a long time as it is suspected of being buggy. I do not deny this fact, it was like that, but I blamed it on my crooked hands.
A few words about the compatibility of Mac OS and BSD file systems. In Disk Utilities there are 4 types of file systems to choose from - they are all called long and abstrusely Extended File System with or without journaling and with or without support for capital and small letters in file names. In fact, this is nothing more than Journaled or Non-Journaled Ext3 with options. So there are no problems with reading both in theory and in the practice of these sections from under BSD (it will convert them to UFS). But there is a catch all the same. It is necessary to boot the loader with HFS +, and the kernel is already from the partition understood in BSD.
For further successful booting of the installed BSD, it is necessary to separate the loader and the kernel itself. To do this, on the disk to the section already described above create a partition for the bootloader. I indicated the size as 0.2 GB, Leopard immediately adjusted it to 1 GB, but after the partitioning process the partition turned out to be 0.86 GB in size. Well, let's not argue with him =). Next, when installing BSD, it will make its partitions unreadable for Macs, so the Leopard installation disk is used only once and only before installing BSD on the hard disk. Otherwise, the next time you boot the Leopard installation disk, Mac OS, all the prepared sections will “improve” to the point of unsuitability, so the installation process will have to start over.

So we have the following partition table:
bootloader (1G)
root (4G)
swap (2G)
var (2G)
usr (8G)
home (22G)

Having finished the preparation of partitions, close Disk Utilities and start terminal (All from the same Leopard or Tiger installation disk).
being in the terminal, you need to place in the bootloader 2 section of the file c previously prepared flash loader and boot.tbxi. No placement requirements. I, for example, created the boot directory there, and copied everything there ... and yes we need to finish the preparation of the boot script.

2.2 Section number identification

Method 1 : While in the terminal of the leopard installation disk, output the list of mounted partitions (everything was already mounted before us)

I have an example of running the mount command:
/ dev / disk0s3 on / bootloader
/ dev / disk0s5 on / root
……

the digit after s is the digits we need (see above an example of my boot script)

Method 2 : Being in the LabelEditor of the FreeBSD installation disk.
An example of my case:

ad0s3
ad0s5

...

Here you have to navigate in order of the size and size of sections to find out who is who, since the specified labels are not visible. A bit uncomfortable.

Now we finish the boot script:
<boot-script>
"screen" output
boot hd: 3, \ boot \ loader hd: 5
</ boot-script>

2.3 Preparing the bootloader

Being in the Terminal we copy from the flash drive to the poppy in the bootloader section the files loader and boot.tbxi

3. Install FreeBSD.

So. What we have at this point is a partitioned (so far only into partitions) disk, the loader and boot.tbxi files copied to the bootloader partition.
Restart the Mac and boot from the FreeBSD installation disk. We carry out the installation. Restart. We get a flashing daddy ;-)

4. Booting an installed FreeBSD.

So far, so good. We go again in OpenFirmware. Test installation by manual download:

0> eject cd - pull out the boot disk of the FreeBSD installer
ok
0> boot hd: 3, \ boot \ loader hd: 5 - load the loader we prepared on the 3rd partition and transfer the kernel from the 5th partition to it.
ok
...

Successfully? If yes, go to paragraph 4.2. No - read on.

4.1 Direct device names.

If the download did not go, then symbolic links are not correctly defined (devalias)
So we will use the direct device names. Remember item 0. Boot again in EFI
Check if we have a boot loader and a kernel:
set currdev = / pci @ f4000000 / ata-6 @ d / disk @ 0: 3
ls - listing files from bootloader section. Must see loader and boot.tbxi
...

set currdev = / pci @ f4000000 / ata-6 @ d / disk @ 0: 5
ls - listing files from the root section.
...

If unsuccessful, then change the digits a and b - disk @ a: b by iterating until we find it.
Suppose you find the numbers you need, then we test the download (having previously been overloaded to OpenFirmware)
0> boot / pci @ f4000000 / ata-6 @ d / disk @ 0: 3, \ boot \ loader / pci @ f4000000 / ata-6 @ d / disk @ 0: 5

accordingly, you need to fix the boot.tbxi boot script for the parameters found

4.2 Installed FreeBSD booted ...

You can work ... Voila!

At this point, the information at about all the bourgeois forums ends ... everything is ok for them. They reached Nirvana ...
But as our attentive proletarian reader will notice - do you really have to load it all with pens now? In many forums in this place, it is recommended to prepare a boot disk (as an installation disk) with the correct .tbxi script that will load the kernel not from the disk, but from the hard drive.

5. But this is not an option!

Not one sleepless week passed, and I came across in a different place and on a completely different occasion on the setenv team. Here it is, the final chord, so to speak ...

setenv boot-device hd: 3, \ boot \ boot.tbxi

On my poppy worked. Will it work for you - no guarantees ... since all this is undocumented features of Makovsky Open Firmware.
In any case, how to get everything back? Reset nvram settings - hold the power button for 20 seconds while the Mac is turned off.

Afterword.
FreeBSD booted on my Mac. Coolers are now working constantly ... WiFi module is not visible ... There is something to continue. Unless of course this is all someone needs.

Source: https://habr.com/ru/post/47414/


All Articles