Difference between revisions of "Enable USB Storage on 2.x"

From AwkwardTV
Jump to: navigation, search
(Prerequisites)
m (typo)
 
(84 intermediate revisions by 12 users not shown)
Line 1: Line 1:
=Note=
+
'''This guide is for Apple TV 2.x (Take 2), for 1.x see [[Enable USB Storage on 1.x]]'''
This how-to is a compilation of bits and pieces of other how-to's in this wiki, such as
+
 
 +
This page is a compilation of bits and pieces of other how-to's in this wiki, mainly
 
* [[Enable Kext Loading]]
 
* [[Enable Kext Loading]]
 
* [[Take 2 Full Update]]
 
* [[Take 2 Full Update]]
  
=Prerequisites=
+
Ben Mackin's USB enabler patch (based on oz_paulb's original patch tool with offsets from Turbo)
 +
* doesn't work with AppleTV V2.x <code>/mach_kernel.prelink</code> straight out of the box, but it works once the script has been modified with the proper offsets.
 +
* doesn't work with AppleTV V3.x, I suppose the offsets have to be modified too...
 +
 
 +
'''NOTE''': You can use a recent version of the [[Install nitoTV|Nito TV]] [[NitoTV_Take_2|plugin]] to enable kext loading and use its smart installer for USB support. There is no need to run the below by hand. --[[User:Hphde|Hphde]] 11:17, 7 June 2009 (CEST)
 +
 
 +
 
 +
==Prerequisites==
 
In order to enable mounting external USB devices, you will need
 
In order to enable mounting external USB devices, you will need
 
* [[Install_SSH_with_Leopard|SSH access]] to the AppleTV, or its harddisk directly connected to your computer
 
