My favorites | Sign in
Project Logo
             
Search
for
Updated Jul 15, 2008 by sdavilla
ATVBackup  

Backup and Restore

Note: This requires "recovery-0.6.tar.gz" or greater. The previous versions do not contain all the required command-line tools.

You have bought an AppleTV and want to alter the original internal PATA disk. To be able to restore the original contents, you need to make a backup. This is highly recommended and does not take much storage space. The AppleTV comes into two flavors, a 40GB version and a 160GB version. This method works with either and takes the same amount of storage space and time to perform.

What we do is take advantage of the self-restoring capability that is already built into the AppleTV EFI fireware. If we properly create the first three partitions (EFI, Recovery and OSBoot) and populate "Recovery", the AppleTV EFI firmware will go into a recovery boot. Then select "Factory Restore" and it will rebuild/populate the "OSBoot" and "Media" partitions.

Warning You might use "dd" to copy the entire disk but that's a waste of time and storage space and "dd" is not the correct tool to copy GPT format disks. Usage of dd to copy the entire disk is fortuitous, it might work, but CAN fail under certain conditions and is therefore unreliable. Proper GPT format includes a secondary partition map in the ending sectors on the disk. If these sectors do not exist because your destination disk is smaller than your source disk, it will not be present after using "dd". Failure to include the secondary partition map or failure to place it in the proper location will lead to unreliable results. Using "dd" for USB pen drives further flawed by inconstancies in flash based disk geometry. Even for non-GPT format, the use of "dd" can lead to unreliable results when used to image a USB flash based pen drive.

Backup

Let's get started, first build atv-bootloader on a USB pen disk with telnet support. You will need a USB flash drive of 512MB or greater. Flash drives of this size are dirt cheap and I recommend buying one specific for this purpose. In addition to the "Recovery" partition that atv-bootloader uses, make a second partition called "backup" that is equal to or greater than 256MB in size. Make this partition "ext3" so the AppleTV EFI firmware ignores it.

This is the USB flash drive created in atv-bootloader on a USB pen disk

parted -s /dev/sdb unit s print

Model: SanDisk Cruzer Micro (scsi)
Disk /dev/sdb: 501759s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End      Size     File system  Name     Flags  
 1      40s     69671s   69632s   hfs+         primary  atvrecv

Add the ext3 partition The ending sector is the max sectors - 34 sectors (501759s - 34s = 501725s)

sudo parted -s /dev/sdb mkpart primary ext3 69672s 501725s

# check it
parted -s /dev/sdb unit s print
Model: SanDisk Cruzer Micro (scsi)
Disk /dev/sdb: 501759s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End      Size     File system  Name     Flags  
 1      40s     69671s   69632s   hfs+         primary  atvrecv
 2      69672s  501725s  432053s               primary         

# sync the system disk partition tables
sudo partprobe /dev/sdb

# format this partition ext3
sudo mkfs.ext3 /dev/sdb2

Boot the AppleTV using this USB flash drive and telnet in. Username is "root", password is "root". Nothing is mounted so make two mount points and mount the second partition of the USB flash drive on one and the "Recovery" partition on the internal PATA disk on the other. Clone the contents of "Recovery" to our backup partition. You don't have to copy the contents of "EFI" as there is nothing to copy. That correct, "EFI" is empty. Note that we fsck.hfsplus the "Recovery" partition even though it will be mounted read only.

mkdir src dst

# mount the destination, we don't need to fsck as this is an ext3 partition
mount /dev/sdb2 dst

# mount the source
fsck.hfsplus /dev/sda2
mount -t hfsplus  /dev/sda2 src

