Linux on Apple TV
WANTED: Somebody to host a pre-compiled 'mach.prelink' built with gimli's current configuration from SVN. Many people would appreciate it, and I'm sure it wouldn't tax your bandwidth too much. A simple README with your kernel args would also be nice.
- Edgar (gimli) Hucek from the mactel-linux project, and AwkwardTV contributor, has gotten the Linux kernel to boot via a custom loader-- which is itself loaded by the AppleTV boot.efi loader. gimli was the first to get Linux running on EFI Intel Macs
View the current SVN with your browser. The Linux side actively requires testing. As you will read below, the results are phenomenal so far.
Sourceforge SVN client address: https://mactel-linux.svn.sourceforge.net/svnroot/mactel-linux/trunk/mach_linux_boot
NOTE: "mach_linux_boot" is the only code you need from mactel!
DO NOT REMOVE THIS NOTICE UNTIL AN ANSWER WITH LINKS HAS BEEN WIKI'D (kad77): We need to establish whether the official NVidia Linux binary supports PureVideo/CUDA for MPEG hardware acceleration; further we need a demonstration application that explicitly shows MPEG hardware acceleration is enabled and usable under Linux. Without hardware MPEG decoding through the GeForce 7300 Go, we are at a severe disadvantage using Linux for video display. Perhaps the video driver could be ported or reverse engineered from the original Apple TV OS (Mac OS X 10.4.7)? See these links (please add):   
The only real video codec acceleration is by using XvMC http://www.mythtv.org/wiki/index.php/XvMC NVidia MPEG2 Hardware Motion Offloading
The NVidia Binary Drivers do not support anything but MPEG2 offloading.
PureVideo for Linux DOES NOT exist. However mpeg4 etc are supported by XvMC just not using the NVidia drivers. Via appears to be the only chipset to support MPEG4 XvMC. http://www.nvnews.net/vbulletin/showthread.php?t=65739
AwkwardTV Linux Project
Many of us would like to see a minimal source distribution, targeted for AppleTV and utilizing the Linux kernel, emerge with boot and kernel configs. Extras might include scripts for USB or disk image builds. Currently we will be working with gimli's Mach-O wrapper approach to bootstrapping, and this will require a MacOS X setup.
Information has been posted to the mactel wiki regarding a Darwin cross-compiler for Linux to compile the Mach-O binary. gimli reports this to work on Ubuntu Fiesty.
- 'alien' package must be installed
- Change to 'mach_linux_boot' and execute the script 'get_cross.sh'
- Move 'darwin-cross' to /opt/
- Execute 'make.sh'
- Cross-compiler download: Darwin/MacOS X Cross-Compiler for Linux (Sourced from the mactel-wiki)
It bears mentioning that we recommend a complete backup of your original AppleTV drive before any experimentation. We have a wiki page dedicated to this subject. Remember, if you pipe the dd through gzip or bzip2, the virgin drive image created should only be ~2.5gb!
Linux Installation Guides
Please add you guides here, they will (hopefully) be maintained by their authors.
beyond's Gentoo Guide
Status of this work: This is a first draft, expect a lot of changes in the coming days.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Canada License
* Apple TV; with Hard Drive removed * A Gentoo Linux computer - any Linux PC should work, but may have some subtle differences * An Mac OSX computer * Laptop IDE->USB Adapter
Please note: many commands will require root access to the computers, please become root as needed.
Step 1: Backup your AppleTV
First connect your AppleTV HD to your IDE->USB adapter, then open a terminal. Issue the following command in the terminal:
dd if=/dev/disk1 of=/path/to/backupfile bs=1024
Please note: /dev/disk1 is the device that is associated with the AppleTV HD. This can vary based on your system configuration.
This process takes a while, so be patient, it will finish eventually!
Under Linux: First connect your AppleTV HD to your IDE->USB adapter, then open a terminal. Issue the following command in the terminal:
dd if=/dev/sdx of=/path/to/backup bs=1024
Please note: /dev/sdx is the device that is associated with the AppleTV HD. This can vary based on your system configuration.
This process takes a while, so be patient, it will finish eventually!
Step 2: Partition and format your AppleTV HD
In a terminal make use of the 'gpt' utility to delete and resize your media partition. There is a project providing an ext3 driver for OSX that you can use to create the filesystem. More details will be available soon.
Under Linux: First we must include the correct options in the kernel, type:
cd /usr/src/linux make menuconfig Select "File Systems" Select "Partition Types" Enable "Advanced partition selection" Enable "Macintosh partition map support" Enable "EFI GUID Partition support" Exit and save configuration changes, then type: make && make modules_install Then copy the new kernel into /boot and reboot. Once your system has rebooted you can repartition your AppleTV HD if you wish, using the GNU parted utility. Once you are ready to continue in a terminal run: mkfs.ext3 /dev/sdx4 (sdx4 is the partition you want to install Gentoo on, ie for me it was sdc4)
Step 3: Install the stage tarball
First we must mount the formatted partition to do so type in a terminal:
mkdir /mnt/appletv mount /dev/sdx4 /mnt/appletv
Open a browser and load: http://www.gentoo.org/main/en/mirrors.xml, and download the current stage3 tarball as well as the latest portage snapshot.
Once you have a stage3 tarball and portage snapshot, ensure they are saved in /mnt/appletv. Open a terminal and type:
cd /mnt/appletv tar -xjvf stage3-x86-2006.1.tar.bz2 tar -xjvf portage-latest.tar.bz2 -C ./usr/
Step 4: Enter the new Environment
Open a terminal and issue the following commands: cp -L /etc/resolv /mnt/appletv/etc/resolv.conf mount -t proc none /mnt/appletv/proc mount -o bind /dev /mnt/appletv/dev chroot /mnt/appletv /bin/bash env-update source /etc/profile emerge --sync --quiet
Step 5: Build a kernel
Download the vanilla 188.8.131.52 kernel from kernel.org. Please ensure it is saved to /mnt/appletv/usr/src/. In our terminal that is in the new environment type:
cd /usr/src tar -xjvf linux-184.108.40.206.tar.bz2 -OR- tar -zxvf linux-220.127.116.11.tar.gz emerge subversion svn co https://mactel-linux.svn.sourceforge.net/svnroot/mactel-linux/trunk/mach_linux_boot/kernel . patch -p0 < 18.104.22.168-appletv.patch mv config-2.6.20-appletv linux-22.214.171.124/.config cd linux-126.96.36.199 make && make modules_install
Step 6: Configure the installation
In Linux, while in the environment issue the following commands, or substitute your own setup below.
passwd [follow the on screen instructions to set the root password...] emerge syslog-ng vixie-cron slocate dhcp rc-update add syslog-ng default rc-update add vixie-cron default dd if=/dev/zero of=/swap bs=1024 count=1000000
Now we must edit several files, first /etc/fstab:
/dev/sda4 / ext3 noatime 0 1 /swap none swap sw 0 0 /dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0 #/dev/fd0 /mnt/floppy auto noauto 0 0 # NOTE: The next line is critical for boot! proc /proc proc defaults 0 0 # glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for # POSIX shared memory (shm_open, shm_unlink). # (tmpfs is a dynamically expandable/shrinkable ramdisk, and will # use almost no memory if not populated with files) shm /dev/shm tmpfs nodev,nosuid,noexec 0 0
Then we must edit /etc/modules.autoload.d/kernel-2.6 to add the following lines:
snd-hda-intel snd-mixer-oss snd-pcm-oss
Edit /etc/conf.d/net to include the following line:
modules=("dhclient") Then run: rc-update add net.eth0 default exit umount /mnt/appletv/proc umount /mnt/appletv/dev cd umount /mnt/appletv
Disconnect the apple tv drive from the computer at this point.
Step 7: The Kernel Wrapper
In OSX: At this point we must build the kernel wrapper provided by Gimli at Mactel-linux. First copy bzImage from /mnt/appletv/usr/src/linux-188.8.131.52/arch/i386/boot/bzImage to your OSX computer.
On the mac, first download and install subversion, one implementation is available at metissian.com. You must also have Xcode installed, which is available for free from Apple.
Open a terminal and type:
svn co https://mactel-linux.svn.sourceforge.net/svnroot/mactel-linux/trunk/mach_linux_boot mach_linux_boot cd mach_linux_boot make
At this point copy the bzImage file from above into the mach_linux_boot folder. Then run this command:
From here we must copy the file mach_kernel to the osboot partition on the apple tv drive. Delete the mach_kernel.preload from this partition while you do this.
In the osboot partition, edit the file com.apple.Boot.plist in folder System/Library/Components, the contents should look like:
<key>Background Color</key> <integer>0</integer> <key>Boot Logo</key> <string>BootLogo.png</string> <key>Kernel</key> <string>mach_kernel</string> <key>Kernel Flags</key> <string>root=/dev/sda4 irqpoll</string>
At this point you can unmount the AppleTV drive, install it into your AppleTV and boot it up! Congratulations you are running Gentoo on your AppleTV!
The original guide comes from beyond's site, used with permission.
arodd's Basic Gentoo Install Guide
Basic Instructions (Assuming you are on OSX and have Xcode Installed and are installing to the internal AppleTV HD)
The guide also assumes you are using Gentoo Linux OS http://www.gentoo.org/doc/en/handbook/handbook-x86.xml
You need to use a LiveCD that supports EFI GPT partition tables.
The Ubuntu InstallCD does. http://www.ubuntu.com/getubuntu/download
The best way to do this step would be to hook up the atv hd to your computer running OSX and create the proper gpt partition for linux and format it as ext3.
More detailed instructions for this will be included later.
The basic rundown would be to make a backup image of the media partition data. Then use gpt to kill the 4th partition on the atv hd. Create a new media partition that doesn't use up the rest of the drive and set as type hfs. Then make a 5th partition as type linux to fill the rest of the drive. Then recover the data to the Media partition
You will need the ext2/3 driver for OSX installed http://sourceforge.net/projects/ext2fsx/ you will then have the tools to format the partition as ext3 and access it from OSX.
newfs_ext2 -j /dev/diskXs5
Boot to the Ubuntu Live CD and then reach the graphical terminal.
sudo su This will probably be hda5/hdb5/sda5/sdb5 or something similar
apt-get install subversion
mount /dev/deviceforatvhd /mnt/gentoo
dd if=/dev/zero of=/mnt/gentoo/swap bs=1024 count=2097152 Creates a 2GB swap file on the root partition
tar -xjvf linux-184.108.40.206.tar.bz2
svn co https://mactel-linux.svn.sourceforge.net/svnroot/mactel-linux/trunk/mach_linux_boot
patch -p0 < mach_linux_boot/kernel/220.127.116.11-apletv.patch
cp mach_linux_boot/kernel/config-2.6.20-appletv linux-18.104.22.168/.config
Start at 5.b on the Gentoo Handbook and continue to the portion before you emerge gentoo-sources 7.b and then continue on below. Make sure you are in the chrooted environment
Add any other features that you may want. Probably not a requirement. Personally I moved some of the things from module to built in. File System support in particular this way you don't need to load a module for hfs/hfs+
make all && make modules_install
Wait for compilation to finish.....and then cleanup
cp arch/i386/boot/bzImage ../mach_linux_boot/
mv mach_linux_boot /
ln -s linux-22.214.171.124 linux
ln -s 126.96.36.199-appletv 188.8.131.52
Seem to have missed a patch somewhere so it's looking for both folders when you load a module
Now the bzImage file is located in /usr/src/linux-184.108.40.206/arch/i386/boot/bzImage as well as in the mach_linux_boot folder which we will copy to OSX later. Continue with the Gentoo Handbook from 8.a. all the way up through 9. Make the fstab look similar to below.
/dev/sda5 / ext3 defaults,errors=remount-ro 0 1
proc /proc proc defaults 0 0
shm /dev/shm tmpfs nodev,nosuid,noexec 0 0
/swapfile swap swap defaults 0 0
Skip all of the bootloader stuff in 10. You can follow 10.d to unmount filesystems etc. Reboot back into OSX
Open Terminal and begin the OSX portion of the mach_kernel loader compilation.
Since the svn-client in fink doesn't support ssl the easiest way is just to cp it from the ext2 partition.
sudo cp -Rv /Volumes/linuxatvpartition/mach_linux_boot /Users/you/Make sure that your bzImage file is located inside this folder...If not copy it here from your linux partition.
Now you have a mach_kernel loader with a linux kernel image enclosed. The ideal method would be to store this on the Media partition alongside boot.efi/com.apple.Boot.plist copied from the OSBoot partition. Modify com.apple.Boot.plist to look similar to below
<key>Background Color</key> <integer>0</integer> <key>Boot Logo</key> <string>BootLogo.png</string> <key>Kernel</key> <string>mach_kernel</string> <key>Kernel Flags</key> <string>root=/dev/sda5 rootdelay=10 irqpoll</string>
Needs Testing/More Documented work
root= may need to be changed to whatever partition number your ext3 partition is at.
The only problem was that I was only able to get it to boot the kernel from the OSBoot partition by removing the atv mach_kernel.prelink from the root directory and customizing the com.apple.Boot.plist in /System/Library/CoreServices/com.apple.Boot.plist. That didn't allow me to dual boot. There is no reason why we shouldn't be able to do the same from the Media partition and swap between atvos/linux and eventually atv/osx/linux, I just haven't got it working yet. In order for it to boot to a specific partition you need to use the bless command either from the ATV via ssh or via an Intel mac. Example...
bless --device=/dev/disk0s4 --setBoot --nextonly
Much of the AppleTV's hardware is supported natively under the Linux kernel. In this section, we will be expanding on the Linux driver details.
Intel CPU Core
- Speedstep functionality - WORKING
GeForce 7300 Go (NV40) Note: framebuffer fixes in SVN as of April 6, 2007 - please recompile
- Official NVidia binary driver works without modification. Full 3D and framebuffer acceleration.
- OSS NVidia driver works without modification (also provides acceleration)
(==) NV(0): Write-combining range (0x10000000,0x4000000) (II) NV(0): Using XFree86 Acceleration Architecture (XAA) Screen to screen bit blits Solid filled rectangles 8x8 mono pattern filled rectangles Indirect CPU to Screen color expansion Solid Lines Scanline Image Writes Offscreen Pixmaps Setting up tile and stipple cache: 32 128x128 slots 32 256x256 slots 16 512x512 slots
- HDMI - WORKING (DVI tested)
- Component - not tested
Intel HD Audio
- HDA-Intel driver recognized by default
- Analogue RCA - not tested
- Optical SPDIF - WORKING
- mactel-linux driver recognizes it - untested otherwise
Broadcom BCM94321MC wireless
- USB booting works when you disable ehci-hcd in kernel
Our components wiki has further information about the specific chips involved.
Barebones Distro Notes
Our preferred base distrubutions:
- Lunar Linux 1.61 A full source based distro, customizable and friendly.
- ttylinux 6.0 A micro distro (8MB w/kernel)
There are a few Linux distributions specialized for Media Center usage:
Some useful components:
- elilo bootloader 3.6 (stable)
- The Linux kernel 220.127.116.11 (recent)
- NVidia binary driver (latest)
- BusyBox 1.4.2 (stable)
- MatchBox Window Manager
- XOrg X11R7.2
We would prefer a lightweight X alternative or optimized/minimal X11 build. Note: KDrive is framebuffer only.
- ATV/Gentoo Wallpaper BigBaconAndEggs
April 5, 2007 dmseg output: (from gimli @ mactel)