Prepare a Hard Drive

From AwkwardTV

Jump to: navigation, search

Contents

Overview

atvDrive 1.1 <- greatly simplifies this process (Mac OS X only!)

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 - a small partition containing very basic information used by the Mac's EFI boot system to identify the drive and boot from it
  2. Recovery - contains an original factory-fresh version of what is copied into OSBoot during a Factory Restore
  3. OSBoot - the boot partition with the Mac OS version the ATV runs.
  4. 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 Simple Alternative Method below is indeed simpler, but can take several hours to complete.

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.

Your Options:

NameTypeModelCapacity Working
HitachiTravelstar 5K160HTS541680J9AT00160GB Yes
HitachiTravelstar 7K100HTS721080G9AT0080GBYes
HitachiTravelstar 7K60HTS726060M9AT00B60GBYes
SeagateMomentus 5400.3ST9120822A120GBYes
SeagateMomentus 7200.1ST96023A60GBYes
Western DigitalScorpioWD1200BEVE120GBYes
Western DigitalScorpioWD1600BEVE160GBYes
Western DigitalScorpioWD2500BEVE250GBYes
Western DigitalScorpioWD3200BEVE320GBYes ***
SamsungSpinPoint M5HM160HC160GBYes
SamsungSpinPoint M5HM121HC120GBYes
SamsungSpinPoint M60HM120JC120GBYes
SamsungSpinPoint M80HM080HC80GBYes
SamsungSpinPoint M80HM160JC160GBYes ***
FujitsuMHV2MHV2080AH80GBYes
FujitsuMHT2MHT2040AH40GBYes
FujitsuMHW2MHW2040AT40GBYes


*** HM160JC & WD3200BEVE (and with some others drives when no Factory Restore possible)

With Mac OS X 10.5 and about the Media partition, you have to concluded with this command after the whole process:

sudo diskutil unmountDisk /dev/disk2
newfs_hfs -J -v Media /dev/disk2s4

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:

sudo diskutil unmountDisk /dev/disk2
sudo dd if=/dev/disk2s1 of=efi.dmg bs=1m
sudo dd if=/dev/disk2s2 of=recovery.dmg bs=1m
sudo dd if=/dev/disk2s3 of=OSBoot.dmg bs=1m (optional, see below)

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.

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:

/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

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.

sudo dd if=/dev/disk0s1 of=/Users/frontrow/Documents/efi.dmg bs=1m
sudo 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.

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

If you prefer to make the copies from your desktop (e.g., you desktop ssh is secured by public key login only), you can execute these commands in a terminal window on your desktop:

scp frontrow@AppleTv.local:Documents/efi.dmg .
scp frontrow@AppleTv.local:Documents/recovery.dmg .

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

hdiutil convert /Volumes/Recovery/OS.dmg -format UDRW -o ~/Desktop/OSrw.dmg
hdiutil attach ~/Desktop/OSrw.dmg

Make whatever modifications you want here (add ssh, add plugins etc...)

once you are done with your modifications

#make sure nothing is broken on the OS.dmg, might want to back it up first

#rm /Volumes/Recovery/OS.dmg
hdiutil convert OSrw.dmg -format UDZO -o /Volumes/OS.dmg
asr -imagescan /Volumes/OS.dmg

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.

A manual update requires the following steps:

1. boot to recovery (menu and -)
2. ssh -1 frontrow@appletv.local
3. (from ssh) diskutil mountDisk /dev/disk0

      • 4. (from computer) scp -r -1 ~/Documents/Updates frontrow@appletv.local:/Volumes/Media

5. (from ssh) cd /Volumes/Media/Updates
6. (from ssh) chmod +x hdmiutil IRReceiverUpdaterTool2
7. (from ssh) ./hdmiutil -m63 -puppetstrings *.sihex
8. (from ssh) ./IRReceiverUpdaterTool2 -progress *.irrxfw
9. (from ssh) sudo asr restore --source final.dmg --target /dev/disk0s3 --erase --noprompt
10 (from ssh) diskutil unmountDisk /dev/disk0
11. (from ssh) sudo reboot


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)
SEEDSCRATCH="/SeedScratch"

if [ $BOOTTYPE == "redirected" ]; then
	SCRATCH="/dev/disk0s4"
fi
mount -ur /

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)

To resize OSBoot the steps below would have to be modified

diskutil unmountDisk /dev/disk2
sudo gpt add -b 888872 -i 3 -s 1843200 -t hfs /dev/disk2

-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

more info here: http://developer.apple.com/mac/library/technotes/tn2006/tn2166.html

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.

diskutil unmountDisk /dev/disk2
sudo gpt destroy /dev/disk2
sudo gpt create /dev/disk2

Mac OS X 10.5.x*

Add the partitions

The partitions have to be added in order otherwise diskutil gets confused.

First, add the EFI partition:

diskutil unmountDisk /dev/disk2
sudo gpt add -b 40 -i 1 -s 69632 -t efi /dev/disk2

Now add the Recovery partition:

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


Next add the OSBoot partition.

diskutil unmountDisk /dev/disk2
sudo gpt add -b 888872 -i 3 -s 1843200 -t hfs /dev/disk2

Now we can determine the size of the Media partition.

diskutil unmountDisk /dev/disk2
sudo 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          6
         40      69632      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
      69672     819200      2  GPT part - 5265636F-7665-11AA-AA11-00306543ECAC
     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 numbers from your output as in the example of the two numbers above:

diskutil unmountDisk /dev/disk2
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.


*** HM160JC & WD3200BEVE (and with some others drives when no Factory Restore possible)

With Mac OS X 10.5 and about the Media partition, you have to concluded with this command after the whole process:

sudo diskutil unmountDisk /dev/disk2
newfs_hfs -J -v Media /dev/disk2s4

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 !

Update Partitions

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

sudo dd if=efi.dmg of=/dev/disk2s1 bs=1m
sudo dd if=recovery.dmg of=/dev/disk2s2 bs=1m
sudo dd if=OSBoot.dmg of=/dev/disk2s3 bs=1m (optional)

With the optional restoration of the OSBoot partition, the factory reset is not required.

Mac OS X 10.4.x*

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.

sudo gpt add -b 888872 -i 3 -s 1843200 -t hfs /dev/disk2

Now we can determine the size of the Media partition.

diskutil unmountDisk /dev/disk2
sudo 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 numbers from your output as in the example of the two numbers above:

diskutil unmountDisk /dev/disk2
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:

diskutil unmountDisk /dev/disk2
sudo 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:

diskutil unmountDisk /dev/disk2
sudo 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

Update Partitions

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

sudo dd if=efi.dmg of=/dev/disk2s1 bs=1m
sudo 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.

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:

gpt destroy /dev/da0
gpt create /dev/da0
gpt add -b 40 -i 1 -s 69632 -t efi /dev/da0
gpt add -b 69672 -i 2 -s 819200 -t 5265636F-7665-11AA-AA11-00306543ECAC /dev/da0
gpt add -b 888872 -i 3 -s 1843200 -t hfs /dev/da0

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.

dd if=/dev/ad0 of=/dev/ad2 bs=4m

Remove the Media partition:

gpt remove i=4 /dev/ad2

List the available size for the new media partition:

gpt show /dev/ad2

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          6
         40      69632      1  GPT part - EFI
      69672     819192      2  GPT part - 5265636F-7665-11AA-AA11-00306543ECAC
     888824    1843192      3  GPT part - Apple - HFS
    2732016  153569383         
  156301455         32         Sec GPT table
  156301487          1         Sec GPT header

The important part is the line above Sec GPT table:

    2732016  153569383         

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.

External Links

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

Personal tools