20

I have deleted the first partition on my external HD such that it now has 100GB of free space at the beginning of the partition. I'd like to reclaim that space, but Disk Utility doesn't let me create a new partition there (it just does nothing when I click 'Apply'). Is there a way to accomplish this with diskutil? I’ve only found ways to change (or erase, or split etc.) existing partitions by e.g. entering disk2s2 as device ID, but the free space has no such device ID.

Outputs:

$ diskutil list disk2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.5 TB     disk2
   1:                        EFI                         209.7 MB   disk2s1
   2:                  Apple_HFS Shared                  199.3 GB   disk2s2
   3:                 Apple_Boot Recovery HD             784.2 MB   disk2s3
   4:          Apple_CoreStorage                         500.0 GB   disk2s4
   5:                 Apple_Boot Boot OS X               134.2 MB   disk2s5
   6:          Apple_CoreStorage                         699.6 GB   disk2s6
   7:                 Apple_Boot Boot OS X               134.2 MB   disk2s7
$ sudo gpt -r show disk2
Password:
       start        size  index  contents
           0           1         PMBR
           1           1         Pri GPT header
           2          32         Pri GPT table
          34           6         
          40      409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
      409640   195575768         
   195985408   389353696      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
   585339104     1531680      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
   586870784   976562504      4  GPT part - 53746F72-6167-11AA-AA11-00306543ECAC
  1563433288      262144      5  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  1563695432  1366319552      6  GPT part - 53746F72-6167-11AA-AA11-00306543ECAC
  2930014984      262144      7  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  2930277128           7         
  2930277135          32         Sec GPT table
  2930277167           1         Sec GPT header
$ sudo fdisk /dev/disk2
Disk: /dev/disk2    geometry: -5415437/4/63 [-1364690128 sectors]
Signature: 0xAA55
         Starting       Ending
 #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
 1: EE 1023 254  63 - 1023 254  63 [         1 - -1364690129] <Unknown ID>
 2: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
 4: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
$ sudo pdisk --list /dev/disk2
pdisk: No valid block 1 on '/dev/disk2'
4
  • 1
    On the Terminal, can you please run these commands and add the output to your question: diskutil list disk2, sudo gpt -r show disk2, sudo fdisk /dev/disk2 and sudo pdisk --list /dev/disk2? It's not clear why Disk Utility isn't working, maybe there's a problem with (one of) the partition table(s). Also, have you tried running a "repair" on both the whole hard disk and the partition on it?
    – pmdj
    Commented Sep 13, 2012 at 17:29
  • This Gist shows all the data you requested: gist.github.com/211c2bd5bc00a2f87b4c
    – MrMage
    Commented Sep 13, 2012 at 22:28
  • Can you boot from an external HD? If yes, I have an answer.
    – duci9y
    Commented Sep 14, 2012 at 7:48
  • Didn't try, but I think so (at least it worked in the past).
    – MrMage
    Commented Sep 14, 2012 at 9:02

1 Answer 1

26
+100

(Before proceeding, please make sure the disk in question is still disk2, you have backups of your data, etc. - that said, the changes here are not particularly dangerous. Read through the whole instructions before doing anything to make sure you understand all the steps.)

OK, your partition tables look fine (a valid GPT and a correct protective MBR), so I don't know why Disk Utility is failing you in this instance, but you should be able to create a partition in the empty space using the gpt command-line utility. Your GPT looks like this:

       start        size  index  contents
           0           1         PMBR
           1           1         Pri GPT header
           2          32         Pri GPT table
          34           6         
          40      409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
      409640   195575768         
   195985408   389353696      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
   585339104     1531680      3  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
   586870784   976562504      4  GPT part - 53746F72-6167-11AA-AA11-00306543ECAC
  1563433288      262144      5  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  1563695432  1366319552      6  GPT part - 53746F72-6167-11AA-AA11-00306543ECAC
  2930014984      262144      7  GPT part - 426F6F74-0000-11AA-AA11-00306543ECAC
  2930277128           7         
  2930277135          32         Sec GPT table
  2930277167           1         Sec GPT header

The free space is indicated by this line (the numbers are 512-byte sectors, so just under 100GB free space:

      409640   195575768         

Apple requires 128MiB (262144 sectors) free space following a partition, so the new partition can be 195575768-262144=195313624 sectors. Unmount all the volumes on the disk using:

diskutil unmountDisk disk2

Then, this command will create an HFS+ partition in the free space:

sudo gpt add -b 409640 -s 195313624 -t hfs disk2

That only creates the partition, not the file system. To check that it went well, you should now see a disk2s8 if you run diskutil list disk2. If this is indeed the case, you can format the partition like so:

sudo newfs_hfs -v "Volume Name" -J /dev/rdisk2s8

If disk2s8 hasn't appeared, you'll need to reboot before formatting. Instead of running newfs_hfs you should also be able to erase the partition in Disk Utility.

The gpt utility doesn't re-order the partition numbers but this shouldn't be a problem in practice. If you make any further changes with disk utility, that will probably fix the ordering anyway.

9
  • Well, this seems to have worked. But Disk Utility now shows a messed-up partition layout: i50.tinypic.com/2qxc3r6.jpg (the free space at the top expands a bit further - the partition view has scrollbars now).
    – MrMage
    Commented Sep 14, 2012 at 19:14
  • Hmm, that might be caused by the numbering and possibly whatever is causing the other Disk Utility bug in the first place. Realistically, if everything else works, you could just carry on in this state. Otherwise, you could try renumbering the partitions. Using standard gpt this is tedious and somewhat error prone/risky, as the only built-in way is to delete and recreate each partition. I actually have some patches against gpt that add renumbering and type changing commands - I could tidy those up and publish them if you'd be OK with rebuilding gpt from source in XCode...
    – pmdj
    Commented Sep 14, 2012 at 20:40
  • I have no problems building gtp from source, but is the code well-tested? I don't want to screw up my partition table. Also, is there a way to backup it?
    – MrMage
    Commented Sep 16, 2012 at 8:23
  • To add the partition, it's gpt add.
    – pduey
    Commented Jan 23, 2013 at 16:04
  • 1
    @AeroCross Their policy is published here, developer.apple.com/library/mac/technotes/tn2166/_index.html#//… in practice it's used as a boot partition if you use software RAID or Core Storage (Fusion Drive and/or File Vault) or similar software.
    – pmdj
    Commented Mar 9, 2013 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .