Darwin

From AwkwardTV
Revision as of 20:47, 14 April 2007 by Probono (talk | contribs) (/etc/hostconfig)
Jump to: navigation, search

This page is about "Darwinx86" in general. Nothing specific to Apple TV. Everything 100% APSL compliant.

About Darwin

As Apple advertises, Mac OS X is built on a "secure, reliable, Open Source foundation", namely Darwin. See http://www.apple.com/opensource/ for more information.

We want to use this system. There are a couple of reasons why Darwin is great:

  • It can read and write HFS+ Journaled natively
  • Mac and Apple TV users are familiar with the workings of the system
  • There is lots of Open Source applications available, including a graphical X desktop
  • Can be used e.g., for embedded applications
  • Can be legally changed and re-distributed in accordance with APSL

Darwin-related community projects

Initially, there was large interest in Darwin, but as time progressed, the community lost interest (due to reasons that shall not be evaluated here). However, with the switch of Mac OS to Intel, there seems to be a lot of interest of the community again, but mainly focused on Mac OS X rather than Darwin itself.

Mac OS Forge

Mac OS Forge, hosted by Apple, is where Kernel (xnu), Launchd, and other parts of Darwin live.

OpenDarwin

Unfortunately, this project closed due to a perceived "lack of interest" just when it became "interesting" due to the move to Intel.

Project was launched by bbraun, a former Apple employee who today insists that this project is dead.

GNU/Darwin

Tries to build a complete desktop-oriented, general-purpose distribution on Darwin.

Fink

A collection of Open Source software for Darwin. It is claimed that they also host pre-compiled, ready-made binaries for Intel, however the URLs of those are hard to impossible to find on the site.

Project was launched by Christoph Pfisterer (later rEFIt), now working for Google.

DarwinPorts

A collection of "ports files" which allow to build binaries from source. Although the primary OpenDarwin site will be closing down, this ports repository, darwinports.com, is separately hosted. James Berry recently wrote that the Ports project will live on.

Is this superceded by MacPorts?

MacPorts

Describes itself as "the project previously known as DarwinPorts". Hosted by Apple, this seems to be actively developed (Google Summer of Code 2007).

Purpose of this page

The first goal will be to install Darwin on a USB drive and boot a generic PC from there. This serves as a starting point for further projects based on Darwin.

Please note that this page is about 100% legitimate uses of the Darwin Open Source system only.

Booting darwinx86-801.iso on a PC

Booting Darwin CD from IDE (works)

This is on a i915 chipset, DVD drive attached to IDE:

IOATAController device blocking bus
AppleIntelPIIXPATA: ICH6 ATA/100 (CMD 0x1f0, CTR 0x3f4, IRQ 14 BM 0xffa0) 
Still waiting for root device
Still waiting for root device
Still waiting for root device

Changing the DVD drive jumper from cable select to Master solved this issue.

It boots up and asks where to install Darwin.

So in principle, darwinx86-801.iso contains a system that is capable of running on a generic PC.

Booting Darwin CD from USB (works)

The same darwinx86-801.iso also boots fine when the DVD drive is connected to the USB bus using a IDE2USB adapter.

So in fact darwinx86-801.iso contains a system that is capable of running on a generic PC from USB.

Can we turn this into a USB "bootstick"?

Booting Darwin CD into single user mode (works)

By default, the Darwin CD boots into a installer. However by using "-s" at the boot prompt, we can boot into "single user mode", which allows us to issue commands on the command line.

Trying to install Darwin to attached USB drive (fails)

Booting Darwin CD as described above, with plugged-in USB drive gives:

USBF: AppleUSBEHCI[0xc181b800]::Found a transaction past the completion deadline on bus 253, timing out!
USBF: AppleUSBEHCI[0xc181b800]::Found a transaction past the completion deadline on bus 253, timing out!
USBF: AppleUSBEHCI[0xc181b800]::Found a transaction which hasn't moved in 5 seconds on bus 253, timing out!

Apparently this is a Darwin bug. Please note here if otherwise.

Installing Darwin to attached IDE drive (works)

As above, but this time the disk is on the IDE bus.

.root.tar.bz2 files

During installation, a lot of .root.tar.bz2 files are uncompressed.

So the installer doesn't actually clone the system that is used to boot the CD, but uses the compressed files. Are they different?

There is no apparent way to determine what gets installed. So We are getting a lot of stuff that is not necessary for a bare bones installation, such as gcc.

What is the minimum configuration of .root.tar.bz2 files necessary?

Updating mkext cache

Wouldn't this be done at next boot anyway?

Personalization

  • Installer asks for a root password
  • Installer asks for a computer name (Bonjour hostname)

Booting into installed Darwin from IDE (works)

Fixing boot issue

If booted without any arguments, the boot fails. However, by entering

rd=disk0s1

Darwin fully boots into a login prompt.

