XBMC will be renamed to Kodi for v14. Read here for more details

Archive:HOW-TO:Install Ubuntu and XBMC on Apple TV 1

From Kodi
Revision as of 16:55, 22 February 2010 by Beenje (Talk)

Jump to: navigation, search


1 Introduction

Installing Linux on the AppleTV is already quite well documented and easy thanks to atv-bootloader. If you plan on installing Linux on your AppleTV, you should definitively start there.

With Broadcom Crystal HD now out, the AppleTV can handle 1080p and this makes it a very nice media center alternative. XBMC works fine under the AppleTV OS, but there are a few pro's for having Linux and some might just prefer it.

That said, setting up Linux can be a bit tricky. If you want sound over HDMI, you have to use at least alsa-driver-1.0.18a and NVIDIA 100.14.19 drivers that compile only on Ubuntu 8.04. This guide explains how to achieve that. Linux will be installed on the AppleTV internal disk without removing the AppleTV OS

I would not recommend this guide if you are not familiar with Linux and the CLI.

If you are not a fan of vi, just use nano instead.

2 Prerequisites

  • A USB Hub
  • A USB keyboard
  • A USB flash drive of 256MB or greater (64MB should even be enough)
  • A network with a DHCP server
  • A wired network connection to the AppleTV
  • A Mac or Linux computer on the same network (Windows should probably work as well)

3 Create the bootable USB flash drive

If you have a Mac, just download and run the OS X version of atvusb-creator. Choose "ATV-Bootloader" for the installation and create your bootable flash drive. When done, if you unplug/plug the USB disk, you should see an empty PATCHSTICK partition.

Download Hardy netboot image and copy the needed files to the empty PATCHSTICK partition created by ATV USB creator.

# If you don't have wget installed, just use your browser to download the file
wget http://archive.ubuntu.com/ubuntu/dists/hardy/main/installer-i386/current/images/netboot/netboot.tar.gz
tar xfz netboot.tar.gz
cp ubuntu-installer/i386/linux /Volumes/PATCHSTICK
cp ubuntu-installer/i386/initrd.gz /Volumes/PATCHSTICK
rm -rf netboot.tar.gz ubuntu-installer

If you only have a Linux machine, just follow those instructions: LinuxUSBPenBoot. Make another partition to copy linux and initrd.gz from the netboot image.

4 Linux installation

Connect the USB keyboard and flash drive previously created to your AppleTV using a USB Hub. Reboot the AppleTV and telnet in from your computer (username/password: root). You should see the IP address on your TV screen.

telnet <IP address>

4.1 Backup!

Before touching the disk partition, you should do a backup! We gonna follow the ATVBackup procedure but do a tar instead of a copy. This ensures that permissions won't be changed, no matter the file system on your USB flash drive partition.

mkdir src dst
# Mount the patchstick partition
# If you created the flash drive manually, it might be sdb2
mount /dev/sdb3 dst
# Mount the source
fsck.hfsplus -f /dev/sda2
mount -t hfsplus /dev/sda2 src
# Make a tar of all files on the "Recovery" partition
cd src
tar cf ../dst/backup.tar *
cd ..
# force a disk buffer flush
umount src dst
rmdir src dst

Run "parted" and make a copy of the original partitioning for the internal PATA disk. The disk can then be re-partitioned back to the original later using this file as a guide. Copy this to the first partition of the USB flash drive for safe keeping.

mkdir tmp
# If you created the flash drive manually, it might be sdb1 here
fsck.hfsplus /dev/sdb2
mount /dev/sdb2 tmp
parted -s /dev/sda unit s print > tmp/org_gtp.txt

Check the file. This is how my 40GB disk looked like:

cat tmp/org_gtp.txt
Model: ATA FUJITSU MHW2040A (scsi)
Disk /dev/sda: 78140160s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start     End        Size       File system  Name                  Flags
 1      40s       69671s     69632s     fat32        EFI System Partition  boot
 2      69672s    888871s    819200s    hfs+         Apple_HFS_Untitled_1  atvrecv
 3      888872s   2732071s   1843200s   hfs+         Apple_HFS_Untitled_2
 4      2732072s  78140119s  75408048s  hfs+         Customer
umount tmp

If you need to restore the disk to its original state, just follow the Restore procedure (watch the sdb partition number), but instead of doing:

