Prepare a Hard Drive
- 1 Overview
- 2 Requirements
- 3 Acquiring the necessary images
- 4 Preparing the partition table
- 5 Formatting the HFS+ partitions
- 6 Creating and writing the EFI and Recovery partitions
- 7 Apple TV Factory Restore
- 8 Simpler Alternative Method
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.
The Apple TV factory disk consists of four partitions:
There is a little bit of voodoo involved in recreating them 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 #Simple Alternative Method below is indeed simpler, but can take several hours to complete.
The instructions have only been tested on an Intel-based Macintosh under Mac OS X. They may work on a PowerPC-based machine, or other BSD-like operating system 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 Intel-based Macintosh.
We will assume that when the disk is connected to your computer, it is associated with device node: /dev/disk2. Remeber to replace /dev/disk2 with the appropariate 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.
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:
diskutil unmountDisk /dev/disk4 dd if=/dev/disk2s1 of=efi.dmg bs=1m dd if=/dev/disk2s2 of=recovery.dmg bs=1m
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 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). You may now disconnect the factory disk.
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.
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.
gpt destroy /dev/disk2 gpt create /dev/disk2
Adding the OSBoot and Media partitions
The OSBoot and Media partitions have to be added and formatted first, otherwise diskutil gets confused by the EFI and Recovery partitions.
First add the OSBoot partition.
gpt add -b 888872 -i 3 -s 1843200 -t hfs /dev/disk2
Now we can determine the size of the Media partition.
gpt show /dev/disk2
The output of the command should look something like this:
start size index contents 0 1 PMBR 1 1 Pri GPT header 2 32 Pri GPT table 34 888838 888872 1843200 3 GPT part - 48465300-0000-11AA-AA11-00306543ECAC 2732072 153569383 156301455 32 Sec GPT table 156301487 1 Sec GPT header
The important part is the line above Sec GPT table:
This is where the Media partition will go. Create the Media partition with the following command, replacing START and SIZE with the two numbers above:
gpt add -b START -i 4 -s SIZE -t hfs /dev/disk2
Again, Finder will complain to you that the disk is unitialized. Ignore the warning.
Formatting the HFS+ partitions
We will now format (erase) the HFS+ partitions and then unmount them:
diskutil eraseVolume "Journaled HFS+" OSBoot /dev/disk2s3 diskutil eraseVolume "Journaled HFS+" Media /dev/disk2s4 diskutil umountDisk /dev/disk2
Creating and writing the EFI and Recovery partitions
Now we can add EFI and Recovery partitions. First, add the EFI partition:
gpt add -b 40 -i 1 -s 69632 -t efi /dev/disk4
After the command completes, Finder will automount the OSBoot and Media partitions. Unmount them.
diskutil unmountDisk /dev/disk4
Now add the Recovery partition:
gpt add -b 69672 -i 2 -s 819200 -t 5265636F-7665-11AA-AA11-00306543ECAC /dev/disk4
Again, after Finder automounts the OSBoot and Media partitions, unmount them.
diskutil unmountDisk /dev/disk4
The final step is to write the EFI and Recovery images that you copied from the factory disk to the new disk. First, we need to create the EFI partition:
dd if=efi.dmg of=/dev/disk2s1 bs=1m dd if=recovery.dmg of=/dev/disk2s2 bs=1m
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.
Simpler 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. This is a simpler method, remove the count=1335 to copy the entire disk, 37 GB instead of 1.4 GB. To duplicate the factory disk, connect it to your computer and execute:
dd if=/dev/disk2 count=1335 of=appletv.dmg bs=1m
If you remove the count=1335, 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:
dd if=appletv.dmg of=/dev/disk2 bs=1m
If you remove the count=1335, 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.