Overview

These instructions will guide you through the preparation of a new hard disk to replace the factory disk in the Apple TV. When complete, the newly prepared disk will be identical to a factory disk but with a larger Media partition. Please refer to other articles for other hacks.

Remark: There are several methods to add a new (larger) hard disk around. Some users found the method described here (doing a factory restore in the end) the only one of the command line based methods to work with large drives (larger than approx. 80 GB). You find out that you have a problem with other methods at the moment when formatting a partition takes longer than minutes ;-)

The Apple TV factory disk consists of four partitions:

EFI - a small partition containing very basic information used by the Mac's EFI boot system to identify the drive and boot from it

Recovery - contains an original factory-fresh version of what is copied into OSBoot during a Factory Restore

OSBoot - the boot partition with the Mac OS version the ATV runs.

Media - the largest partition, where all of your media is stored.

The goal of this document is to illustrate several methods of re-creating the basic layout of the original drive, and then re-formatting the Media partition in order to increase the storage.

There is a little bit of voodoo involved in recreating the partitions on the new disk, because of strange behavior of diskutil. The OSBoot and Media partitions must be created and formatted before the EFI and Recovery partitions are on the disk. Otherwise, diskutil gets confused and does some strange things to the partition table. This method should take less than 10 minutes to complete, because only the EFI and Recovery partition are duplicated from the factory disk. The OSBBoot partition and Media get initialized by the Apple TV Factory Restore procedure.

The main procedure outlined below is somewhat technical, but is the fastest way to format the new drive and get it working.

The FreeNAS Method requires only few steps and doesn't require a Macintosh at all.

Requirements

The instructions are only working on any Macintosh Computer (PPC or Intel) at least as you running under Mac OS X 10.4.x or OS X 10.5.x. Whatever OS you have, "gpt," the GUID Partition Table tools, must be found on your current operating system to get it working.

Other BSD-like operating systems might also be used, but the ingredients will have to be suitably modified. This article assumes that you have successfully removed the factory disk from the Apple TV and that you have the necessary hardware, e.g. a 2.5" ATA to USB or FireWire adapter, for connecting the disk to your Macintosh.

We will assume that when the disk is connected to your computer, it is associated with device node: /dev/disk2. Remember to replace /dev/disk2 with the appropriate device node!

While executing the gpt commands below, OS X may try to mount the volumes on the disk. You can safely click "Ignore" if Finder complains to you about an uninitialized disk. If it is able to mount the volume, make sure to eject it before continuing, otherwise gpt will not be able to access the disk.

Compatible Drives

The orginal Apple TV drives are Fujitsu MHW2040AT for the ATV 40GB or the Samsung HM160JC for the 160GB version, these are parallel ATA (PATA) drives. The highest capacity PATA currently on the market is 320GB, by Western Digital.

To go beyond the current barrier limited by the PATA drives you need a PATA<->SATA adaptor which will allow you to use recent SATA drives.

This will create a formatted (Journaled HFS+) Media partition. You may have to run (force by pressing Menu + down/scroll) for a Factory Restore process. Factory Restore must be done twice !

Acquiring the necessary images

The factory disk should be connected to your computer and located at device node /dev/disk2. You will need a copy of the EFI image and the recovery partition from the factory disk. They are located on partitions 1 and 2 of the factory disk, respectively. You can copy them with dd by entering these commands into the command prompt:

The unmount is there to make sure that the HFS+ partitions on the factory disk are not mounted. These commands may take a few minutes to complete. You can check on the status of dd while it is running by pressing Ctrl-T. The bs=1m option sets the size of the memory buffer used while copying, it is not strictly necessary, but it helps speed things up.

When the commands have completed, the resulting files should be 35651584 bytes (about 34MB) and 419430400 bytes (about 400MB). The optional step with the OSBoot image is required, if the factory reset should be avoided. You may now disconnect the factory disk.

If you have the ability to ssh into the ATV, the EFI and Recovery images may be generated entirely within the ATV, then copied to your desktop computer. This allows the new hard drive to be prepared in advance so that the hard drive upgrade process becomes a simple swap out. To get started, first ssh into the ATV, then type diskutil list. This is not strictly necessary but does help ensure a uniform starting point. You should get the following results:

Then type the following commands to generate the disk images in your /Users/frontrow/Documents directory. It is not necessary to unmount the drive since the two partitions you are copying have never been mounted to begin with.

The password is frontrow. The images will be placed in the current directory.

Optional: Hacking the Recovery Image

The recovery.img file can be mounted like any other disk image. Inside, you will find OS.dmg. This is the factory image of the OSBoot partition. Eventually, this image will be written to your new disk. You can modify it at this point if you'd like.

to edit the image you will need to convert it to read-write and then attach it

EDIT: If you want to edit the OS.dmg make CERTAIN to do an asr imagescan, and make SURE it is read only. Otherwise any attempt to restore from this dmg will fail.

Optional: Resizing OSBoot

If you have used the AppleTV long enough and done enough extra installations you realize the space on OSBoot shrinks really quickly to nothing, it is possible to resize OSBoot with one MAJOR caveat Anything over 1000 MB will require some **extra tweaking, and all future updates will have to be performed MANUALLY. In addition, the recovery hack above is also required with ssh installed at the VERY least.

