Mac – Why does “diskutil eraseVolume …” add an extra “Apple_Free” partition

disk-utilitydiskutilmacpartition

My question is about why "diskutil eraseVolume" adds an extra partition to an APM partition table.

A little history will help understand the situation better I think — had a 240GB APM style disk on an old PowerBook system that I wanted to upgrade to a larger disk. The PowerBook has some heat related problems and the video goes bad after about 1-2 hours, so wanted to do all this work on another Mac that runs High Sierra, in case the video went bad during the reconstruction on the old PowerBook.

So, basically used "dd" command to clone the entire old 240GB disk to the new 500GB disk, then modified the partition table to correct the total size of disk and size of last partition to compensate for the larger disk, knowing that would need to erase that last HFS+ partition as it's no longer valid. But first, wanted to use "diskutil verifyVolume …" command to check all the various filesystems and discovered that besides the last MacOS volume the xxxxx volume was also no longer correct.

So, no problem I think — will erase the last two volumes and restore from a backup image and all should be fine. Here is what the partition table started out as on the 500GB disk:

==================================pdisk "p" command output============
Partition map (with 512 byte blocks) on '/dev/rdisk6'
 #:                type name               length   base      ( size )
 1: Apple_partition_map Apple                  63 @ 1        
 2:      Apple_Driver43*Macintosh              56 @ 64       
 3:      Apple_Driver43*Macintosh              56 @ 120      
 4:    Apple_Driver_ATA*Macintosh              56 @ 176      
 5:    Apple_Driver_ATA*Macintosh              56 @ 232      
 6:      Apple_FWDriver Macintosh             512 @ 288      
 7:  Apple_Driver_IOKit Macintosh             512 @ 800      
 8:       Apple_Patches Patch Partition       512 @ 1312     
 9:           Apple_HFS MacOS 10.0       64039712 @ 1824      ( 30.5G)
10:           Apple_HFS MacOS 10.1       64039712 @ 64041536  ( 30.5G)
11:           Apple_HFS MacOS 10.2       64039712 @ 128081248 ( 30.5G)
12:           Apple_HFS MacOS 10.3       64039712 @ 192120960 ( 30.5G)
13:           Apple_HFS MacOS 10.4       64039712 @ 256160672 ( 30.5G)
14:           Apple_HFS xxxxx            64039712 @ 320200384 ( 30.5G)
15:           Apple_HFS MacOS           592532992 @ 384240096 (282.5G)
16:          Apple_Free Extra                  80 @ 976773088

Device block size=512, Number of Blocks=976773168 (465.8G)
DeviceType=0x0, DeviceId=0x0
Drivers-
1:  23 @ 64, type=0x1
2:  36 @ 120, type=0xffff
3:  21 @ 176, type=0x701
4:  34 @ 232, type=0xf8ff
======================================================================

