Make a partition of an exact size for cloning

Dec 19, '07 07:30:00AM

Contributed by: iangoldby

It is very difficult to create a disk partition of the exact same size as an existing partition of another disk using Apple's Disk Utility. Whenever I try this, I always find the size of the partition created by Disk Utility is slightly different from the partition I'm trying to clone. Here's a way using the command line that allows you to get the size exactly right.

The standard warning applies: Be very careful. This will wipe the entire disk that you are repartitioning. One small typo could result in the wrong disk being wiped!

Here's how to do it:

  1. Open Terminal, and if your account doesn't have administrator privileges, su to the administrator user.
  2. Type diskutil info /Volumes/partition_to_clone/ to find the size of the partition you want to clone. The output should include something like this:
    Total Size: 74.2 Gi (79682387968 B) (155629664 512-byte blocks)
  3. Note the number of 512-byte blocks, and then add 262144 to that number. Why 262144? Because that amount is added to each partition, for "future use by Apple, and are populated as needed for some boot methods, such as AppleRAID booting on PowerPC systems," according to this email message.
  4. Create the new partition using the augmented size you just calculated, for example:
    sudo diskutil partitionDisk partition_id 2 GPTFormat "Journaled HFS+" "Bootable Clone" 155891808S "Journaled HFS+" "Spare" 1G
    partition_id represents the disk that you are partitioning, for example, /dev/disk1. diskutil automatically extends the final partition to use the remaining space on the disk, so the given size (1G) doesn't actually mean anything here. The S suffix means that the size is being specified in 512-byte blocks.
The key to getting this right is adding on the 262144 blocks. If you don't do this, your partition will always be slightly too small!

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20071209105649551