I created a copy of a working (but getting a few disk errors) 1TB spinning disk drive using dd
. I can mount the image (hdiutil attach
or just double click in Finder) no problem and see the files on the main HFS+ volume. However, I don't see the other partitions which I know are there (EFI, Recovery HD). I know these are there because if I restore the image directly to a physical drive, they are there.
However, I would like to restore this image to a 480GB SSD (smaller), so I need to shrink the main/large HFS+ partition of the image. There is plenty of free space in the partition (700GB) so this should be feasible.
I have tried converting the image to a read-write image (hdiutil convert -format UDRW
) or a sparse bundle (hdiutil convert -format UDSB
– results in a 200GB file).
The read-write image won't resize:
hdiutil: resize request is below minimum size allowed.
Running hdiutil compact
on the sparse bundle won't shrink it:
Reclaimed 0 bytes out of 796.9 GB possible.
What is the correct way to accomplish resizing the main/large HFS+ partition in the full disk image?
Best Answer
In my opinion this may be possible but it's not effective because to accomplish this you would have to extract and shrink one part of the dd raw image and then reassemble all three parts. Additionally you have to manipulate the gpt partition table inside the reassembled raw dd image by hex-editing it. Then you have to
dd
back the image.Instead do the following which is significantly less time consuming and probably less error-prone:
dd
the EFI and the Recovery HD in your dd raw image to the respective partitions of your new SSDrsync
the content to the new main volume.Here I assume you have an external disk with a full OS X (El Capitan) to prepare the SSD. All device names/identifiers or sizes are just examples and may differ from your actual environment/results.
Preparing your new SSD:
Open Terminal and enter
diskutil list
. The result should be (the sizes may slightly differ from yours):In Terminal enter
sudo gpt -r show disk0
. The result should be (the sizes may slightly differ from yours):Now unmount disk0 and remove the second partition:
Add the recovery partition. The recovery partition always has the size 1269536 blocks and starts at total size of the disk in blocks - 1269576 blocks (in my example that's: 937426944 - 1269576 = 936157368)
Enter
sudo gpt -r show disk0
again to show the new partition:In the empty space between partition i=1 and i=3 add a new partition. The start block and the size are given by the data found above:
Unmount disk0 and format the new volume:
Restoring your data:
Enter
diskutil list
. You should see a new entry similar to this one:dd the EFI and the Recovery HD from the image to the SSD:
mount the main volume of the SSD:
rsync the content of the main volume of the disk image (which should be visible on your desktop in contrary to the EFI/Recovery HD partitions) to the main SSD volume:
This is a very basic rsync command example. You may refine the rsync command (options/exclusions) according to this or this linked scripts.
Please check all device names in the various command containing
dd
orgpt
thoroughly or you will delete or overwrite important partitions/data unwantedly.