I used the command "diskutil eraseVolume HFS+ xxxxx /dev/rdisk6s14" (can't use the GUI Disk Utility program to erase an HFS+, non-journaled, filesystem as that is apparently no longer supported on High Sierra version of Disk Utility.app GUI application) and the partition table had been modified to include a new "Apple_Free" partition right before the "xxxxx" partition:

==================================pdisk "p" command output===========================
Partition map (with 512 byte blocks) on '/dev/disk6'
 #:                type name               length   base      ( size )
 1: Apple_partition_map Apple                  63 @ 1        
 2:      Apple_Driver43*Macintosh              56 @ 64       
 3:      Apple_Driver43*Macintosh              56 @ 120      
 4:    Apple_Driver_ATA*Macintosh              56 @ 176      
 5:    Apple_Driver_ATA*Macintosh              56 @ 232      
 6:      Apple_FWDriver Macintosh             512 @ 288      
 7:  Apple_Driver_IOKit Macintosh             512 @ 800      
 8:       Apple_Patches Patch Partition       512 @ 1312     
 9:           Apple_HFS MacOS 10.0       64039712 @ 1824      ( 30.5G)
10:           Apple_HFS MacOS 10.1       64039712 @ 64041536  ( 30.5G)
11:           Apple_HFS MacOS 10.2       64039712 @ 128081248 ( 30.5G)
12:           Apple_HFS MacOS 10.3       64039712 @ 192120960 ( 30.5G)
13:           Apple_HFS MacOS 10.4       64039712 @ 256160672 ( 30.5G)
14:          Apple_Free                    262144 @ 320200384 (128.0M)
15:           Apple_HFS xxxxx            63777568 @ 320462528 ( 30.4G)
16:           Apple_HFS MacOS           592532992 @ 384240096 (282.5G)
17:          Apple_Free                        80 @ 976773088

Device block size=512, Number of Blocks=976773168 (465.8G)
DeviceType=0x0, DeviceId=0x0
Drivers-
1:  23 @ 64, type=0x1
2:  36 @ 120, type=0xffff
3:  21 @ 176, type=0x701
4:  34 @ 232, type=0xf8ff
===============================================================================

So, why the new "Apple_Free" partition right before the real "xxxxx" HFS+ partition? I did the "diskutil eraseVolume" once more for the MacOS partition and it again created a new "Apple_Free" partition of same size (262144 blocks) before the real HFS+ partition. So that after these two "eraseVolume" commands the partition table now looks like this:

==========================pdisk "p" command output=====================
Partition map (with 512 byte blocks) on '/dev/disk6'
 #:                type name               length   base      ( size )
 1: Apple_partition_map Apple                  63 @ 1        
 2:      Apple_Driver43*Macintosh              56 @ 64       
 3:      Apple_Driver43*Macintosh              56 @ 120      
 4:    Apple_Driver_ATA*Macintosh              56 @ 176      
 5:    Apple_Driver_ATA*Macintosh              56 @ 232      
 6:      Apple_FWDriver Macintosh             512 @ 288      
 7:  Apple_Driver_IOKit Macintosh             512 @ 800      
 8:       Apple_Patches Patch Partition       512 @ 1312     
 9:           Apple_HFS MacOS 10.0       64039712 @ 1824      ( 30.5G)
10:           Apple_HFS MacOS 10.1       64039712 @ 64041536  ( 30.5G)
11:           Apple_HFS MacOS 10.2       64039712 @ 128081248 ( 30.5G)
12:           Apple_HFS MacOS 10.3       64039712 @ 192120960 ( 30.5G)
13:           Apple_HFS MacOS 10.4       64039712 @ 256160672 ( 30.5G)
14:          Apple_Free                    262144 @ 320200384 (128.0M)
15:           Apple_HFS Titoonium        63777568 @ 320462528 ( 30.4G)
16:          Apple_Free                    262144 @ 384240096 (128.0M)
17:           Apple_HFS MacOS           592270848 @ 384502240 (282.4G)
18:          Apple_Free                        80 @ 976773088

Device block size=512, Number of Blocks=976773168 (465.8G)
DeviceType=0x0, DeviceId=0x0
Drivers-
1:  23 @ 64, type=0x1
2:  36 @ 120, type=0xffff
3:  21 @ 176, type=0x701
4:  34 @ 232, type=0xf8ff
=======================================================================

Any idea why these "Apple_Free" partitions get created, or even better how to keep it from happening? Thanks…

Best Answer

Instead of diskutil, try using newfs_hfs to create the filesystems. I don't know what happens in Mac OS, but in my experience, the newfs_* commands in BSD create a filesystem in a partition without changing the partition map.

I don't know why Apple likes to reserve 128 megabytes of free space before an HFS partition. I saw this in my PowerBook G4, when I used the Disk Utility from Mac OS X 10.4 to format my internal hard disk, and it put 128M of Apple_Free (partition 2) between the Apple_partition_map (partition 1) and my Apple_HFS (partition 3). I guess that one can use part of the 128M to add Mac OS 9 drivers for the disk.

Your disk already has Mac OS 9 drivers (Apple_*Driver* and Apple_Patches), so I don't know why it would need 128M of Apple_Free. I speculate that your disk might have IDE drivers but not FireWire drivers. If you would boot your PowerBook in FireWire disk mode, and connect it to some Mac OS 9 machine, then you might need some Apple_Free space to add more drivers; but I never had FireWire hard disks, so I don't know.