* [[Install_SSH_with_Leopard|SSH access]] to the AppleTV, or its harddisk directly connected to your computer
* [http://0xfeedbeef.com/appletv/ Turbo]'s .kext enabler
+
* [http://0xfeedbeef.com/appletv/ Turbo's] .kext enabler
* [http://www.benmackin.com/ Ben Mackin]'s [http://www.benmackin.com/stuff/kernelpatch.tgz kernel patcher].
+
* [http://www.benmackin.com/ Ben Mackin's] version of oz_paulb's original kernel patcher.
* Mac OS X Tiger - Intel extensions for USB mass storage I/O
+
* Mac OS X Tiger - Intel: extensions for USB mass storage I/O
  
=Kernel=
+
==Installation==
 +
 
 +
===Kernel===
 
Enabling USB requires to modify <code>/mach_kernel.prelink</code> on the AppleTV.
 
Enabling USB requires to modify <code>/mach_kernel.prelink</code> on the AppleTV.
 
If this file isn't there yet, this means the system partition hasn't been forced to be mounted read/write yet.
 
If this file isn't there yet, this means the system partition hasn't been forced to be mounted read/write yet.
Force it read/write:
+
Force it read/write with:
 
  ssh frontrow@AppleTV.local
 
  ssh frontrow@AppleTV.local
 
  sudo -s
 
  sudo -s
 +
mount -uw /
 
  touch /.readwrite
 
  touch /.readwrite
 
  reboot
 
  reboot
  
=Kext enabler=
+
===Kext enabler===
 
Turbo's Kext enabler allows to load <code>.kext</code> system extensions into the system.
 
Turbo's Kext enabler allows to load <code>.kext</code> system extensions into the system.
  
*Download [http://0xfeedbeef.com/appletv/turbo_kext_enabler.bin turbo_kext_enabler.bin] which works for AppleTV 2.0.
+
*Download [http://0xfeedbeef.com/appletv/turbo_atv_enabler.bin turbo_atv_enabler.bin] which offers the latest SSE3 emulation and works for AppleTV 2.x series
  
*Copy it to the AppleTV in folder <code>/sbin/</code> and check for the file's attributes:
+
* Rename it from turbo_atv_enabler.bin to turbo_kext_enabler.bin. This is to ensure compatibility as older versions of this file were called turbo_atv_enabler.bin
 +
 
 +
*Copy it to the AppleTV in folder <code>/sbin/</code> and check for the file's attributes:  
 
  ssh frontrow@AppleTV.local
 
  ssh frontrow@AppleTV.local
 
  sudo -s
 
  sudo -s
Line 35: Line 48:
 
  chmod 555 turbo_kext_enabler.bin
 
  chmod 555 turbo_kext_enabler.bin
  
Turbo's USB patch doesn't work for AppleTV 2.0 yet.
+
Note: Turbo's USB patch has not been updated to work for AppleTV 2.x yet.
 +
 
 +
===Kernel patch===
 +
[http://www.benmackin.com/ Ben Mackin] is hosting a modified copy of oz_paulb's [http://www.benmackin.com/stuff/kernelpatch.tgz kernel patcher] for enabling USB.
 +
 
 +
Note: the [[Take_2_Full_Update#7.29_Install_USB|Take 2 Full Update]] page seems to indicate that the kernel patcher only works on Intel Macs, and has to be recompiled from source for PPC Macs (or other platforms).
  
=Kernel patch=
+
To patch the kernel:
[http://www.benmackin.com/ Ben Mackin] has written a [http://www.benmackin.com/stuff/kernelpatch.tgz kernel patcher] for enabling USB.
 
  
 
* Download the [http://www.benmackin.com/stuff/kernelpatch.tgz kernel patcher] to your Mac.
 
* Download the [http://www.benmackin.com/stuff/kernelpatch.tgz kernel patcher] to your Mac.
Line 44: Line 61:
 
* Extract the <code>kernelpatch</code> folder from it (double-click).
 
* Extract the <code>kernelpatch</code> folder from it (double-click).
  
* Copy <code>/mach_kernel.prelink</code> to your Mac inside that folder.
+
* Copy the AppleTV's <code>/mach_kernel.prelink</code> to your Mac inside that folder.
 +
 
 +
* Inside the Terminal, <code>cd</code> into that folder.
 +
 
 +
* '''With AppleTV 2.0.1, 2.0.2, 2.1, 2.2 or 2.3''', modify the portion of <code>do_usb_patch.sh</code> so that it becomes:
 +
#
 +
# ==== patch the decompressed kernel
 +
#
 +
echo ======== patch kernel =========
 +
./poke mach_kernel_patched.bin 0x52055e 0x75:0x75 0x34:0x30
 +
if [ $? -ne 0 ]; then exit 1; fi
 +
 +
./poke mach_kernel_patched.bin 0x52123E 0x75:0x75 0x34:0x30
 +
if [ $? -ne 0 ]; then exit 1; fi
 +
 +
./poke mach_kernel_patched.bin 0x520576 0x75:0x75 0x1c:0x18
 +
if [ $? -ne 0 ]; then exit 1; fi
 +
 +
./poke mach_kernel_patched.bin 0x521256 0x75:0x75 0x1c:0x18
 +
if [ $? -ne 0 ]; then exit 1; fi
  
* Inside the Terminal, <code>cd</code> to that folder. Once there:
+
* Patch the kernel:
 
  ./do_usb_patch.sh
 
  ./do_usb_patch.sh
 
  mv mach_kernel.prelink mach_kernel_original.prelink
 
  mv mach_kernel.prelink mach_kernel_original.prelink
Line 53: Line 89:
 
* Copy the new <code>/mach_kernel.prelink</code> back to the AppleTV.
 
* Copy the new <code>/mach_kernel.prelink</code> back to the AppleTV.
  
=Extensions for USB drives=
+
* Reboot the AppleTV
 +
 
 +
===Extensions for USB drives===
 +
The following extensions are needed for mounting USB drives:
 +
/System/Library/Extensions/IOSCSIArchitectureModelFamily.kext
 +
/System/Library/Extensions/IOStorageFamily.kext
 +
/System/Library/Extensions/IOUSBMassStorageClass.kext
 +
 
 +
I got mine from a Mac OS X Tiger install on an Intel machine.
 +
 
 +
The ones from the Darwin x86 iso won't work: with these, I get the message:
 +
kextload: loaded version 1.5.1 of module com.apple.iokit.IOStorageFamily differs from requested version com.apple.iokit.IOStorageFamily
 +
 
 +
One can [[Patchstick/Leopard#Leopard_Files|retrieve files from a downloadable combo update]].
 +
 
 +
Once the files are copied, you can try if they work.
 +
Reboot the AppleTV and:
 +
ssh frontrow@AppleTV.local
 +
sudo -s
 +
/sbin/turbo_kext_enabler.bin
 +
/sbin/kextload -v /System/Library/Extensions/IOUSBMassStorageClass.kext
 +
 
 +
If the kext fail to load you can try changing the permissions:
 +
<pre>sudo chmod -R 755 /System/Library/Extensions/IOUSBMassStorageClass.kext
 +
sudo chmod -R 755 /System/Library/Extensions/IOStorageFamily.kext
 +
sudo chmod -R 755 /System/Library/Extensions/IOSCSIArchitectureModelFamily.kext
 +
sudo chown -R root:wheel /System/Library/Extensions/IOUSBMassStorageClass.kext
 +
sudo chown -R root:wheel /System/Library/Extensions/IOStorageFamily.kext
 +
sudo chown -R root:wheel /System/Library/Extensions/IOSCSIArchitectureModelFamily.kext</pre>
 +
 
 +
 
 +
If the loading works fine, plug an USB drive to the AppleTV and check if it is seen by the system:
 +
diskutil list
 +
 
 +
You should see
 +
/dev/disk0
 +
    #:                  type name              size      identifier
 +
    0:  GUID_partition_scheme                    *37.3 GB  disk0
 +
    1:                    EFI                    34.0 MB  disk0s1
 +
    2:        Apple_Recovery                    400.0 MB  disk0s2
 +
    3:              Apple_HFS OSBoot            900.0 MB  disk0s3
 +
    4:              Apple_HFS Media              35.8 GB  disk0s4
 +
/dev/disk1
 +
    #:                  type name              size      identifier
 +
    ...
 +
where, <code>/dev/disk1</code> is the newly mounted USB drive.
 +
 
 +
==Automatic loading at boot==
 +
 
 +
===Using rc.local===
 +
 
 +
Automatically loading the USB mass storage extension at boot can be done with the help of <code>/etc/rc.local</code>.
 +
Create or edit the file and add the commands from the following listing:
 +
 
 +
# rc.local
 +
 +
# enable USB
 +
/sbin/turbo_kext_enabler.bin
 +
/sbin/kextload -v /System/Library/Extensions/IOUSBMassStorageClass.kext
 +
 
 +
Restart the AppleTV and try pluging and unplugging an USB drive.
 +
 
 +
===Defining a startup item===
 +
 
 +
Let's define a <code>Shares</code> startup item:
 +
 
 +
* Login to the AppleTV and navigate to the user startup items location:
 +
ssh frontrow@AppleTV.local
 +
sudo -s
 +
cd /Library/StartupItems/
 +
 
 +
* Create the folder defining the startup item and go inside it:
 +
mkdir Shares
 +
cd Shares
 +
 
 +
* Create the <code>Shares</code> startup item script (the name must match the directory):
 +
#!/bin/sh
 +
 +
##
 +
# Share control
 +
##
 +
 +
. /etc/rc.common
 +
service_name='Network Shares'
 +
 +
StartService ()
 +
{
 +
    echo "Starting $service_name"
 +
    turbo_kext_enabler.bin > /dev/null 2>&1
 +
    kextload  /System/Library/Extensions/IOUSBMassStorageClass.kext
 +
}
 +
 
 +
StopService ()
 +
{
 +
    echo "Stopping $service_name"
 +
    kextunload  /System/Library/Extensions/IOUSBMassStorageClass.kext
 +
}
 +
 +
RestartService ()
 +
{
 +
    StopService
 +
    sleep 2s
 +
    StartService
 +
}
 +
 +
RunService "$1"
 +
 
 +
Make the service executable:
 +
chmod 755 Shares
 +
 
 +
* Create the <code>StartupParameters.plist</code> definition:
 +
{
 +
  Description    = "Network Shares";
 +
  Provides        = ("Network Shares");
 +
  Requires        = ("Disks");
 +
}
 +
 
 +
Restart the AppleTV and try pluging and unplugging an USB drive.
  
  
[[Category:How-to]] [[Category:2.0]]
+
[[Category:How-to]]
 +
[[Category:2.0]]
 +
[[Category:2.0.1]]
 +
[[Category:2.0.2]]
 +
[[Category:2.1]]
 +
[[Category:2.3]]

Latest revision as of 10:24, 20 May 2011

This guide is for Apple TV 2.x (Take 2), for 1.x see Enable USB Storage on 1.x

This page is a compilation of bits and pieces of other how-to's in this wiki, mainly

Ben Mackin's USB enabler patch (based on oz_paulb's original patch tool with offsets from Turbo)

  • doesn't work with AppleTV V2.x /mach_kernel.prelink straight out of the box, but it works once the script has been modified with the proper offsets.
  • doesn't work with AppleTV V3.x, I suppose the offsets have to be modified too...

NOTE: You can use a recent version of the Nito TV plugin to enable kext loading and use its smart installer for USB support. There is no need to run the below by hand. --Hphde 11:17, 7 June 2009 (CEST)


Prerequisites

In order to enable mounting external USB devices, you will need

  • SSH access to the AppleTV, or its harddisk directly connected to your computer
  • Turbo's .kext enabler
  • Ben Mackin's version of oz_paulb's original kernel patcher.
  • Mac OS X Tiger - Intel: extensions for USB mass storage I/O

Installation

Kernel

Enabling USB requires to modify /mach_kernel.prelink on the AppleTV. If this file isn't there yet, this means the system partition hasn't been forced to be mounted read/write yet. Force it read/write with:

ssh frontrow@AppleTV.local
sudo -s
mount -uw /
touch /.readwrite
reboot

Kext enabler

Turbo's Kext enabler allows to load .kext system extensions into the system.

  • Rename it from turbo_atv_enabler.bin to turbo_kext_enabler.bin. This is to ensure compatibility as older versions of this file were called turbo_atv_enabler.bin
  • Copy it to the AppleTV in folder /sbin/ and check for the file's attributes:
ssh frontrow@AppleTV.local
sudo -s
cd /sbin/
ls -l turbo_kext_enabler.bin
  • You might want to change them to:
chown root:wheel turbo_kext_enabler.bin
chmod 555 turbo_kext_enabler.bin

Note: Turbo's USB patch has not been updated to work for AppleTV 2.x yet.

Kernel patch

Ben Mackin is hosting a modified copy of oz_paulb's kernel patcher for enabling USB.

Note: the Take 2 Full Update page seems to indicate that the kernel patcher only works on Intel Macs, and has to be recompiled from source for PPC Macs (or other platforms).

To patch the kernel:

  • Extract the kernelpatch folder from it (double-click).
  • Copy the AppleTV's /mach_kernel.prelink to your Mac inside that folder.
  • Inside the Terminal, cd into that folder.
  • With AppleTV 2.0.1, 2.0.2, 2.1, 2.2 or 2.3, modify the portion of do_usb_patch.sh so that it becomes:
#
# ==== patch the decompressed kernel
#
echo ======== patch kernel =========
./poke mach_kernel_patched.bin 0x52055e 0x75:0x75 0x34:0x30
if [ $? -ne 0 ]; then exit 1; fi

./poke mach_kernel_patched.bin 0x52123E 0x75:0x75 0x34:0x30
if [ $? -ne 0 ]; then exit 1; fi

./poke mach_kernel_patched.bin 0x520576 0x75:0x75 0x1c:0x18
if [ $? -ne 0 ]; then exit 1; fi

./poke mach_kernel_patched.bin 0x521256 0x75:0x75 0x1c:0x18
if [ $? -ne 0 ]; then exit 1; fi
  • Patch the kernel:
./do_usb_patch.sh
mv mach_kernel.prelink mach_kernel_original.prelink
mv mach_kernel_patched.prelink mach_kernel.prelink
  • Copy the new /mach_kernel.prelink back to the AppleTV.
  • Reboot the AppleTV

Extensions for USB drives

The following extensions are needed for mounting USB drives:

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

I got mine from a Mac OS X Tiger install on an Intel machine.

The ones from the Darwin x86 iso won't work: with these, I get the message:

kextload: loaded version 1.5.1 of module com.apple.iokit.IOStorageFamily differs from requested version com.apple.iokit.IOStorageFamily

One can retrieve files from a downloadable combo update.

Once the files are copied, you can try if they work. Reboot the AppleTV and:

ssh frontrow@AppleTV.local
sudo -s
/sbin/turbo_kext_enabler.bin
/sbin/kextload -v /System/Library/Extensions/IOUSBMassStorageClass.kext

If the kext fail to load you can try changing the permissions:

sudo chmod -R 755 /System/Library/Extensions/IOUSBMassStorageClass.kext
sudo chmod -R 755 /System/Library/Extensions/IOStorageFamily.kext
sudo chmod -R 755 /System/Library/Extensions/IOSCSIArchitectureModelFamily.kext
sudo chown -R root:wheel /System/Library/Extensions/IOUSBMassStorageClass.kext
sudo chown -R root:wheel /System/Library/Extensions/IOStorageFamily.kext
sudo chown -R root:wheel /System/Library/Extensions/IOSCSIArchitectureModelFamily.kext


If the loading works fine, plug an USB drive to the AppleTV and check if it is seen by the system:

diskutil list

You should see

/dev/disk0
   #:                   type name               size      identifier
   0:  GUID_partition_scheme                    *37.3 GB  disk0
   1:                    EFI                    34.0 MB   disk0s1
   2:         Apple_Recovery                    400.0 MB  disk0s2
   3:              Apple_HFS OSBoot             900.0 MB  disk0s3
   4:              Apple_HFS Media              35.8 GB   disk0s4
/dev/disk1
   #:                   type name               size      identifier
   ...

where, /dev/disk1 is the newly mounted USB drive.

Automatic loading at boot

Using rc.local

Automatically loading the USB mass storage extension at boot can be done with the help of /etc/rc.local. Create or edit the file and add the commands from the following listing:

# rc.local

# enable USB
/sbin/turbo_kext_enabler.bin
/sbin/kextload -v /System/Library/Extensions/IOUSBMassStorageClass.kext

Restart the AppleTV and try pluging and unplugging an USB drive.

Defining a startup item

Let's define a Shares startup item:

  • Login to the AppleTV and navigate to the user startup items location:
ssh frontrow@AppleTV.local
sudo -s
cd /Library/StartupItems/
  • Create the folder defining the startup item and go inside it:
mkdir Shares
cd Shares
  • Create the Shares startup item script (the name must match the directory):
#!/bin/sh

##
# Share control
##

. /etc/rc.common
service_name='Network Shares'

StartService ()
{
    echo "Starting $service_name"
    turbo_kext_enabler.bin > /dev/null 2>&1
    kextload  /System/Library/Extensions/IOUSBMassStorageClass.kext
}
 
StopService ()
{
    echo "Stopping $service_name"
    kextunload  /System/Library/Extensions/IOUSBMassStorageClass.kext
}

RestartService ()
{
    StopService
    sleep 2s
    StartService
}

RunService "$1"

Make the service executable:

chmod 755 Shares
  • Create the StartupParameters.plist definition:
{
  Description     = "Network Shares";
  Provides        = ("Network Shares");
  Requires        = ("Disks");
}

Restart the AppleTV and try pluging and unplugging an USB drive.