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

See also: HOW-TO:Install XBMC on Apple TV 1 (Linux)

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. Any more dissent release seems affected by a regression bug #385076 and it need to be resolved first.

This guide explains how to achieve it using Ubuntu 8.04 for now. 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.

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)

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 only have a Linux machine, just follow those instructions: LinuxUSBPenBoot. Make another partition to copy linux and initrd.gz from the netboot image.

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.

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.

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.

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

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: do:

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 lose 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 lose, 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.

Here is how the disk should now look like:

Start Linux installation
Bootstrap into netboot installer

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

If you are asked to select a specific kernel, just take the default choice (generic kernel)

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

When the install is done, reboot.

Post installation fix
Telnet again to your AppleTV.

Change the USB flash drive, so that it will boot automatically to Linux next time -> change patchstick to auto

Edit your menu.lst Change it to something like this (check your kernel version):

Bootstrap to this new kernel (or just reboot)

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

Set the MAX_CSTATE
You may experience dropped ethernet packets if you do not adjust the maximum cstate for the AppleTV's processor. Cstates are different levels of power that the processor will operate at. The intention is to conserve energy when the system is not in use, but in Linux's case this can cause a few issues. I have seen better and more reliable network activities after performing the following steps.

Add the following line to your /etc/modprobe.d/options file: Then update the initrd image using the following command: The initrd image is now updated to include the option. Then reboot. Verify if it works: You should see:

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.

Install Xserver and NVIDIA 100.14.19 drivers
Check http://www.nvidia.com/object/linux_display_ia32_100.14.19.html Take the opportunity to edit your xorg.conf Turn off the use of TurboCache by the nvidia binary driver by adding (see ATV blog):

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

Your nvidia driver section should look like:

Install atvclient
To get the front LED stop flashing and get the Apple Remote to work, just install atvclient See https://github.com/Evinyatar/atvclient/wiki/Installation-on-Ubuntu-8.04

Install crystal HD driver and library
svn trunk and git trees might be unstable. So use the last tag from http://code.google.com/p/crystalhd-for-osx/ (it contains both osx and linux source code).

Time to install XBMC
To get Official PPA and SVN PPA, update your system's software sources:

Add:

Add the keys and update your list of software:

Create xbmc user:

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: Change this line: To:

Update your Xwrapper.config Replace console by anybody

Login as xbmc and create a .bash_profile Set it to: Create a .xsession:

Reboot

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 -> unmute IEC958 1 (that's the HDMI audio output)

Save the driver setup:

You can check the device by running: You should see:

Go to XBMC Audio output settings and choose custom for the Audio output device.

Set it to: plughw:0,3 Do the same thing for Passthrough output device.

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

What next?
If you don't want to have to plug/unplug the USB stick to boot into Linux/AppleTV OS, check: https://github.com/Evinyatar/atvclient/wiki/AppleTV-Linux-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: Add: Same can be done on the AppleTV OS side

Faster boot
atv-bootloader boots a default Linux kernel and then finds and boots your Linux kernel using kexec. You can avoid this double boot process by creating a custom atv-bootloader. To do so you need a Mac computer with the Developer Tools installed (it should be possible under Linux with the darwin-cross tools to compile/link).

On your Mac, get the atv-bootloader source code: Copy from your atv to that directory your ubuntu kernel (check your kernel version) and run make

You should now have a custom mach_kernel.

To use it to directly boot into your Linux installation, you just need to give the arguments that will get passed to the Linux kernel in the com.apple.Boot.plist.


 * If you use an USB flash drive to boot into Linux, replace the mach_kernel by the one you created and replace the plist by the following one:

Check the kernel arguments on the last line. They should be the same as the ones you have in your /boot/grub/menu.lst file. Note that there is no need for the "atv-boot=auto" line.


 * If you switch plist to boot into ATV OS / Linux as explained here, just replace the /mach_kernel_linux with the one you created and edit the /System/Library/CoreServices/com.apple.Boot.plist.linux file to add the kernel arguments as described above.

Runing Firefox
Exit XBMC and at the terminal install Firefox and Flash: Create a script to start firefox: add: Make firefox.sh executable: HDMI audio: add: Edit rc.local to restore launching xbmc at boot. add: Increase font size: Add an option DPI in the "monitor" section: run script ps.: It can take up to 3min to load firefox at first time. ps2.: to return to terminal: Ctrl+Alt+backspace

VNC Server
Install X11vnc Set a password (optional) Make X to load X11vnc at startup