Difference between revisions of "Backup your original Hard Drive"

From AwkwardTV
Jump to: navigation, search
(Phoem's Fast DD Method (OS X))
m (Reverted edits by LizaCaddy (Talk) to last revision by Fcorthay)
 
(90 intermediate revisions by 21 users not shown)
Line 1: Line 1:
[http://www.engadget.com/2007/03/23/how-to-upgrade-the-drive-in-your-apple-tv/ The Phoem method may be superseded by Engagets.] '''Please consider doing a complete ~40GB backup of your original drive.'''
+
=Assumptions=
  
==Phoem's Fast DD Method (OS X)==
+
This how-to is based on the assumption that you have removed the AppleTV's harddisk and connected it to your desktop computer.
  
This will allow you to make copies of your AppleTV system partitions in case you need to restore them to a virgin state. This has only been tested on MacOS X.
+
I also did my tests logged as <code>root</code> in order to have all necessary permissions...
  
NOTE: These instructions assume '''/dev/disk2''' is your AppleTV drive.
+
===Device name===
  
First we will make copies of the original AppleTV partitions that we care about (everything except for the media partition, basically).
+
It is assumed that the drive shows up as <code>/dev/disk4</code>.
 +
It could have another drive number on your Mac.
 +
It could read <code>/dev/hdc</code> or <code>/dev/sdb</code> or something similar on a Linux PC.
 +
 
 +
So be sure to replace the <code>/dev/disk4</code> in the following code by the proper device name.
 +
 
 +
The partitions will also change from e.g. <code>/dev/disk4s3</code> to something like <code>/dev/sdc3</code> on Linux.
 +
 
 +
===Device mount point===
 +
 
 +
It is assumed that the partitions are mounted on <code>/Volumes/OSBoot</code> and <code>/Volumes/Media</code>.
 +
This will be different on a Linux PC.
 +
So again replace the mount point names with the proper ones.
 +
 
 +
=Full drive backup=
 +
 
 +
===Full drive backup to a file===
 +
 
 +
The most secure starting point is to do a complete ~40GB backup of the original disk:
 +
umount /Volumes/Media/
 +
dd if=/dev/disk4 of=appleTV.img bs=1024
 +
 
 +
The only good backup is the tested one:
 +
dd if=appleTV.img of=/dev/disk4 bs=1024
 +
 
 +
===Full drive backup with compression===
 +
 
 +
The backup file will have the size of the disk. If you want to save space, you can compress it on the fly.
 +
Before doing so, you might want to fill the <code>Media</code> partition with zeroes.
 +
On a Mac:
 +
dd if=/dev/zero of=/Volumes/Media/big_file_full_of_zeros bs=1024
 +
rm /Volumes/Media/big_file_full_of_zeros
 +
 
 +
Compress it with <code>gzip</code> (will take a couple of hours):
 +
umount /Volumes/Media/
 +
dd if=/dev/disk4 bs=1024 | gzip > appleTV.img.gz
 +
 
 +
Compress it more (will take about twice the time):
 +
umount /Volumes/Media/
 +
dd if=/dev/disk4 bs=1024 | bzip2 -9 > appleTV.img.bz2
 +
 
 +
=Partitionwise backup (OS X)=
 +
 
 +
This has only been tested on Mac OS X.
 +
 
 +
===Phoem's fast method===
 +
 
 +
Phoem suggests a [http://phoem.com/appletv.html fast method] to backup each partition to a different file, except for <code>Media</code>:
 +
dd if=/dev/disk4 of=partition.img bs=1024k count=100
 +
dd if=/dev/disk4s1 of=EFI.img
 +
dd if=/dev/disk4s2 of=os.img
 +
dd if=/dev/disk4s3 of=OSBoot.img
 +
 
 +
The restoring process is similar:
 +
dd if=partition.img of=/dev/disk4 bs=1024k count=100
 +
dd if=EFI.img of=/dev/disk4s1
 +
dd if=OS.img of=/dev/disk4s2
 +
dd if=OSBoot.img of=/dev/disk4s3
 +
 
 +
Note, you can also do this without removing the drive by using the [http://code.google.com/p/atv-bootloader/wiki/ATVBackup LinuxUSBPenBoot].  --[[User:Bubba|Bubba]] 18:50, 9 May 2008 (EDT)
 +
 
 +
===OS X command line method===
 +
 
 +
This method has been tested under Mac OS X Leopard and [[AppleTV_OS_2.1]].
 +
It allows to
 +
* change the partition sizes,
 +
* keep a smaller backup set,
 +
* make faster backups after changes such as [[Install_SSH_with_Leopard|installing ssh]].
 +
 
 +
As the recovery partition is not mountable in Mac OS X, we'll copy it using Phoem's method:
 +
diskutil eject /dev/disk4
 +
dd if=/dev/disk4s2 of=recovery.img
 +
 
 +
The next partitions in turn will be saved as Mac OS disk images:
 +
hdiutil create -srcdevice /dev/disk4s3 osBoot.dmg
 +
hdiutil create -srcdevice /dev/disk4s4 media.dmg
 +
asr -imagescan osBoot.dmg
 +
asr -imagescan media.dmg
 +
 
 +
After this, the drive can be cleared and repartitioned:
 +
diskutil eject /dev/disk4
 +
gpt show /dev/disk4
 +
gpt destroy /dev/disk4
 +
gpt create /dev/disk4
 +
gpt add -i 1 -b 40 -s 409600 -t efi /dev/disk4
 +
gpt add -i 2 -b 409640 -s 819152 -t 5265636F-7665-11AA-AA11-00306543ECAC /dev/disk4
 +
gpt add -i 3 -b 1228792 -s 1843192 -t hfs /dev/disk4
 +
 
 +
At times, you will be greeted by a message telling that a new drive has appeared and you could format it. Click on ''ignore''.
 +
 
 +
Some notes:
 +
* With Leopard I had to create a larger EFI partition than the original one because it growed and moved after I attempted to format and restore the HFS partitions.
 +
* The largest partition I was able to create for <code>/dev/disk4s3</code> was 2097152 in size.
 +
* Leopard created a secondary GPT at the end of the disk.
 +
 
 +
Before adding the last partition, see how much place is left:
 +
diskutil eject /dev/disk4
 +
gpt show /dev/disk4
 +
 
 +
Then add the last partition (here for a 40GB drive):
 +
gpt add -i 4 -b 3071984 -s 75170959 -t hfs /dev/disk4
 +
 
 +
Format the partitions:
 +
diskutil list
 +
diskutil eraseVolume "Journaled HFS+" OSBoot /dev/disk4s3
 +
diskutil eraseVolume "Journaled HFS+" Media /dev/disk4s4
 +
 
 +
Restore the partitions:
 +
dd if=recovery.img of=/dev/disk4s2
 +
asr restore -s osBoot.dmg -t /dev/disk4s3 --erase --noprompt
 +
asr restore -s media.dmg -t /dev/disk4s4 --erase --noprompt
 +
 
 +
Eject the disk:
 +
diskutil eject /dev/disk4
 +
 
 +
Place it back in the AppleTV and let it boot.
 +
 
 +
=Linux info=
 +
 
 +
Creating a full backup image should be clear by looking at the partition table with fdisk. The minor partitions are wrapped in one large meta-partition!
  
Lets copy the partitions onto your local drive:
 
 
<pre>
 
<pre>
dd if=/dev/disk2 of=Partition.img bs=1024k count=100
+
Disk /dev/hdc: 40.0 GB, 40007761920 bytes
dd if=/dev/disk2s1 of=EFI.img
+
255 heads, 63 sectors/track, 4864 cylinders
dd if=/dev/disk2s2 of=OS.img
+
Units = cylinders of 16065 * 512 = 8225280 bytes
dd if=/dev/disk2s3 of=OSBoot.img
 
</pre>
 
  
Now lets put it back in place onto the new drive:
+
Device    | Boot | Start | End  | Blocks  | Id | System
<pre>
+
/dev/hdc1          1      4864    39070076  ee  EFI GPT
dd if=Partition.img of=/dev/disk2 bs=1024k count=100
 
dd if=EFI.img of=/dev/disk2s1
 
dd if=OS.img of=/dev/disk2s2
 
dd if=OSBoot.img of=/dev/disk2s3
 
 
</pre>
 
</pre>
  
Now use iPartition demo to find out the size if you were to grow the partition completely; using up the free space.<br>
 
Execute: '''gpt recover /dev/disk2'''<br>
 
Execute: '''gpt remove -i 4 /dev/disk2'''<br>
 
Unmount the drives.<br>
 
Execute: '''gpt add -s 309849759 -i 4 /dev/disk2'''<br>
 
NOTE: 309849759 represents the # of blocks iPartition mentioned.<br>
 
Finally, open '''diskutility''' and format just the media partition. (erase)<br>
 
  
==Linux Method==
+
Linux can see the partitions and can mount them (although journaling is not supported), if the following options are compiled in the kernel. (not sure if you need all of them)
  
[[XXX]] represents your AppleTV 2.5" notebook drive. It could be sda/sdb/sdc (USB) or hda/hdb/hdc (IDE) depending on your system, and how you connect the drive.
+
<pre>
 +
Filesystems -> Partition Types -> Advanced partition selection                    (CONFIG_PARTITION_ADVANCED=y)
 +
Filesystems -> Partition Types -> Macintosh partition map support                (CONFIG_MAC_PARTITION=y)
 +
Filesystems -> Partition Types -> EFI GUID Partition support                      (CONFIG_EFI_PARTITION=y)
 +
Filesystems -> Miscanelous filesystems ->Apple Extended HFS file system support  (CONFIG_HFSPLUS_FS=m or y)
 +
</pre>
  
Execute: '''dd if=/dev/[[XXX]] of=appletv-full-disk.bin bs=1M'''
+
Partitions can be mounted forcefully. Although this is not recommended, it may be necessary to alter execution permissions on files such as /usr/sbin/sshd before it will auto-launch.  Forceful mounts can be done with:
 +
<pre>
 +
mount -t hfsplus -o force /dev/sdc3 /mnt/appletv
 +
</pre>
  
This will create a full ~40GB backup of the drive. In the future, we will have to work on manipulating the partition table under linux, given HFS+ support is missing.
+
[[Category:How-to]]
 +
[[Category:2.0]]
 +
[[Category:2.0.1]]
 +
[[Category:2.0.2]]
 +
[[Category:2.1]]
 +
[[Category:2.3]]

Latest revision as of 12:50, 27 July 2010

Assumptions

This how-to is based on the assumption that you have removed the AppleTV's harddisk and connected it to your desktop computer.

I also did my tests logged as root in order to have all necessary permissions...

Device name

It is assumed that the drive shows up as /dev/disk4. It could have another drive number on your Mac. It could read /dev/hdc or /dev/sdb or something similar on a Linux PC.

So be sure to replace the /dev/disk4 in the following code by the proper device name.

The partitions will also change from e.g. /dev/disk4s3 to something like /dev/sdc3 on Linux.

Device mount point

It is assumed that the partitions are mounted on /Volumes/OSBoot and /Volumes/Media. This will be different on a Linux PC. So again replace the mount point names with the proper ones.

Full drive backup

Full drive backup to a file

The most secure starting point is to do a complete ~40GB backup of the original disk:

umount /Volumes/Media/
dd if=/dev/disk4 of=appleTV.img bs=1024

The only good backup is the tested one:

dd if=appleTV.img of=/dev/disk4 bs=1024

Full drive backup with compression

The backup file will have the size of the disk. If you want to save space, you can compress it on the fly. Before doing so, you might want to fill the Media partition with zeroes. On a Mac:

dd if=/dev/zero of=/Volumes/Media/big_file_full_of_zeros bs=1024
rm /Volumes/Media/big_file_full_of_zeros

Compress it with gzip (will take a couple of hours):

umount /Volumes/Media/
dd if=/dev/disk4 bs=1024 | gzip > appleTV.img.gz

Compress it more (will take about twice the time):

umount /Volumes/Media/
dd if=/dev/disk4 bs=1024 | bzip2 -9 > appleTV.img.bz2

Partitionwise backup (OS X)

This has only been tested on Mac OS X.

Phoem's fast method

Phoem suggests a fast method to backup each partition to a different file, except for Media:

dd if=/dev/disk4 of=partition.img bs=1024k count=100
dd if=/dev/disk4s1 of=EFI.img
dd if=/dev/disk4s2 of=os.img
dd if=/dev/disk4s3 of=OSBoot.img

The restoring process is similar:

dd if=partition.img of=/dev/disk4 bs=1024k count=100
dd if=EFI.img of=/dev/disk4s1
dd if=OS.img of=/dev/disk4s2 
dd if=OSBoot.img of=/dev/disk4s3 

Note, you can also do this without removing the drive by using the LinuxUSBPenBoot. --Bubba 18:50, 9 May 2008 (EDT)

OS X command line method

This method has been tested under Mac OS X Leopard and AppleTV_OS_2.1. It allows to

  • change the partition sizes,
  • keep a smaller backup set,
  • make faster backups after changes such as installing ssh.

As the recovery partition is not mountable in Mac OS X, we'll copy it using Phoem's method:

diskutil eject /dev/disk4
dd if=/dev/disk4s2 of=recovery.img

The next partitions in turn will be saved as Mac OS disk images:

hdiutil create -srcdevice /dev/disk4s3 osBoot.dmg
hdiutil create -srcdevice /dev/disk4s4 media.dmg
asr -imagescan osBoot.dmg
asr -imagescan media.dmg

After this, the drive can be cleared and repartitioned:

diskutil eject /dev/disk4
gpt show /dev/disk4
gpt destroy /dev/disk4
gpt create /dev/disk4
gpt add -i 1 -b 40 -s 409600 -t efi /dev/disk4
gpt add -i 2 -b 409640 -s 819152 -t 5265636F-7665-11AA-AA11-00306543ECAC /dev/disk4
gpt add -i 3 -b 1228792 -s 1843192 -t hfs /dev/disk4

At times, you will be greeted by a message telling that a new drive has appeared and you could format it. Click on ignore.

Some notes:

  • With Leopard I had to create a larger EFI partition than the original one because it growed and moved after I attempted to format and restore the HFS partitions.
  • The largest partition I was able to create for /dev/disk4s3 was 2097152 in size.
  • Leopard created a secondary GPT at the end of the disk.

Before adding the last partition, see how much place is left:

diskutil eject /dev/disk4
gpt show /dev/disk4

Then add the last partition (here for a 40GB drive):

gpt add -i 4 -b 3071984 -s 75170959 -t hfs /dev/disk4

Format the partitions:

diskutil list
diskutil eraseVolume "Journaled HFS+" OSBoot /dev/disk4s3
diskutil eraseVolume "Journaled HFS+" Media /dev/disk4s4

Restore the partitions:

dd if=recovery.img of=/dev/disk4s2
asr restore -s osBoot.dmg -t /dev/disk4s3 --erase --noprompt
asr restore -s media.dmg -t /dev/disk4s4 --erase --noprompt

Eject the disk:

diskutil eject /dev/disk4

Place it back in the AppleTV and let it boot.

Linux info

Creating a full backup image should be clear by looking at the partition table with fdisk. The minor partitions are wrapped in one large meta-partition!

Disk /dev/hdc: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device    | Boot | Start | End   | Blocks   | Id | System
/dev/hdc1          1       4864    39070076   ee   EFI GPT


Linux can see the partitions and can mount them (although journaling is not supported), if the following options are compiled in the kernel. (not sure if you need all of them)

Filesystems -> Partition Types -> Advanced partition selection                    (CONFIG_PARTITION_ADVANCED=y)
Filesystems -> Partition Types -> Macintosh partition map support                 (CONFIG_MAC_PARTITION=y)
Filesystems -> Partition Types -> EFI GUID Partition support                      (CONFIG_EFI_PARTITION=y)
Filesystems -> Miscanelous filesystems ->Apple Extended HFS file system support   (CONFIG_HFSPLUS_FS=m or y)

Partitions can be mounted forcefully. Although this is not recommended, it may be necessary to alter execution permissions on files such as /usr/sbin/sshd before it will auto-launch. Forceful mounts can be done with:

mount -t hfsplus -o force /dev/sdc3 /mnt/appletv