This process may seem needlessly complicated, but Media must be mounted because the recovery dmg does not have enough free space on it to accommodate a hacked OS.dmg. (hence the need to ssh in and mountDisk /dev/disk0 first before scping)

as far as extra tweaking is concerned the /etc/rc file on OSBoot needs to be modified with the following snippet (the bold is the new code)

step 4 is predicated by atvPwn being run prior to scping that Updates folder. (with the new rc patch preference selected)

the rc script runs a binary called redirect, specifically "redirect --scratch" is what we are focused on, if the OSBoot partition has been sized over a 1 GB redirect --scratch reports /dev/disk0s3 when it SHOULD report /dev/disk0s4 (the assumption is the efi sets an interval to search for the start of /dev/disk0s4 for the Media partition) we ONLY set it for redirected because "redirected" is only reported as the variable (alledgedly) when we are booted normally. For updates and recovery mode "redirect --boottype" returns "recovery", so if we always set SCRATCH to /dev/disk0s4 updates and recoveries wouldn't work properly. (although updates still require manual coaxing)

-s 184300 is 900 MB in bytes (184300 / 2048 = 900) so if you wanted a OSBoot to be 1 GB rather than 900 MB you would use -s 2048000 of course the start and size of the Media partition would need to be adjusted as well in the steps directly after adding index 3. Note the caveats listed above for any OSBoot over 1000 MB.

NOTE: This information is technically incomplete, the GPT partition map requires any drive that has multiple partitions above the 1/2GB mark to start with an EFI partition that is 200 megs in size rather than 40 bytes, it also requires 128 megs of empty space after each partition over 1 GB, and then 262151 bytes of free space after the final partition

Preparing the partition table

Connect the new disk. Again, the instructions assume that it is associated with device node: /dev/disk2. If this disk was previously non-empty, make sure that no volumes on the disk are mounted.

We will now erase any existing partition table on the disk and create a new GUID partition table using the command gpt. The command will fail if any volumes on the disk are mounted, so make sure you unmount them.

Update Partitions

You may now disconnect the disk (but make sure you have ejected/unmounted it first).

Apple TV Factory Restore

Connect the new disk to the Apple TV and power it up. The Apple TV should now boot up from the new disk. After a minute or so, you should be asked to choose a language and then presented with the "Apple TV Recovery" screen. Go ahead and do the factory restore. This will initialize the OSBoot partition with the original factory image. Your Apple TV is now identical to the factory version, but with a larger Media partition.

Simple Alternative Method

There is an alternative method where you duplicate the partitions you need with one command and then copy them to the new disk, then complete the preparation with the Apple TV Factory Restore.
To duplicate the factory disk, connect it to your computer and execute:

sudo dd if=/dev/disk2 of=appletv.dmg bs=1m

This command may take several hours to complete, depending on the speed of the interface between your computer and the disk. Now disconnect the factory disk and connect your new disk. Write the image of the factory disk:

sudo dd if=appletv.dmg of=/dev/disk2 bs=1m

This command may take several hours to complete, depending on the speed of the interface between your computer and the disk. Once it completes, disconnect the disk and follow the instructions above under #Apple TV Factory Restore.

FreeNAS Method (1)

Not everyone has a Mactinosh under the table but you need a system to create the GPT including the GUID signature for the recovery partition. The quickest and slickest I was able to find is a FreeBSD based system using the FreeNAS distribution. Depending on whether you are running the ISO natively or inside a VMware you need only a few steps of the above. If you have only one attached USB storage device it's likely to be /dev/da0 so the example will use this device:

Now dd the EFI and Recovery images back to the first and second partition and you are all set. There is no need to partition the Media storage - it will automatically be done during the factory restore. Also partition three and for will be formated - no need to do this also. --Hphde 23:13, 18 February 2008 (CET)

FreeNAS Method (2)

If the Factory restore fails using FreeNAS Method (1) above, I found the following worked to install a WD 320 GB drive into a 40 GB AppleTV:

Boot up FreeNAS from a CD-ROM

Create a USB boot of the embedded version (choice 9/1)

Using two 3.5 to 2.5 IDE adapters connect the old 40 GB AppleTV drive to the primary IDE channel and the new 320 GB drive to the secondary channel. Remove all other devices from the IDE channels.

Boot up the PC, go into the Bios and set the correct HD settings, Set Bios to boot from the USB port. Boot up the PC.

Select option 6 from the FreeNAS startup menu and enter the source mode.

Check which drive is which:

gpt show /dev/ad0
gpt show /dev/ad2

Do a complete disk copy using dd. This will take 15-30 mins. The following command assumes the 40GB drive is ad0 and the new 320GB drive is ad2.

This is where the Media partition will go. Create the Media partition with the following command, replacing START and SIZE with the numbers from your output as in the example of the two numbers above:

gpt add -b START -i 4 -s SIZE -t hfs /dev/ad2

The drive is now ready to put into the AppleTV. The AppleTV will boot up normally. Go to Settings/General/Reset Settings and select the Factory Restore. After this has run, you will need to apply any available software updates. Go to Settings/General/Update Software.