0

I was trying to erase dual boot Ubuntu from my drive partition of 75 GBs. I erased it using disk utility, and followed some steps online to remove the partition.

Now all I see is my primary partition has TYPE Name : FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF

enter image description here

How can I fix it and add that 75GBs to my primary partition of 175 GBs. I search other similar post, but didn't understand anything over there.

Output of gpt -r show /dev/disk0 :

  start      size index contents
      0         1       PMBR
      1         1       Pri GPT header
      2        32       Pri GPT header
     34         6
     40   3932000     1 GPT part - 4846465300-0000-11AA-AA11-00306543ECAC
3932040    262151    
4194191        32       Sec GPT table
4194223         1       Sec GPT header

Output of fdisk /dev/disk0:

Disk: /dev/disk0            geometry
Signature: 0xAA55
      Starting              Ending
#: id    cyl     hd   sec   -  cyl   hd  sec  [   start -     size]
--------------------------------------------------------------------
1: EE   1023    254    63   - 1023  254   63  [       1 -  4194223] <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
12
  • Can you post the output from the command diskutil info disk0s2 | grep -e Offset -e Size Commented Apr 8, 2020 at 0:37
  • I get this : Partition Offset: 209735680 Bytes (409640 512-Byte-Device-Blocks) Disk Size: 175.8 GB (175790436352 Bytes) (exactly 343340696 512-Byte-Units) Device Block Size: 512 Bytes
    – Deep
    Commented Apr 8, 2020 at 1:48
  • Please edit your question to add additional details, don't post them as answers below.
    – nohillside
    Commented Apr 8, 2020 at 5:17
  • @DavidAnderson the output is added it to the question.
    – Deep
    Commented Apr 8, 2020 at 5:18
  • It would appear the drive is no longer in the Mac. Commented Apr 8, 2020 at 5:20

1 Answer 1

0

Note: This answer assumes the Mac only has one internal drive.

Follow the steps given below.

  1. Determine the partition offset and disk size in blocks. To do this, enter the command given below in a Terminal application window.

    diskutil info disk0s2 | grep -e Offset -e Size
    

    Below is an example output where the block size is 512 bytes. From the output, the partition offset and disk size can be determined as 409640 blocks and 195312500 blocks, respectively.

       Partition Offset:         209735680 Bytes (409640 512-Byte-Device-Blocks)
       Disk Size:                175.8 GB (175790436352 Bytes) (exactly 343340696 512-Byte-Units)
       Device Block Size:        512 Bytes
    

     
    Below is an example output where the block size is 4096 bytes. From the output, the partition offset can be determined as 76806 blocks. To get the disk size in 4096 bytes blocks, the value of 390625232 512-Byte-Units needs to be divided by 8 to get 48828154 blocks.

       Partition Offset:          314597376 Bytes (76806 4096-Byte-Device-Blocks)
       Disk Size:                 200.0 GB (200000118784 Bytes) (exactly 390625232 512-Byte-Units)
       Device Block Size:         4096 Bytes
    

     

  2. Use the key combination Option-⌘-R to boot to macOS Recovery over the Internet.
  3. Enter the commands below in a Terminal application window. Here, you will need to replace <offset-in-blocks> and <size-in-blocks> with an actually numbers.

    Disk=$(diskutil list | grep "(internal, physical)")
    Disk=${Disk/ *}
    gpt -f remove -i 2 $Disk
    gpt -f add -i 2 -b <offset-in-blocks> -s <size-in-blocks> -t apfs $Disk
    

    For example, if you used the output from the first example in step 1, then you would enter the commands given below.

    Note: The commands are case-sensitive.

    Disk=$(diskutil list | grep "(internal, physical)")
    Disk=${Disk/ *}
    gpt -f remove -i 2 $Disk
    gpt -f add -i 2 -b 409640 -s 343340696 -t apfs $Disk
    

    Note: Below is the legacy version of the above commands. You can use these commands, if the above two commands generate an illegal option error message.

    Disk=$(diskutil list | grep "(internal, physical)")
    Disk=${Disk/ *}
    diskutil unmountdisk $Disk
    gpt remove -i 2 $Disk
    diskutil unmountdisk $Disk
    gpt add -i 2 -b <offset-in-blocks> -s <size-in-blocks> -t 7C3457EF-0000-11AA-AA11-00306543ECAC $Disk
    

     

  4. Boot back to macOS.
  5. Enter the command given below to recover the free space.

    sudo diskutil apfs resizeContainer disk0s2 0
    

     

7
  • I haven't restarted my Macbook. I am afraid doing so will lock me out of the operating system. Will it affect data on my primary partition?
    – Deep
    Commented Apr 8, 2020 at 2:16
  • If you are at step 2, then when you restart you will not be able to boot to macOS until you complete step 3. Commented Apr 8, 2020 at 2:19
  • I get this error: gpt: illegal option -- f when I do gpt -f remove -i 2 disk0
    – Deep
    Commented Apr 8, 2020 at 3:01
  • Option-⌘-R is suppose to be the latest for your Mac. I will update my answer to include the legacy commands. Commented Apr 8, 2020 at 3:06
  • I was able to get gpt -f remove -i 2 disk0 but when I do gpt -f add -i 2 -b 409640 -s 343340696 -t apfs disk0 get an error saying gpt add: disk0: error: no space available on the device`
    – Deep
    Commented Apr 8, 2020 at 3:56

You must log in to answer this question.

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