Saturday, February 16, 2008

AppleTV | AppleTV Enable USB Storage

With much hard work from Turbo the AppleTV has finally been "hacked" to allow for external USB Storage. So instead of being limited to the internal 2.5 sata drive we can now use those nice cheap huge hard drives.

I am going to try and retrace the steps I took to enable usb storage on my AppleTV. I'll try and make it as simple as possible.

Before you start:
- You'll need ssh enabled
- You need to know the ip of your appletv (Can be found under the AppleTV's Settings:Network menus)
- You will need to have completed the 1.1 Safe Update. This might work for the 1.1 Software Update but I have not tried it so at your own risk!!!
- You will need a HFS or HFS+ formatted hard drive. (Note: you can do this with other formats; however, that will hopefully be explained in another tutorial)

Step One:
Download the update from apple. 2Z694-5248-45.dmg

Step Two:
Mount the dmg you just downloaded and copy the file mach_kernel.prelink to a temporary folder.

Step Three:
**This is an important step. According to the AwkwardTV Wiki you are supposed to use 2007-03-30 bsdiff file from Turbo if you have done the safe update. This did not work for me! I had to use the 2007-06-23 bsdiff file. This was huge hassle as I spent endless time trying to get the 20070330 update working.

If you have done the 1.1 Safe Update and want to try my procedure download the turbo-11-usb-and-watchdog-20070623.bsdiff and place it into the temporary folder you just created.

Step Four:
Open a new terminal window and navigate to the temporary folder you created. Execute the following command:
bspatch mach_kernel.prelink mach_kernel.patched turbo-11-usb-and-watchdog-20070623.bsdiff

Step Five:
You will now have a file called mach_kernel.patched. To make sure this patch was successful execute the following:
md5 mach_kernel.patched

Hopefully your result will match mine. (311f50ae644bc16967b7c0ac91cefaae)

Step Six:
Rename the patched file to mach_kernel.prelink, you can do this by entering the following command.
cp mach_kernel.patched ~/Desktop/mach.kernel.prelink

This command will copy the patched file to your desktop and also rename it appropriately.

Step Seven:
SSH into the AppleTV by entering the following commands:
ssh -1 frontrow@appletvipaddress (replace appletvipaddress with the AppleTV's IP Address)
Note: the password is frontrow

Step Eight:
Enter these command:
sudo /usr/sbin/AppleFileServer
sudo mount -uw
sudo cp /etc/hostconfig ~/hostconfig

Step Nine:
From a new finder window's menu select Go. Then select Connect to Server from the dropdown menu.

Enter the following for the address: afp://AppleTVsIPAddress. Of course replace 'AppleTVsIpAddress' with the actual ip of your AppleTV.

When prompted enter frontrow for both the username and password.

Step Ten
Select frontrow from the list of volumes to mount and then click ok

Step Eleven
Your AppleTV will now appear in your finder for easy access to files!

Step Twelve
Now drag the mach_kernel.prelink file you have on your desktop to the frontrow volume you just mounted.

Step Thirteen
Go back to your terminal window and execute the following commands.
sudo chown root:wheel mach_kernel.prelink
sudo mount -uw /
sudo mv mach_kernel.prelink /

This will set the correct permissions for the file and then move it to the correct location.

Step Fourteen
Go back to the frontrow volume you have mounted in a finder window and open hostconfig in TextEdit. Change AFPSERVER=-NO- to
AFPSERVER=-YES- and then save it.

Now in your terminal window execute the following:
sudo chown root:wheel hostconfig
sudo chmod 666 hostconfig
sudo mv hostconfig /etc/hostconfig
sudo reboot

These steps enable the AFP server at boot so you don't have to start it manually every time.

Step Fifteen
Open a new finder window and select Go:Go to Folder from the menu. Input /System/Library/Extensions/ as the folder to go to.

Step Sixteen
Select the following files:
IOUSBMassStorageClass.kext, IOStorageFamily.kext, and IOSCSIArchitectureModelFamily.kext

Select Edit:Copy from the menu, then in the other finder window with the frontrow volume mounted select Edit:Paste from the menu. This will copy the required files over to the Apple TV.

Step Seventeen
SSH back into the AppleTV by opening a new terminal window and executing the following:

ssh -1 frontrow@AppleTVIPAddress (where 'AppleTVIPAddress' is your Apple TV's IP Address)

Step Eighteen
Execute the following to correct the permissions of the files you just copied.

sudo mount -uw /
sudo chmod -R 755 IOUSBMassStorageClass.kext
sudo chmod -R 755 IOStorageFamily.kext
sudo chmod -R 755 IOSCSIArchitectureModelFamily.kext
sudo chown -R root:wheel IOUSBMassStorageClass.kext
sudo chown -R root:wheel IOStorageFamily.kext
sudo chown -R root:wheel IOSCSIArchitectureModelFamily.kext

Step Nineteen
Move the files to the correct location on the AppleTV.

sudo mv IOUSBMassStorageClass.kext /System/Library/Extensions/IOUSBMassStorageClass.kext
sudo mv IOStorageFamily.kext /System/Library/Extensions/IOStorageFamily.kext
sudo mv IOSCSIArchitectureModelFamily.kext /System/Library/Extensions/IOSCSIArchitectureModelFamily.kext

Step Twenty
Now you need to enable kext loading. Execute the following:
sudo touch /.readwrite
sudo sync
sudo reboot

Your AppleTV will reboot and when it does there are two new files /mach and /mach.sym

NOTE***: After my AppleTV rebooted from this I got the request to set my resolution. Once I did this it asked me to confirm that I saw the Apple Logo. I selected ok and then was presented with a menu that said restart, run diagnostics or restore. I selected run diagnostics. Once it confirmed that my appletv was okay I then unplugged the Apple TV and it booted up successfully this time. You may not get this but thats what happened to me!

Step Twenty One
SSH back into the AppleTV by executing the following in your terminal window:

ssh -1 frontrow@AppleTVIPAddress (where 'AppleTVIPAddress' is your Apple TV's IP Address)

Step Twenty Two
Enter the following commands into the terminal window:
sudo mount -uw /
sudo rm /.readwrite
sudo sync

Step Twenty Three
Download the file turbo_kext_enabler.bin from here.

Copy this file into the frontrow volume we mounted earlier.

Step Twenty Four
Enter the following:
sudo chmod 755 turbo_kext_enabler.bin
sudo mv turbo_kext_enabler.bin /System/Library/Extensions/turbo_kext_enabler.bin

Step Twenty Five
Now to load the kexts enter the following:
sudo /System/Library/Extensions/turbo_kext_enabler.bin
sudo kextload -v 6 /System/Library/Extensions/IOUSBMassStorageClass.kext

Step Twenty Six
Now the exciting part. Time to hook up a USB hard drive and see if it works! These instructions are for HFS and HFS+ formatted hard drives only! I may try and write a tutorial for other types later but for now this will only work with HFS and HFS+ drives.

Plug in your hard drive via the USB port at the back.

Enter the following into the terminal:
diskutil list

You should get a list of the disks connected to your system. Most likely the AppleTV is disk0 and your usb drive will be disk1.

Note: My hard drive has two partitions the first called data (disk1s2) and the second partition called MAC OS X Install DVD (disk1s3). Also note I upgrade my internal hard drive so my AppleTVs Media partition (disk0s4) is likely larger then yours.

Step Twenty Seven
Yay! Hopefully you just saw your USB Drive. Problem is that this does not happen automatically at boot so we need to do the following.

Open a new document in TextEdit.

Enter the following:
kextload /System/Library/Extensions/IOUSBMassStorageClass.kext

Then select Format:Make Plain Text from the menu.

You can now save this file as rc.local

Step Twenty Eight
Now copy this file(rc.local) over to your mounted frontrow volume.

Step Thirty
In terminal execute the following:
sudo chmod 755 rc.local
sudo chown root:wheel rc.local
sudo mv rc.local /etc/rc.local
sudo reboot

This will set the correct permissions for rc.local, move it to the correct location, and reboot the appletv.

Note***: Just a reboot didn't work for me I had to physically unplug the AppleTV so you might want to do that.

Step Thirty One
SSH back into the AppleTV by executing the following in your terminal window:

ssh -1 frontrow@AppleTVIPAddress (where 'AppleTVIPAddress' is your Apple TV's IP Address)

Don't forget the password is: frontrow

Step Thirty Two
Enter diskutil list at the command prompt. Your USB Hard Drive should appear!

Step Thirty Three
Now you have a choice. If you have a mac and want to enable afp permanently you could do this and then just access the new usb drive through the finder. (The new volumes will appear in Step 10)

But wait, I wanted my USB Drive to work with ATVFiles. In order to do this I must mount my external drive under the Movies folder where ATVFiles looks.

I am not sure of the best way to do this and would welcome any suggestions. What I ended up doing was creating a new StartupItem.

To do this continue with the next step.

Step Thirty Four
Create a new document in TextEdit.


# USBDisk

. /etc/rc.common

StartService ()
disktool -u disk1
/sbin/mount -t hfs /dev/disk1s1 '/Volumes/OSBoot/Users/frontrow/Movies/AppleTV HD'


StopService ()
/sbin/umount '/Volumes/OSBoot/Users/frontrow/Movies/AppleTV HD'

RestartService ()
/sbin/umount '/Volumes/OSBoot/Users/frontrow/Movies/AppleTV HD'
/sbin/mount -t hfs /dev/disk1s1 '/Volumes/OSBoot/Users/frontrow/Movies/AppleTV HD'

RunService "$1"

Replace disk1 & disk1s1 with the volume you would like to mount. If you don't know which volume to mount use the diskutil list command in your terminal window. Also I named my folder AppleTV HD. You can name yours whatever you like.

NOTE***: I have done this twice on two different appletvs. For some reason I needed the disktool -u disk1 on one and not the other. I have included it but you might not need to.

Click Format:Make Plain Text and then save this file as USBDisk with no extension.

Then copy the file to the frontrow volume you already mounted in finder.

Step Thirty Five
Create the following new document in Text Edit:

Description = "External USB Storage";
Provides = ("USBDisk");

Click Format:Make Plain Text and then save this file as StartupParameters.plist.

Then copy the file to the frontrow volume you already mounted in finder.

Step Thirty Six
Execute the following in your terminal window:
sudo mount -uw /
sudo mkdir /System/Library/StartupItems/USBDisk
sudo mv /Users/frontrow/USBDisk /System/Library/StartupItems/USBDisk/USBDisk
sudo mv /Users/frontrow/StartupParameters.plist /System/Library/StartupItems/USBDisk/StartupParameters.plist
sudo chown root:wheel /System/Library/StartupItems/USBDisk/USBDisk
sudo chmod 755 /System/Library/StartupItems/USBDisk/USBDisk
sudo chown root:wheel /System/Library/StartupItems/USBDisk/StartupParameters.plist

This will copy the StartupItem to the AppleTV. And set the correct permissions

Step Thirty Seven
Now go to the movies folder: cd Movies
And make a directory with the same name we used in Step Thirty Four which in my case was 'AppleTV HD': mkdir 'AppleTV HD'

Step Thirty Eight
Reboot the AppleTV with sudo reboot. When it reboots the USB Hard Drive should be mounted under the Movies:AppleTV HD folder. (Or whatever folder name you chose).

No comments: