Sunday, September 16, 2012

 

Ubuntu Precise (12.04) on Apple TV (1st generation)

I have an Apple TV(1st generation) that I use as a HTPC running XBMC. I planned to swap out the original hard drive with a compact flash card (poor man's SSD). One of the biggest issue with swapping the original hard drive out and replacing it with a compact flash card is to find a compact flash card that will boot. It is supposed that only compact flash card that identifies itself as "fixed disk" can boot as a replacement drive inside the Apple TV. Off late most vendors dont sell compact flash card that identifies itself as a "fixed disk" when using a compact flash to IDE adapter nor do they provide any utility to do the same as they have done in the past. Finding a compact flash card that will boot as a replacement drive has been the toughest part. After experimenting with a few myself and talking with other people who have tried I was close to giving up on using a compact flash card as the bootable drive. I finally found a card that did boot.

The devices I am using are:
Compact flash to IDE adapter: Syba SY-IDE2CF-NB25
Compact flash card: Maxell 8GB compact flash card maxdata 400x

In this post I will install a minimal base system that boots and starts a ssh-server. I will use IDE to USB adapter and linux system to do the installation.

In the rest of the post the compact flash device comes up as sdb, please use the appropriate device when you are trying it out.

First we will zero out the card.
# dd if=/dev/zero of=/dev/sdb bs=4096 count=2M

Create a GPT partition table
# partprobe /dev/sdb
# parted -s /dev/sdb mklabel gpt

Create the recovery partition
# parted -s /dev/sdb mkpart primary hfs 40s 69671s
# parted -s /dev/sdb set 1 atvrecv on

Create the swap partition
# parted -s /dev/sdb mkpart primary linux-swap 69672s 1118247s

Create the root partition
# parted -s /dev/sdb mkpart primary 1118248s 14909294s

Format the recovery partition
# partprobe /dev/sdb
# mkfs.hfsplus -v Recovery /dev/sdb1

Format the swap partition.
# mkswap /dev/sdb2

Format the root partition.
# mkfs.ext4 /dev/sdb3

Mount the root parition
# mount /dev/sdb3 tmp/

Install a minimal base system
debootstrap precise tmp/ http://us.archive.ubuntu.com/ubuntu/

Chroot into the base system
# mount -o bind /proc tmp/proc
# mount -o rbind /dev tmp/dev
# chroot tmp/ /bin/bash

Fix the locale warning like like "Locale not supported by C library." or "perl: warning: Setting locale failed."
# echo "en_US.UTF-8 UTF-8" > /var/lib/locales/supported.d/local
# dpkg-reconfigure locales

Setup the fstab, my fstab looks like this
# /etc/fstab: static file system information.
#
#                                                                
proc                                            /proc           proc    defaults                        0       0
# /dev/sda3
UUID=a0f8594c-fe28-4f6a-9312-ef684b4f5785       /               ext4    noatime,errors=remount-ro       0       1
# /dev/sda2
UUID=a3592f78-72fc-4cca-884d-b8bb4c26280f       none            swap    sw                              0       0

Setup apt sources.list, my sources.list looks like this
deb http://us.archive.ubuntu.com/ubuntu precise main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu precise-security main restricted universe multiverse

Create a user for login
# adduser foo --gecos "Foo Bar"

Install ssh server
apt-get install openssh-server

To boot linux on the apple tv one needs to use the atv-bootloader [1]. One can use the atv-bootloader to kexec into the stock distribution kernel. Since I dont upgrade my kernel often I would rather avoid the kexec step. I built my own kernel with using a config that works with the atv-bootloader. After I install that kernel I create the mach_kernel that I copied into the recovery partition. I am not covering the details in this post.
Now just go ahead and replace the stock IDE hard drive with this compact flash and now you have a poor mans SSD booting in your apple tv.


[1] Apple TV bootloader

Labels: , ,


Comments:
Bharath, "Ubuntu Precise (12.04) on Apple TV (1st generation)" Have you done this on a actual "fixed" hard drive? I'd rather use a ,say 120 gig SSD, than a compact flash.
 
@Tom,
This would work on a fixed hard drive as well. Compact flash just comes up as an IDE drive.
 
I am curious if you could install linux directly to a drive and do that instead?

Or are these parations and bootloader required by the atv.
 
The recovery partition is required for the apple tv to boot. You need to create the first partition just as mentioned in this guide, dont change even the sectors. You can then install linux however you want.
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?