Thinking until the 2147483648'th second

About This

James Long
I think all of the files I linked to in some of my older posts are gone now. I am working on fixing them.
View my complete profile

Tuesday, February 19, 2008

Re-creating the Apple TV harddrive from Scratch

Phew. For a second there I didn't think my AppleTV was going to make it.

I bought an ATV a few months ago and hacked it pretty seriously. At that point, I was trying to run the full Tiger version of OS X on it. I impatiently wiped the whole hard drive without backing up the recovery partition. Eventually, I decided I wanted to use ATV's interface, and I struggled a bit to get ATV re-installed without a Factory Restore. I finally got it working though, so I knew it *was* possible to get the ATV back up and running from scratch with *only* the OS.dmg from mesu.apple.com.

You see, Apple released a big ATV update (from v1.1 to v2.0) just last week. You can rent HD movies with this update - which is awesome (albeit a little overpriced). I really wanted this update, but I couldn't do it the convenient way because my ATV was hacked. I tried the Safe Update but the DRM's are screwed up so you can't rent anything. I decided that it would be best to do a Factory Restore (manually, mind you) and let it update itself.

Easy, right? I did it once before, so it should be a piece of cake, right? Psh, like I can remember the nuances of disk images and partitions after months of not working with the stuff. I ended up wasting three nights trying to remember the exact layout of partitions and the precise format of system data that AppleTV requires. The thing that is so frustrating is that it is *not that hard* and should have only taken me an hour - but dammit, the thing is picky.

I never want to forget this again, so I'm documenting it here. So, you have a blank hard drive, and you want it to use it for the Apple TV? Get the OS.dmg from any torrent site, make sure your drive is physically compatible, then follow these steps *precisely*. Assuming /dev/disk1 is your disk.

(A quick note: Awkward TV's tutorial was a big help, but I had problems with a few of its instructions, specially the ones using diskutil to format the disk)

1. Connect your hard drive to a Macbook using an IDE-to-usb/firewire dongle.

2. Clear any partition information and create a new partition table:
gpt destroy /dev/disk1
gpt create /dev/disk1
3. Create the partitions using 'gpt'. There should be four partitions: EFI (200m), Recovery (400m), OSBoot (900m), Media (rest of the disk). The EFI and Recovery partitions can be completely blank, but those sizes must be exact.

Assuming, /dev/disk1 is your disk:
gpt add -b 40 -i 1 -s 409600 -t efi /dev/disk1
gpt add -b 409640 -i 2 -s 819200
-t 5265636F-7665-11AA-AA11-00306543ECAC /dev/disk1
gpt add -b 1228840 -i 3 -s 1843200 -t hfs /dev/disk1
gpt add -b 3072040 -i 4 -s *size* -t hfs /dev/disk1
You'll have to unmount the drive after every gpt command because OS X likes to automount drives.

4. Create the filesystems.
newfs_hfs /dev/disk1s2
newfs_hfs -J -v OSBoot /dev/disk1s3
newfs_hfs -J -v Media /dev/disk1s4
5. Remount the drives with ownerships enabled.
diskutil unmountDisk /dev/disk1
mount -t hfs /dev/disk1s3 /Volumes/OSBoot
mount -t hfs /dev/disk1s4 /Volumes/Media
6. Restore the system. You can use the command 'asr', but at this point it's easier to use disk utility, click on OSBoot, and restore OS.dmg to it. I also did 'Scan Image For Restory' under Images for safety before I restored it. This took me a while to trackdown; initially I just rsync'ed the files. Evidently the restore preserves something that it needs (the window server would just crash on me).

7. Depending on how you dumped the image into OSBoot, this may be needed. If you used Disk Utility, this is unneeded.
sudo bless --folder=/Volumes/OSBoot/System/Library/CoreServices
--file=/Volumes/OSBoot/System/Library/CoreServices/boot.efi --setBoot
There you are. You should be able to unmount the drive, stick in in your AppleTV and boot right up. I found the tools mentioned above *much* more reliable than Disk Utility (and its CLI equivalent diskutil). diskutil would screw up my partitions - randomly resize them, etc. which was a big pain.

Update: It seems that the bless command is unneeded, if using Disk Utility's restore at least. Note that you can also use the new ATV2 OS.dmg found here. (The next thing to do is to get the recovery partition back in order. I tried a few different set ups and couldn't get it working.)

Update #2: If you are doing this to upgrade to ATV2, make sure you also update your HDMI/DVI controller. This is something it would do automatically. You can see the controller update here:

http://mesu.apple.com/version.xml