The following procedure fixes the boot issue permanently:

mcedit /Library/Preferences/SystemConfiguration/com.apple.Boot.plist
# edit Boot.plist, remove "Boot Device" entry
reboot

USB issue (fixed)

The installed Darwin seems to fail recognizing any USB devices

kextstat | grep USB
com.apple.iokit.IOUSBFamily (2.2.0) 
com.apple.driver.AppleUSBUHCI (2.2.0) 
com.apple.driver.AppleUSBEHCI (2.2.0)
com.apple.driver.AppleUSBHub (2.2.0) 

Trying to load IOUSBFamily.kext says "check ownership and permissions".

Apparently this is a Darwin bug of the installer. Please note here if otherwise.

So permissions need to be repaired. However, since there is no /Libaray/Receipts and no diskutil in Darwin, we need to do this manually

chmod -R 755 /System/Library/Extensions
chown -R 0:0 /System/Library/Extensions
touch /System/Library/Extensions
reboot

This fixes the USB issue. An USB drive is now correctly recognized as /dev/disk1s, it is not automatically mounted however.

Mounting HFS+ (Journaled) USB drive (fails)

mount /dev/disk1s1
# unknown special file or file system
mkdir /Volumes/Test
mount /dev/disk1s1 /Volumes/Test
# Incorrect super block

Further investigation required. Please note any solution here.

Booting into installed Darwin from USB (works)

Good news of the year!

The very same hard disk that boots from IDE also boots when connected with a IDE2USB cable. Yay!

Note that in addition to the USB kexts above, this time there are additional ones loaded:

kextstat | grep USB
AppleUSBComposite (2.2.0)
IOUSBStorageClass (1.4.0)
IOUSBUserClient (2.2.0)

Mounting HFS+ (Journaled) USB drive (fails)

However, when adding another USB drive, that is not recognized (i.e., no /dev/disk1 showing up).

Further investigation required. Please note any solution here.

Enabling sshd

killall sshd
ssh-keygen -t rsa -f /etc/ssh_host_rsa_key # do NOT use passphrase
ssh-keygen -t rsa1 -f /etc/ssh_host_key # do NOT use passphrase
sshd

Edit /System/Library/LaunchDaemons/ssh.plist to launch sshd on each start:

       <key>Disabled</key>
       <false/>

Enabling apache2

apache2 is installed in /opt by default. You can launch it with

/opt/apache2/bin/apachectl start

It is configured to listen on port 8080 by default. So you can access the machine via http://darwin.local:8080/ for example (if your computer name is set to "Dawin").

/etc/hostconfig

Various services are supposed to be automatically started by editing /etc/hostconfig, including

  • AFP
  • Webserver
  • SMB Server
  • Spotlight - is this a leftover from Mac OS X and disfunctional on Darwin?

Installing "Darwin nano" on bootable USB drive

This is not working yet. Any help is greatly appreciated. From the experiments above it is apparent that this should work.

Plan

# Get Darwin 8.0.1 ISO for i386 from Apple
# Boot it into single user mode (see above). From booted Darwin, do:
# Prepare USB stick by formatting it as HFS+ (Journaled) and enabling permissions
# Copy /usr /bin /sbin /System /Library /private /cores /mach_kernel from ISO to USB drive
# (maybe need to use the .root.tar.bz2 files instead, see above)
# Bless USB stick and set partition active
# Change Boot.plist 
# Fix permissions and touch Extensions
# Boot USB stick

This easily fits on a 512 MB USB stick, and probably can be slimmed down further (e.g. for embedded applications).

This does boot, but as soon as the kernel is supposed to appear, it reboots the PC (even before printing a kernel panic).

Minimal hardware requirements for darwinx86-801.iso

Found out by experimentation. Please add.

Processor

SSE2 and SSE3 are NOT required since Darwin 8.0.1 ISO boots fine on a Celeron 400 MHz machine from 1999 with a PIIX4.

(However, this system requires "platform=X86PC" because it otherwise stalls with an ACPI error message.)

Hard Disk

The Darwin installer puts 1.44 GB on disk. There is no apparent way to select less software in the installer. This is far more than what is needed for a minimal Darwin system.

Minimal number of files to boot the Darwin kernel

What are the minimum required files to boot the Darwin kernel and to bring up a minimal shell?

# Please collect here
xnu-792.root.tar.bz2
# ...


Versions

  • Darwin 8.0.1 = Mac OS X 10.4.x (what this page focuses on)
  • Darwin 7.0.1 = Mac OS X 10.3.x
  • Darwin 6.0.2 = Mac OS X 10.2.x
  • Darwin 1.4.1 = Mac OS X 10.1.x
  • Darwin 1.3.1 = Mac OS X 10.0.x
  • Darwin 1.2.1 = Mac OS X Public Beta
  • Darwin 1.0.2 = Developer Preview 4