Prepare a Hard Drive

From AwkwardTV
Revision as of 13:47, 25 May 2007 by LeMarsu (talk | contribs) (Compatible Drives)
Jump to: navigation, search


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:

  1. EFI
  2. Recovery
  3. OSBoot
  4. Media

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 could work on a PowerPC-based machine, with OS X 10.4.6 or higher where "gpt," the GUID Partition Table tools can be found. 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 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.

Compatible Drives

The orginal Apple TV drive is a FUJITSU MHW2040AT , a parallel ATA (PATA) drive. The highest capacity PATA currently on the market is 160GB.

Your Options:

Name Works
160 GB Samsung Harddrive (Samsung SpinPoint HM160JC) ??
Hitachi [HTS541616J9AT00] Yes
Hitachi Travelstar 4K120 ??
Seagate ST9160821A ??

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/disk2
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: Acquiring EFI and Recovery images without removing the hard drive

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:

   #:                   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

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.

dd if=/dev/disk0s1 of=/Users/frontrow/Documents/efi.dmg bs=1m
dd if=/dev/disk0s2 of=/Users/frontrow/Documents/recovery.dmg bs=1m 

Finally, copy the two images to your desktop computer with the following commands and proceed as below.

scp /Users/frontrow/Documents/efi.dmg yourusername@youraddress:/efi.dmg
scp /Users/frontrow/Documents/recovery.dmg yourusername@youraddress:/recovery.dmg

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:

    2732072  153569383         

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 unmountDisk /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/disk2

After the command completes, Finder will automount the OSBoot and Media partitions. Unmount them.

diskutil unmountDisk /dev/disk2

Now add the Recovery partition:

gpt add -b 69672 -i 2 -s 819200 -t 5265636F-7665-11AA-AA11-00306543ECAC /dev/disk2

Again, after Finder automounts the OSBoot and Media partitions, unmount them.

diskutil unmountDisk /dev/disk2

The final step is to write the EFI and Recovery images that you copied from the factory disk to the new disk.

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. To duplicate the factory disk, connect it to your computer and execute:

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:

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.

External Links

GUID Partition Table (GPT) details at Wikipedia [1]