Download the installer (called 'hdmiutil') and the update file, copy to your ATV, ssh in and run the update like so:
$ ./hdmiutil FW29050_20080205_dse_hex.sihex
You should get this message:
hdmiutil - HDMI Flash Utility Version 1.1000 (Mac)
For Programming Silicon Image's SiI1930 (DVI-HDMI) microcontroller.
Copyright (C) 2006-2008, NVIDIA Corporation. All Rights Reserved.
Using default I2C configuration on Mac platform.
Temporarily disabling hotplug interrupt processing...
Firmware Filename: FW29050_20080205_dse_hex.sihex

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! Do not interrupt power or hotplug displays during flashing process. !!!
!!! This might take a while to complete (approx 5 min for each file) !!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Sector Erase 0%........10%.......20%........30%.......40%........50%.......60%........70%.......80%........90%......100%

Programming 0%..........10%..........20%..........30%..........40%..........50%..........60%..... (goes till 100%)

OK - file FW29050_20080205_dse_hex.sihex firmware flashed successfully!
Re-enabling hotplug interrupt processing...
This will fix issues with playing HD over your HDMI/DVI cable (such as HDCP).

Update #3: Fixed a few typos, filled out the start positions for the partitions, and a few other minor updates. Glad you guys found this useful.

33 comments:

Anonymous said...

Excellent post. I used some of your stuff to upgrade the hard drive of my Apple TV, today! Well done, (and thanks)!

Anonymous said...

There is one downside with this approach. It will take a long time to restore the OSBoot partition via Wifi due to the size oft he OSBoot dmg.

Personally, I would have just restored the Recovery Partition. (If you do not have a dmg of the recovery partition, you can find version 1.0 on the Torrents).

Then bless and reboot. When the AppleTV reboots, it will see that something is wrong and should do a factory restore based (using the Recovery Partition). It should then create the OSBoot partition and the Media Partition.

Then use iTunes to upgrade to version 2.0..

James Long, code expander said...

Restoring OSBoot doesn't take that long if you have the hard drive connected through a IDE-to-USB or firewire adaptor. It took me about 2 minutes to restore it.

Restoring the recovery partition would be the best method though. It would be best to get the ATV as close as possible to when it was new; doing a real update has its advantages also (see my update at the end of the post).

My problem was that I tried restoring the recovery partition but I could only get it to boot to an ATV logo with a blinking question mark. I may have blessed it wrong or something.

Gaurav said...

Have you figured out how to create the recovery partition, thats crucial for factory restore and upgrade

Anonymous said...

Great work. Well done. Bravo. Kudos. You really saved me.

Anonymous said...

Thank you VERY much. You saved my crippled AppleTV!

Abdullah said...

thank you very much for this post, I thought I lost my apple tv for good.
however I always fail to do step 3, I could do the first step in 3 but the second one of the 3rd step it tells me that I don't have enough space?
could you please help me out ?

Tim said...

Thanks! Probably one of the easiest and least time consuming guides out there, not to mention that none of the guides were working for my ATV2...

Tim said...

Also, if you're still not able to get the recovery partition working, I tried dd'ing and image from the recovery partition from my original backup of the stock ATV drive and then dd'ing that image to the upgraded ATV drive. Seems to be working perfectly.

James Long, code expander said...

@tim - That's the catch though, I don't have a backup of the original ATV hard drive. Would you mind hosting the image for me? I would extremely grateful - email me at longster at gmail.com if you do.

@abdullah - Make sure you are using the correct block start parameter. For the second parition, it should be something like 409670. So the whole second to create the second partition would be:

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

If that doesn't work, something is seriously wrong with your hard drive.

jc said...

Nice posting, but I can't seem to get step 5 to work. I can "unmount" the new drive successfully, but the rest of the steps, I can't get the disk to mount again per the posted command lines.

Thanks in advance for the help!

asdp38 said...

nice post, now my appletv works fine.

But I have a problem, when I try to do update from th Appletv TV, it is not working at all.

It is downloading the version, and ask me if I want to update now, I click on Yes

The Atv, restart and after the boot, I have the apple tv logo with a "?"

It is compulsary for me to disconnect the cable power.

Afeter that it is ok but with 1.0 version.

Do you have any idear in order to have 1,1 or 2,0 version.

Thakns for you help (past and future)

Asdp38

stak said...

