Recover some hard drive space via pdisk

May 29, '05 08:51:00AM

Contributed by: david-bo

Apple's Disk Utility wastes 128 MB of hard drive space for every partition it creates. On my PowerBook with a 40GB disk and three partitions (system, user, swap), this corresponds to about 1% of wasted space, or 384 MB. This is output from pdisk for that disk:

/dev/rdisk0  map block size=512
   #:                 type name                 length   base       ( size )
   1:  Apple_partition_map Apple                    63 @ 1       
   2:           Apple_Free                           0+@ 64      
   3:            Apple_HFS Apple_HFS_Untitled_2  9961472 @ 262208   (  4.8G)
   4:           Apple_Free                           0+@ 10223680
   5:            Apple_HFS Apple_HFS_Untitled_3  4225792 @ 10485824 (  2.0G)
   6:           Apple_Free                           0+@ 14711616
   7:            Apple_HFS Apple_HFS_Untitled_4 63166384 @ 14973760 ( 30.1G)
   8:           Apple_Free                           0+@ 78140144
Your output might look slightly different; for no appearant reason my two PowerBook's pdisk output varies a little. These Apple_Free parts are completely unnecessary and can be removed. I won't tell exactly how to repartition your drive, because if you can't figure out that yourself, you probably shouldn't do it, but I will give some hints on the way...

Here are a few things to keep in mind...

  1. You have to boot into single user mode (Command-S), otherwise you will get an error message stating "The map is not writeable."
  2. It is not until you do [w]rite that the partition table something actually changes. Until then, you can quit at any moment without risk.
  3. Let the first partition remain untouched:
      1: Apple_partition_map Apple                 63 @ 1
    Also, save 16 blocks (i.e. 8KB) at the end of the partition table:
      5:          Apple_Free Extra                 16 @ 78140144
    I don't know what the last 16 blocks are for, but they have been there since I used pdisk for the first time on my 9600 back in 1997.
  4. Just use the base of the Apple_Free section as start point for the next partition onwards.
Caution: If you have no means for backup, you shouldn't try this hint. With that said, you can split one partiton into two (or more) without losing your data, if you first defragment the partition and put all data at the beginning of the partition. You can also merge two partitions and keep the data on the first partition (the data of the second partition will disappear).

[robg adds: Please note that the instructions for doing this step-by-step are not provided here on purpose -- I've not used pisk before, and I'm not going to experiment through testing of this hint. The details here are for those who already understand pdisk and wish to use it to recover some free space.]

Comments (41)


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