cp -arp src/* dst/


cd dst
tar xf ../src/backup.tar
cd ..

4.2 Make space for Linux

I didn't exactly follow the procedure described here (btw, it seems Apple doesn't always follow the same naming convention). I just did a resize on my "Customer" partition and it worked fine. I didn't have to perform a "Factory Restore" and didn't loose anything.
But from my Linux experience, when doing a resize on a disk, you should be ready in case it doesn't work. That means, if you have data on that partition you don't want to loose, backup first!
Note that we did NOT backup that partition previously (only the Recovery partition was). This partition is where you might have synced, pictures, movies... If the resize doesn't work, you'll have to remove the partition and do a "Factory Restore". Read this page for more explanations.
You can adjust the partitions sizes to your needs.

# Resize partition 4 and create the main partition for Linux + swap
parted -s /dev/sda resize 4 2732072s   54525951s
parted -s /dev/sda mkpart primary ext3 54525952s  77091549s
parted -s /dev/sda mkpart primary linux-swap 77091550s 78140126s
# Sync the partition tables
partprobe /dev/sda
# Format the new partition
mkfs.ext3  -b 4096 -L Linux /dev/sda5

Here is how the disk should now look like:

parted /dev/sda unit s print
Model: ATA FUJITSU MHW2040A (scsi)
Disk /dev/sda: 78140160s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start      End        Size       File system  Name                  Flags
 1      40s        69671s     69632s     fat32        EFI System Partition  boot
 2      69672s     888871s    819200s    hfs+         Apple_HFS_Untitled_1  atvrecv
 3      888872s    2732071s   1843200s   hfs+         Apple_HFS_Untitled_2
 4      2732072s   54525951s  51793880s  hfs+         Customer
 5      54525952s  77091549s  22565598s  ext3         Linux
 6      77091550s  78140126s  1048577s   linux-swap   primary

4.3 Start Linux installation

Bootstrap into netboot installer

# Mount the patchstick partition with the netboot files
# If you created the flash drive manually, it might be sdb2
mount /dev/sdb3 tmp
kexec --load tmp/linux --initrd=tmp/initrd.gz --command-line="nosplash vesa video=vesafb"
kexec -e

You should now see the Ubuntu install screen on your TV. Proceed with the keyboard you connected earlier.

Follow the steps of the installer.
When asked for partitioning Method, choose manual
Select the ext3 partition you created previously: sdb5 (the USB stick shows up as sda, so the internal disk is sdb)
Use as : Ext3
Mount point: /
sb6 should already be selected as swap
Write the changes to disk

When asked for username, do NOT use “xbmc”, create an admin user

When you come to the “Software selection” window, choose only "OpenSSH server"

When the install is done, reboot.

4.4 Post installation fix

Telnet again to your AppleTV.

telnet <IP address>

Change the USB flash drive, so that it will boot automatically to Linux next time

mkdir tmp
mount /dev/sdb2 tmp
vi tmp/com.apple.Boot.plist

-> change patchstick to auto

umount tmp

Edit your menu.lst

mount /dev/sda5 tmp
vi tmp/boot/grub/menu.lst

Change it to something like this (check your kernel version):

default 0
timeout 3
title Linux
root (hd0,4)
kernel /boot/vmlinuz-2.6.24-27-generic root=/dev/sda5 ro vesa video=vesafb
initrd /boot/initrd.img-2.6.24-27-generic

Bootstrap to this new kernel (or just reboot)

kexec --load tmp/boot/vmlinuz-2.6.24-27-generic --initrd=tmp/boot/initrd.img-2.6.24-27-generic --command-line="root=/dev/sda5 ro vesa video=vesafb"
kexec -e

4.5 Linux setup

You can now ssh to your AppleTV. Use the user you created during installation.

ssh user@appletv.ip

4.5.1 Install alsa-driver 1.0.19

At least 1.0.18a is needed but it failed to compile on my system. 1.0.19 worked fine.

sudo apt-get install linux-sound-base alsa-utils build-essential linux-headers-`uname -r`
wget ftp://ftp.alsa-project.org/pub/driver/alsa-driver-1.0.19.tar.bz2
tar xfj alsa-driver-1.0.19.tar.bz2
cd alsa-driver-1.0.19
# alsa-driver package installs in /lib/modules/'uname -r'/kernel/sound by default
# but ubuntu has the alsa drivers in /lib/modules/'uname -r'/ubuntu/sound/alsa-driver
# so give the ubuntu directory
./configure -with-moddir=/lib/modules/2.6.24-27-generic/ubuntu/sound/alsa-driver
sudo make install

4.5.2 Install Xserver and NVIDIA 100.14.19 drivers

Check http://www.nvidia.com/object/linux_display_ia32_100.14.19.html

sudo apt-get remove --purge nvidia*
sudo apt-get install xserver-xorg-core xserver-xorg-dev xinit xfonts-base x11-xserver-utils xauth
wget http://us.download.nvidia.com/XFree86/Linux-x86/100.14.19/NVIDIA-Linux-x86-100.14.19-pkg1.run
sudo sh NVIDIA-Linux-x86-100.14.19-pkg1.run
sudo nvidia-xconfig  --no-composite --no-logo

Take the opportunity to edit your xorg.conf

sudo vi /etc/X11/xorg.conf

Turn off the use of TurboCache by the nvidia binary driver by adding (see ATV blog):

Option "RegistryDwords" "RMDisableRenderToSysmem=1"

Some people experienced problem with refresh rate due to NVIDIA’s DynamicTwinView feature, so disable it by adding:

Option "DynamicTwinView" "false"

Your nvidia driver section should look like:

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    Option "RegistryDwords" "RMDisableRenderToSysmem=1"
    Option "DynamicTwinView" "false"

4.5.3 Install atvclient

To get the front LED stop flashing and get the Apple Remote to work, just install atvclient See http://wiki.github.com/Evinyatar/atvclient/installation-on-ubuntu-804

sudo apt-get install git-core libusb-dev pkg-config
git clone git://github.com/Evinyatar/atvclient.git
cd atvclient
./configure && make
sudo make install
cd ..
sudo cp atvclient /etc/init.d/atvclient
sudo update-rc.d atvclient defaults
sudo /etc/init.d/atvclient start

4.5.4 Install crystal HD driver and library

git clone git://git.wilsonet.com/crystalhd.git
cd crystalhd/linux_lib/libcrystalhd
sudo make install
cd ../../driver/linux
sudo apt-get install autoconf
sudo make install
sudo modprobe crystalhd

4.6 Time to install XBMC

To get SVN PPA, update your system's software sources:

sudo vi /etc/apt/sources.list


deb http://ppa.launchpad.net/team-xbmc-svn/ppa/ubuntu hardy main
deb-src http://ppa.launchpad.net/team-xbmc-svn/ppa/ubuntu hardy main

Add the key and update your list of software:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 64234534
sudo apt-get update
Install xbmc
sudo apt-get install xbmc

Create xbmc user:

sudo adduser xbmc --gecos XBMC
sudo usermod --group audio,video,fuse,plugdev xbmc

Here is one way to have XBMC started automatically at boot. You could as well choose to just install xbmc-live.

Change tty1 for automatic login:

sudo vi /etc/event.d/tty1

Change this line:

exec /sbin/getty 38400 tty1


exec /bin/login -f xbmc </dev/tty1 > /dev/tty1 2>&1
#exec /sbin/getty 38400 tty1

Update your Xwrapper.config

sudo vi /etc/X11/Xwrapper.config

Replace console by anybody


Login as xbmc and create a .bash_profile

su - xbmc
vi .bash_profile

Set it to:

if [[ "`tty`" == "/dev/tty1" ]]
  clear && startx -- -br & >/dev/null

Create a .xsession:

echo "exec xbmc --standalone" > .xsession
# Logout


sudo reboot

4.7 Set up the HDMI audio output

After reboot, XBMC should start up automatically. You might have some strange colors. Just unmute the HDMI audio output by running alsamixer.

ssh to your appletv

ssh user@appletv.ip

-> unmute IEC958 1 (that's the HDMI audio output)
Save the driver setup:

sudo alsactl store 0

You can check the device by running:

aplay -l

You should see:

card 0: Intel [HDA Intel], device 3: ATI HDMI [ATI HDMI]

Go to XBMC Audio output settings and choose custom for the Audio output device.
Set it to: plughw:0,3

That's it, you should have sound over HDMI!

4.8 What next?

If you don't want to have to plug/unplug the USB stick to boot into Linux/AppleTV OS, check: http://wiki.github.com/Evinyatar/atvclient/appletvlinux-bootmenu

I don't really like to put a password in clear text in a script... I removed the password from the script, and added the script to the sudoers file instead:

sudo visudo


xbmc ALL=NOPASSWD: /usr/local/bin/bootAppleTV.sh

Same can be done on the AppleTV OS side

5 External Links

This guide is based on differents sources. Thanks to the original author (sorry if I forgot some):

Personal tools

Wiki help