1

I was trying to remove Ubuntu (dual boot) from my 2017 Macbook Air. Now my computer can not start successfully in either macOS or Linux. When I restart it, it now opens refind, then gnu rnu in both macOS and Linux.

I used Disk Utility when trying to remove Ubuntu. I don't completely remember what I did. However, I could not remove the partition Ubuntu uses. Then, I opened macOS in recovery mode and did some changes using diskutil. The disk now looks like this:

Can you help me fix this without losing my data? Is my data gone for good?

diskutil ls

gpt -r show /dev/disk0 shows:

enter image description here

Disk utility shows:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Edit: Output of :

export LC_CTYPE="ASCII"
diskutil unmountdisk disk0
dd if=/dev/disk0 count=1 bs=16 skip=13108482 | vis -cw;echo

enter image description here

Edit: It says resource busy when I entered the command gpt add -i 2 -b 409640 -t apfs disk0.

enter image description here

7
  • 1
    Hi Gizem, welcome to the community! Please edit your question and illustrate which troubleshooting steps you have performed so far, how you tried to remove ubuntu and what data you are trying to recover (Linux, macOS). Also try to choose a title that illustrates your issue. Commented Oct 13, 2021 at 17:38
  • This question about a problem similar to yours (and its answers) might help, at least in terms of how to post your question and which details to include.
    – Alper
    Commented Oct 13, 2021 at 18:40
  • When booting into Recovery Mode and selecting "Startup Disk" from the Apple Logo in the menu bar - are any options listed? I would use another Mac or install macOS to an external drive and see if you can locate any file via Finder (or use Terminal if your savvy enough) to check what's stored on the mountable volumes. Commented Oct 14, 2021 at 9:23
  • Gizem: Edit your question and add the output from the command gpt -r show /dev/disk0. Commented Oct 14, 2021 at 13:26
  • 1
    You made a mistake when entering export LC_CTYPE="ASCII". If you look at the image you posted, then you will see that you entered export LC_TYPE="ASCII" instead. This may have caused the dd if=/dev/disk0 count=1 bs=16 skip=13108482 | vis -cw;echo command to output partially useless data. Commented Oct 16, 2021 at 2:12

2 Answers 2

1

Note: This answer uses export LC_CTYPE="ASCII". While using export LC_CTYPE="ASCII" works, internally the vis command does not recognize ASCII and defaults to C. So, in the future, export LC_CTYPE="C" (or just export LC_CTYPE=C) should be used instead.

Use the following steps.

  1. Boot to the same Recovery Mode used in your question.

  2. Enter the following commands. None of these commands alter your Mac. The commands just product diagnostic information, which may be helpful.

    sw_vers
    export LC_CTYPE="ASCII"
    diskutil unmountdisk disk0
    dd if=/dev/disk0 count=1 bs=16 skip=13108482 | vis -cw;echo
    

    Post the output from the above commands to your question.

  3. Enter the commands given below.

    diskutil unmountdisk disk0
    gpt -f add -i 2 -b 409640 -t apfs disk0
    diskutil list internal
    

    If the above commands execute successfully, then the name of the APFS volume containing macOS will appear in the output from the command diskutil list internal. If not, then post the output from the above commands to your question, post a comment to my answer and wait for my response. Otherwise, proceed.

  4. Enter the following commands. When entering the commands, use the output from the previously entered diskutil list internal command to replace diskXsV with the identifier for the APFS Volume containing macOS and replace diskYsC with the identifier for the Apple_APFS Container listed as the Physical Store for the APFS Volume.

    diskutil info diskXsV | grep "Disk Size"
    diskutil info diskYsC | grep "Disk Size"
    

    If the output from both commands match, then you are done. Otherwise, proceed.

  5. Enter the following commands. When entering the commands, use the output from the previously entered diskutil info diskXsV | grep "Disk Size" command to replace SizeInBlocks with the disk size in 512-Byte-Units for the APFS Volume containing macOS.

    diskutil unmountdisk disk0
    gpt -f remove -i 2 disk0
    diskutil unmountdisk disk0
    gpt -f add -i 2 -b 409640 -s SizeInBlocks -t apfs disk0
    

Use of the gpt add Command

This section can be ignored by the OP (user Gizem Kaya) . This section was added to this answer mainly to address concerns posted by user Jean_JD. The add command for gpt includes the -i, -b, -s and -t command-specific options. The table below explains how the default values are determined when one or more of these options is omitted.

Option Default If Omitted
-i The first partition in the table with a partition type of zero
-b The starting sector number of the first available block of an unused disk space.
-s The largest available size in sectors based on the starting sector number.
-t A partition type UUID value of 48465300-0000-11AA-AA11-00306543ECAC, which is the same as the hfs alias.

If the case of this answer, the command-specific option -s was omitted from gpt -f add -i 2 -b 409640 -t apfs disk0 command in step 3. When the OP enters the command, the default value of 384370648 will be used for the size in sectors.

7
  • First, thank you for your response. It says resource busy when I entered the command “gpt add -i 2 -b 409640 -t apfs disk0”
    – Gizem Kaya
    Commented Oct 15, 2021 at 11:24
  • @David. In poin3 your gpt command is incomplete.
    – user415185
    Commented Oct 15, 2021 at 11:46
  • @Jean_JD: I am not sure what is incomplete. Can you precise? If by chance, you are referring to the omission of the -s option, then I can state this was deliberate and does not result in an incomplete command. Commented Oct 15, 2021 at 18:39
  • @David This command can't work gpt add -i 2 -b 409640 -t apfs disk0. But without the size info or gpt show disk0 it's a little hard find a solution ;-}
    – user415185
    Commented Oct 15, 2021 at 19:26
  • @Jean_JD: You are wrong. You should verify what you claim before posting false information. Commented Oct 15, 2021 at 19:53
0

First, boot in internet recovery mode (cmd+alt+r at boot) Then verify if the internal disk is always disk0

diskutil list internal

will help you. Then from the terminal verify if it's necessary to remove the entry 2 if present with command (keep in mind replacing diskX with the good value).

gpt -r show diskX

If yes

diskutil unmountdisk diskX
gpt remove -i 2 diskX

Then in all case create this entry:

diskutil unmountdisk diskX
gpt add -i 2 -b 409640 -s  384370648 -t apfs diskX

Then you verify with :

diskutil list internal
1
  • The OP has already posted the output from gpt -r show disk0. So your answer instructs the OP to perform the same operations I posted in step 3 of my answer. Commented Oct 15, 2021 at 20:28

You must log in to answer this question.

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