Thanks for the post. Btw, the *start* sizes are as follows: 40, 409640, 1228840, 3072040. Unfortunately I think my ATV is beyond saving now :(

iMaajka said...

Can you please explain this part:
"Fill in *start* by running 'gpt show /dev/disk1' after every add and using the next available sector. The last *size* is the size that will fill up the rest of the disk of course. You'll have to unmount the drive after every gpt command because OS X likes to automount drives."

I'm confused what to exactly do here...

thanks!

Rog said...

Can this rebuild be done on MAC OS X Leopard. I understand that you can only do it in TIGER which I DO NOT HAVE. I have a totally FUBAR ATV from a patchstick install and now I have a paper weight

Thanks

Anonymous said...

Can you perform this restore by connecting the ATV to a Macbook via USB-to-USB without removing the HDD from the case?

Armz said...

Great post, everything is working except the last part. I don't see hdmiupdate in http://mesu.apple.com/version.xml there is only hdmiutil. I tried to copy hdmiutil and FW29050_20080205_dse_hex.sihex but still doesn't work. The terminal say 'command not found'.

Any idea?

James Long, code expander said...

@armz - you are right, the command is `hdmiutil' not `hdmiupdate'. This has been fixed.

When you download the command and the supporting file, make sure they are in the same directory. Then make sure to the following exactly, and it should work (you probably forgot the preceding './' when calling it):

$ chmod +x hdmiutil
$ ./hdmiutil FW29050_20080205_dse_hex.sihex

Jesuz said...

Don't forget to chmod FW29050_20080205_dse_hex.sihex also

maze said...

thanks dude, you made my day. now i can use my ipod as a remote!

Jonas said...

Great work. I followed the guide, it bootet, and everything worked fine. But I cant update the software?? In iTunes it just shows up with version 1.0 and no option to update. In the ATV-menu I can choose updates, it finds an update, downloads and ask if I want to install it. I choose install now, the ATV restarts. But the version is still 1.0. Why?

Btw: I have an ATV2 and restored the 1.0 software to the OSBoot partition in the process described.

Thanks!

Anonymous said...

Very Good Post!!! So how do you recover your hard drive if you dont have a Macbook or an apple computer and you need to rely on Linux and Windows tools. Is there a way to do so?

James Long, code expander said...

@jonas & anonymous:

I had the same problem with my software update. I fixed it by using linux to create the partitions instead. I think OS X is trying to do a little magic with the hard drive, and messes it up. I had several unsuccessful attempts at fixing my factory restore using OS X, but when I used linux it worked the first time.

Use the `parted' program in linux, and you can follow this post's steps more or less.

Juan C. said...

Thank you! Excellent post.
@jonas - I think I had the same 1.0/2.0 version issue you describe. I documented my fix at http://8020world.com/jcmendez/2009/01/geeky-stuff/how-to-fix-an-upsized-apple-tv-stuck-in-10-software/

Hope it helps you as well

Zeus said...

Great article.
@Rog I was able to do this in Leopard.
@JD I had issues mounting the drives again. All I did was unplug the ATV drive from the computer and plugged it back in, it showed up correctly in Disk Utility.

maze said...

i srsly need hekp :-/
i followed your guide to the point. my apple tv boots up, i see the apple logo and then i'll get forwareded to the language selection. but i can't select anything. my remote does work (i can reboot) but i can't select anything. what has gone wrong here? please help! thanks in advance!

Anthony said...
This post has been removed by the author.
Anthony said...

Same deal as Maze. Updated an ATV2 (2.0.2 on recovery partition) to 2.3. After recovery, on reboot, the unit flashes at apple logo and the seems to freeze at the Language selection.
Cant use the remote to set the language or proceed but can access the unit via ssh.

Juan C. said...

@maze, @anthony - without having a way to test, my guess is that when you upgrade 2.0x->2.3 the filesystem in the root partition is not fully erased, just some files are replaced, and some drivers for the remote could have been left in a wrong state. In your shoes, I would try taking the HD out, connect to a computer, replace the OS.dmg in the recovery partition and doing a full restore (remote should allow that)

fine thin hair said...

black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines

afordable beach resorts in the philippineshomeopathy for eczema.baby eczema.save big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here

night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest pricefind air beds in wisconsinbest air beds in wisconsincloud air beds

best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsbed air informercialsbest informercials bed airmattress sized air beds

bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestadjustable bed air foam The best bed air foam

hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds

migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicantdessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas

vero beach vacationvero beach vacationsbeach vacation homes veroms beach vacationsms beach vacationms beach condosmaui beach vacationmaui beach vacationsmaui beach clubbeach vacationsyour beach vacationscheap beach vacations

bob hairstylebob haircutsbob layeredpob hairstylebobbedclassic bobCare for Curly HairTips for Curly Haircurly hair12r 22.5 best pricetires truck bustires 12r 22.5

washington new housenew house houstonnew house san antonionew house venturanew houston house houston house txstains removal dyestains removal clothesstains removalteeth whiteningteeth whiteningbright teeth

jennifer grey nosejennifer nose jobscalebrities nose jobsWomen with Big NosesWomen hairstylesBig Nose Women, hairstyles

Flerkin McBlerkin said...

Wow, how's that last comment get through moderation?
Sunroom

Anonymous said...

Hi! I just hooked my ATV HD with USB to my iMac but Diskutility only shows the OS Boot and Media partitions... Can i repartition the HD also with diskutility or do I have to dive into the Terminal?
I assume Terminal is the tool you use to execute those commands..??

Anonymous said...

Ok, this worked for me to solve the language selection issue: restart the Apple TV with your remote, and while it is restarting continue to hold the menu button on your remote.
Then when you see the language menu appear you can let go and scroll up and down.
Let's hope this works for everyone else as well!!

Random Notes

I work at Coptix

Ideas / To-do

  • Research .Mac style photo gallery for screenshots