cp -arp src/* dst/
# force a disk buffer flush
sync

umount src dst
# clean up by removing the mount points
rmdir src dst

Run "parted" and make a copy of the original partitioning for the internal PATA disk. If we alter the original partitioning, the internal PATA disk can be re-partitioned back to the original later using this copy as a guide. Copy this to the first partition of the USB flash drive for safe keeping.

mkdir tmp

# mount 
fsck.hfsplus /dev/sdb1
mount /dev/sdb1 tmp

parted -s /dev/sda unit s print > tmp/org_gtp.txt

Check the file using "cat tmp/org_gtp.txt", for a 40GB disk it should look something like this.

Model: FUJITSU  K00FT7125M1W (scsi)
Disk /dev/sda: 78140160s
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start     End        Size       File system  Name      Flags  
 1      40s       69671s     69632s     fat32        EFI       boot   
 2      69672s    888823s    819152s    hfs+         Recovery  atvrecv
 3      888824s   2732015s   1843192s   hfs+         OSBoot           
 4      2732016s  77878015s  75146000s  hfs+         Media            
umount tmp
# clean up by removing the mount points
rmdir tmp

Remove the USB flash drive and store it in a safe place. If you want, you can also tar and gzip the contents of the "backup" partition on the USB flash drive to another location. That was quick and painless.

For a 160GB disk, the end result will look something like this

# parted -s /dev/sda unit s print
Model: ATA SAMSUNG HM160JC (scsi)
Disk /dev/sda: 312581808s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start     End         Size        File system  Name Flags
 1      40s       69671s      69632s      fat32        primary boot
 2      69672s    888823s     819152s     hfs+         primary atvrecv
 3      888824s   2732015s    1843192s    hfs+ primary
 4      2732016s  312319663s  309587648s  hfs+ primary

Restore

Boot the AppleTV using the same USB flash drive and telnet in. Again nothing is mounted. Mount the first partition of the USB flash drive and copy over the dump of the original partitioning.

mkdir tmp

# mount
fsck.hfsplus /dev/sdb1
mount /dev/sdb1 tmp

cp tmp/org_gtp.txt ./

umount tmp
rmdir tmp

Wipe the partition structure of the internal PATA disk. Make sure you have the correct disk/partition or bad things will happen

dd if=/dev/zero of=/dev/sda bs=4096 count=1M

Using the contents of "org_gtp.txt" and "parted", re-create the original partitioning. I create and format all four partitions. Remember "OSBoot" and "Media" are formatted hfsplus journaled but "Recovery" is not.

# create the GPT format
parted -s /dev/sda mklabel gpt

# 1-EFI
parted -s /dev/sda mkpart primary fat32 40s 69671s
parted -s /dev/sda set 1 boot on

# 2-Recovery
parted -s /dev/sda mkpart primary HFS 69672s 888823s
parted -s /dev/sda set 2 atvrecv on

# 3-OSBoot
parted -s /dev/sda mkpart primary HFS 888824s 2732015s

# 4-Media
parted -s /dev/sda mkpart primary HFS 2732016s 77878015s

# make file systems for the four partitions
mkfs.msdos -F 32 -n EFI /dev/sda1
mkfs.hfsplus -v Recovery /dev/sda2
mkfs.hfsplus -J -v OSBoot /dev/sda3
mkfs.hfsplus -J -v Media /dev/sda4


# use partprobe to re-sync the new partitions to the system partition tables
partprobe /dev/sda

Mount and copy the original contents of "Recovery" from your "backup" partition into the newly created "Recovery" partition.

mkdir src dst

# mount the backup
mount /dev/sdb2 src

fsck.hfsplus -f /dev/sda2
mount -t hfsplus -o rw,force /dev/sda2 dst

cp -arp src/* dst/
# force a disk buffer flush
sync

umount src dst
# clean up by removing the mount points
rmdir src dst

Remove the USB flash drive and power cycle the AppleTV. It will see that contents of "OSBoot" is missing and go into a recovery boot. Select "Factory Restore" and the AppleTV EFI firmware will do the rest. It might do several reboots as it reconfigures itself.

When it finally comes up, presto, a factory fresh AppleTV.

Opps I did not make a backup

Update - April 29, 2008 - Apple seems to have purged their previous updates. The following are now missing from mesu.apple.com. This means that one will no longer be able to recover back to the 1.x series. Bummer. I've not tested this procedure with the 2.0.2 dmg update but it seems like it should work. I'll test it when I get a chance. You might run into issues if your AppleTV was at the original EFI firmware as the 2.0.x series will expect the updated EFI firmware that occurred during the 1.0.x to 2.0.x updates.

1.0.1 - at http://mesu.apple.com/data/OS/061-2988.20070620.bHy75/2Z694-5248-45.dmg
2.0.0 - at http://mesu.apple.com/data/OS/061-3561.20080212.ScoH6/2Z694-5274-109.dmg
2.0.1 - at http://mesu.apple.com/data/OS/061-4375.20080328.gt5er/2Z694-5387-25.dmg

Still present is the current 2.0.2 update.

2.0.2 - at http://mesu.apple.com/data/OS/061-4632.2080414.gt5rW/2Z694-5428-3.dmg

So you messed up and did bad things to the internal PATA disk without making a backup. All is not lost. You can save the day by using the AppleTV 2.0.2 update to re-create the AppleTV disk. Do this step on a working Linux box, the proceed to the "Restore" section above.

Start by downloading the update, converting it and mouting. Do this on a working Linux system or LiveCD. We going to use same methods as in extract "boot.efi" so see that section if you need to build dmg2img.

# download the AppleTV 2.0.2 update
wget http://mesu.apple.com/data/OS/061-4632.2080414.gt5rW/2Z694-5428-3.dmg
#
# convert it to an img format
dmg2img 2Z694-5428-3.dmg atv.img

# create a mount point
mkdir atv-update

# mount the converted dmg disk image
sudo mount -o loop -t hfsplus atv.img atv-update

The AppleTV "Recovery" partition has the following files. The byte count of your "mach_kernel.prelink" and "OS.dmg" might be different, this is from an AppleTV rev 1.0. Note that "Desktop DB" and "Desktop DF" will be created by the AppleTV during recovery mode and do not need to be manually created.

-rw-r--r-- 1 root root     45590 Feb 16  2007 BootLogo.png
-rw-r--r-- 1 root   80      1024 Mar 15  2007 Desktop DB
-rw-r--r-- 1 root   80         2 Mar 15  2007 Desktop DF
-rw-rw-r-- 1 root   80 207475830 Mar 15  2007 OS.dmg
-rw-r--r-- 1 root root    298800 Feb 16  2007 boot.efi
-rw-r--r-- 1 root   80       520 Mar 15  2007 com.apple.Boot.plist
-rw-r--r-- 1 root root   6306364 Mar 15  2007 mach_kernel.prelink

Create a directory called "staging" and copy a few items from the update.

mkdir staging

cp -arp atv-update/mach_kernel.prelink staging/
cp -arp atv-update/System/Library/CoreServices/boot.efi staging/
cp -arp atv-update/System/Library/CoreServices/BootLogo.png staging/
cp -arp atv-update/System/Library/CoreServices/com.apple.Boot.plist staging/

Copy 2Z694-5428-3.dmg into your staging directory as OS.dmg. That's correct, the update becomes the "OS.dmg" image that the AppleTV EFI firmware will use to create the contents of "OSBoot".

cp -arp 2Z694-5428-3.dmg staging/OS.dmg

Edit "staging/com.apple.Boot.plist" and change it to look just like this. You will be changing "Boot Logo" and "Kernel Flags" strings.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Background Color</key>
        <integer>0</integer>
        <key>Boot Fail Logo</key>
        <string></string>
        <key>Boot Logo</key>
        <string>BootLogo.png</string>
        <key>Kernel</key>
        <string>mach_kernel</string>
        <key>Kernel Cache</key>
        <string>mach_kernel.prelink</string>
        <key>Kernel Flags</key>
        <string>rp=file:///OS.dmg</string>
</dict>
</plist>

Clean up

sudo umount atv-update
rmdir atv-update

rm 2Z694-5428-3.dmg

Done, the contents of the directory "staging" can now be copied to the "backup" partition on your Linux USB pen rescue disk. Proceed to the Restore section above.


Comment by blazkristan, Oct 05, 2008
Comment by gaetanobattaglini, Nov 01, 2008

I have a problem. I followed all the indication but when I start Apple Tv after a while appares Apple logo and nothing else. You say: "Select "Factory Restore" and the AppleTV EFI firmware will do the rest. It might do several reboots as it reconfigures itself." I tryed many reboots but apple tv stop at the logo and is not possible to see the apple menu. I have ubuntu last distro. Thankds in advance for your help Gaetano

Comment by grant.thienemann, Dec 03, 2008

HAHAHAHA wow that worked perfectly!!!! I have been looking for a way to restore my AppleTV and this did it perfectly on the first try. I struggled because I never made a backup. Thank you so much

Comment by vmomin, Jan 01, 2009

How do you clone an AppleTV hardrive with all the modifications done to it to put on multiple AppleTV's?

Comment by sdavilla, Jan 01, 2009

cloning only works to AppleTVs with the same sized internal disks (ie. 40GB -> 40GB, not 40GB ->160GB)

boot atv-bootloader, remove the usb flash after booting, insert your pre-formated destination USB HD and mount it.

dd if=/dev/sda of=<some mount point>/atv.img bs=4096

restore is the opposite

dd if=<some mount point>/atv.img bs=4096

Comment by sdavilla, Jan 01, 2009

opps, last part should be

dd if=<some mount point>/atv.img of=/dev/sda bs=4096

Comment by paco.iglesias, Jan 12, 2009

anyone can give me a copy of an usb to recover a 160gb appletv

Comment by osmophilia, Jan 17, 2009

Hello and thanks for making this info available. I'm try to resurrect a of of warranty atv but seem to have hit a snag.... it seems that the Media partition is not mounting. If I issue a ls /Volumes/ only OSBoot is listed. Anyone have an idea why this would be? Otherwise the system seems functional, only it refuses to sync.

Comment by sean.rhodes, Feb 25, 2009

Quick side comment. Can you substitute the OS-dot-DMG 1.0.dmg (renamed to os.dmg)instead of the 2.1 or 2.2 image. That way the system can be resored with all the files that were removed from the OS in the subsequent updates?

Comment by sdavilla, Feb 25, 2009

yes, any appletv dmg can be used but the mach_kernel prelink must match that inside the dmg.

Comment by miguelmeza, Mar 25, 2009

I have a 40GB AppleTv? could you guys share your usb image so I can create it with the program. I dont have a mac or am able to do this please!! miguelmezaa?gmail.com pleaes!!!!! thank you!!

Comment by mikestaszel, Apr 16, 2009

Trying this guide tomorrow. My AppleTV HD killed itself and I'm out of warranty, so I'm restoring using the 2.0.2 DMG. Wish me luck!

Comment by ph7labs, Apr 28, 2009

is there a way to do this on leopard machine?

Comment by sdavilla, Apr 28, 2009

yes, convert the linux command into osx commands that do a similar operation. for example instead of parted use gpt.

the only thing you need to watch is OSX cannot mount a recovery partition so you must set the GUID to the standard HFS, mount it to add contents, unmount, then change the GUID to recovery.

and you need to watch the ownership/permissions of anything you copy over. 0:0 for root:wheel and 501:501 for frontrow:frontrow.

Comment by ph7labs, Apr 28, 2009

thanks sdavilla, but ouch... this sounds too advance for a non-programmer person, may end up having to pay a visit to genious bar... unless i can find watered-down steps on how to make this work.

Comment by chaosburn, May 20, 2009

I followed the instructios to rebuild from scrtach, but i only get a boot logo, what can be the issue? Thank you

Comment by chaosburn, May 20, 2009

Hi, I only want to thank you for your work (my apple tv is now ok!), I had been 2 weeks wasted on this (and I mean wasted cause the real issue was the IDE cable of the apple tv), and with your advices and ome patience i had done it.

THANK YOU

Comment by fpetrus, Oct 24, 2009

Hello.

I am having a problem similar to that described by gaetanobattaglini. The ATV only gets to the Apple Logo. I know the system cotinue booting in background cause I am able to access using SSH aferwards but the screen keeps with the logo. I tried ALL I could imagine and I read about this. I even tried recovering the whole HD with dd command and a disk image. Same. I also tried above steps with latest Apple TV OS image. Same.

Digging into the logs I found below error, any idea what could be the cause of this? Also, is there anything that could be failing (not besides hardware)? I know too little about EFI, is there a firmware that could got damanged? how can I recover it?

Thanks a lot for any assistance you can provide on this.

-- Federico

This is the error I found after ATV boot:

NVChannel(GL): Graphics channel exception! status = 0xffff info32 = 0x6 NVChannel(GL): Graphics channel exception! status = 0xffff info32 = 0x6 NVChannel(GL): Graphics channel timeout! NVChannel(GL): Graphics channel timeout! NVChannel(GL): Graphics channel error! Unable to recover!!! NVChannel(GL): Graphics channel timeout!

Comment by sdavilla, Oct 24, 2009

not an EFI problem, most likely your setup of the disk was incorrect somehow. Need more info on exactly what you did broken down into steps.

Comment by fpetrus, Nov 02, 2009

Thanks for your prompt response. Last thing I tried before that problem started was, using NitoTV, to roll-back to the ATV 2.4 image (maybe not a clever idea).

But since them I try a thousand different things. Latest was downloading an image if a working harddrive and overwrite mine using dd. Image recovery was correct, but the ATV boot up until the same point, frozen Apple picture in the screen and the operation system fully booting in the background.

Do you think this could be an actual hardware issue?

Is there any firmware (real firmware not the ATV image from Apple) in the ATV that I can upgrade? If I donwload the latest 2.5 image, is there a way to apply that using a command line command?

Thanks a lot in advance.

Comment by sdavilla, Nov 02, 2009

If you are confident that the disk image you have dd onto the disk is good, then it's dead. I never, ever use dd to recreate the internal disk, the procedure depends on both disks being the exact same in size (block sizes, not disk size).

There is firmware but you need a working atv to apply. If you have a working disk, you might give atvclone a try.

Comment by fpetrus, Nov 02, 2009

My ATV only has issues with the video, but OS is working in background, how can I upgrade the firmware? what is atvclone?

Comment by sdavilla, Nov 02, 2009

google works wonders -> http://dynaflashtech.net/

Trying to fix the problem by doing a firmware update is futile, you don't know it that's the problem and are guessing that it will fix it. Work the problem.

Comment by zerosix, Nov 07, 2009

i'm a little confused with the recovery without a backup procedure. I've got the recovery patchstick made, but it seems the size of partition is too small to hold anything from the "staging" directory. whenever i try to make the partition bigger, it will not boot.

Am i missing something?

Comment by sdavilla, Nov 07, 2009

I'm a little confused as to what you are trying to do. The partition the patchstick boot from is not designed to "hold" anything, the second partition of the patchstick is designed to hold payloads. Payloads are copied to the OSBoot or Media partition of the AppleTV.

What are you really trying to do?

Comment by yrojjory, Nov 08, 2009

I have two Apple TVs, one I bought with OS 1.1 and the other came with OS 2.2. After v3 has annoyed me to no end, I've been wanting to downgrade. However, I managed to make my 2.2 ATV endlessly reboot as a result of copying the Recovery partition from my 1.1 device over. After 5 hours of troubleshooting, I discovered that there's a reason for this: not all ATVs are equal! The mach_kernel.prelink is different between the two machines, so be sure you back up your Recovery partition or you may not be able to restore your ATV to Factory Defaults!

Comment by yrojjory, Nov 08, 2009

Incidentally, I also found that the newer ATV could not be downgraded to 1.x. It continually crashed the unit when trying to boot.

Comment by yrojjory, Nov 08, 2009

One more note: The 2.2 OS ATV was unable to work properly with the 2.4 OS in its Recovery partition, too. So you'd better follow the directions well and back up your original Recovery partition!!!

Comment by tylerbook, Nov 08, 2009

sdavilla:

My ATV HD is hosed. I am trying to recreate it. I have an update DMG that I want to use as my Recovery partition. When going through your processes, I do not see where a second partition is created. I see where we create the penboot, which serves as the bootable USB drive. Where do we use the remaining disk space on the USB drive? Further, I have my staging directory created verbatim to your steps, but I guess I am confused on where it goes. You say to put it on the "backup" partition of the USB drive, but according to the steps, we only make one partition called "Recovery"

Comment by sdavilla, Nov 08, 2009

see the "Backup" section above, you make a second partition there.

Comment by tylerbook, Nov 08, 2009

I see--- the instructions were a little fuzzy on that. it seemed like i wanted to bypass the backup section all together. i'll give it another go.

Comment by SchneiderIS.Peter, Nov 16, 2009

I am trying to restore and am using the "Oops" method. The image that I managed to download from Apple is for version 2.4 but when I reboot it gets to the language selection and then won't allow me to go any further. Originally this box was installed with an early version 2 of Apple TV and I read about the controller patch Apple did in order to allow other remotes. My thinking is that this is now causing me a conflict. I have ben trying to find a 2.2 version to test my theory but for the moment it appears that Apple has removed all available downloads. Does anyone have any experience or thoughts on this? For now this is keeping me from being able to properly restore the ATV.

There is another question that I have. Alternatively I get this back to a MythTV box but for some reason I keep failing Patchstick.sh on a OSBoot/mnt not existing. think this is because my OSBoot doesn't exist anymore so my thinking is that if I take the "Oops" backup and also copy it to the OSBoot folder I might have some success. At this point I am grasping for straws though.

Comment by SchneiderIS.Peter, Nov 16, 2009

Correction to my last post. The Patchstick error is:

error mounting OSBoot partition

Any help would be greatly appreciated.

Comment by sdavilla, Nov 17, 2009

can you do a "Factory restore" or is your internal disk gone?

Comment by acsulliv, Nov 19 (6 days ago)

I know this an extremely newbie question, but how do I copy the contents of the directory "staging" to the "backup" partition on my Linux USB pen rescue disk. I've created the backup partition and when I check it, everything looks exactly as it does above. i use the "mkdir src dst" command, then the "mount /dev/sdb2 dst" command, so I'm assuming the backup partition is mounted. I have all of the necessary files in the "staging" directory (currently located at home/dmg2img/staging). I just cannot for the life of me figure out how to get these onto the backup partition. Thanks ahead of time for any help!


Sign in to add a comment
Hosted by Google Code