MacOS – (Mistakenly) Deleted all partitions except for disk0s2, can’t mount or repartition

disk-utilitymacospartition

First of all, I apologize that I cannot remember exactly what version of Mac OS I am running, but I am 99% sure it's Yosemite.

I recently tried to delete a second partition I had been using for a Ubuntu distro. While I was trying to erase the partition, the minus button was grayed out, but I found that if I clicked the minus on the other small partitions (I'm assuming retrospectively that it was the disk utility partition and something else) then I was able to delete the Ubuntu partition, so that's what I did.

So now my hard drive has one partition, disk0s2 with about 900gb and then an extra free space of 99.8gb. The free space can't be partitioned or reconfigured in any way, attempting to do so starts up a progress bar that never gets beyond 'preparing'. disk0s2 is unmounted, the mount button is blue and not grayed out, but clicking it does nothing.

Restarting and running in disk utility mode (I believe that's what it's called, CMD+R), does work, restarting holding OPT shows only the EFI boot, which takes me to GNU Grub version 2.02, which is also what happens when restarting normally. I thought that maybe inserting a USB and downloading Mac OS onto that from the disk utility start up might be a way of solving this problem, but my computer won't mount the USB (the mount button is not grayed out but clicking it does nothing) so it doesn't show up when trying to reinstall the OS.

What should I do? I have access to an external hard drive with enough space to put what was on my hard drive if that is possible, but obviously I would prefer to be able to recreate the disk utility partition (?) and remount disk0s2.

Here is the result of running diskutil in terminal:

enter image description here

Best Answer

You should be able to repair you existing partition so you can boot to OS X. The steps are given below. Here, I assume you were using Yosemite or some other version of OS X that installs to a "Mac OS Extended (Journaled)" formatted volume. Also, I assume encryption was not being used.

Note: The examples were made using a disk image while booted to High Sierra. So, your output may vary from what is shown.

  1. Start up the Mac from macOS Recovery over the Internet by restarting and immediately pressing and holding the the key combination ⌘-R.
  2. From the menu bar, select to open a Terminal application window.
  3. Enter the following command to get the GUID Partition Table (GPT) entries.

    gpt -r show /dev/disk0
    

    An example output is shown below.

    $ gpt -r show /dev/disk0
           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  1757812496      2  GPT part - FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
      1758222136   194902871         
      1953125007          32         Sec GPT table
      1953125039           1         Sec GPT header
    
  4. Enter the commands given below to change the GPT.

    diskutil unmountdisk /dev/disk0
    gpt remove -i 2 /dev/disk0
    diskutil unmountdisk /dev/disk0
    gpt add -i 2 -b <start> -s <size> -t 48465300-0000-11AA-AA11-00306543ECAC /dev/disk0
    

    Where <start> and <size> are integers taken from the row with index equal to 2 in the table shown in step 2. An example is shown below.

    $ diskutil unmountdisk /dev/disk0
    Unmount of all volumes on disk0 was successful
    $ gpt remove -i 2 /dev/disk0
    /dev/disk0s2 removed
    $ diskutil unmountdisk /dev/disk0
    Unmount of all volumes on disk0 was successful
    $ gpt add -i 2 -b 409640 -s 1757812496 -t 48465300-0000-11AA-AA11-00306543ECAC /dev/disk0
    /dev/disk0s2 added
    

    You will need to replace 409640 and 1757812496 with the values shown in your GPT table.

  5. Restart the Mac back to OS X.

  6. Enter the command given below in a Terminal application window to reclaim the free space.

    sudo diskutil resizevolume /dev/disk0s2 R
    

    An example is shown below.

    $ sudo diskutil resizevolume /dev/disk0s2 R
    Resizing to full size (fit to fill)
    Started partitioning on disk0s2 Macintosh HD
    Verifying the disk
    Verifying file system
    Volume was successfully unmounted
    Performing fsck_hfs -fn -x /dev/rdisk0s2
    Checking Journaled HFS Plus volume
    Checking extents overflow file
    Checking catalog file
    Checking multi-linked files
    Checking catalog hierarchy
    Checking extended attributes file
    Checking volume bitmap
    Checking volume information
    The volume Macintosh HD appears to be OK
    File system check exit code is 0
    Restoring the original state found as mounted
    Resizing
    Modifying partition map
    Growing file system
    Finished partitioning on disk0s2 Macintosh HD
    /dev/disk0
       #:                       TYPE NAME                    SIZE       IDENTIFIER
       0:      GUID_partition_scheme                        *1.0 TB     disk0
       1:                        EFI EFI                     209.7 MB   disk0s1
       2:                  Apple_HFS Macintosh HD            999.7 GB   disk0s2
    

Addition Comments

  • Your internal recovery partition no longer exists. When you reinstall OS X or upgrade to a newer OS X or macOS, a new recovery volume will be created.
  • Grub still exists in your EFI partition (disk0s1). You should consider removing Grub.