2

I installed Kali Linux on my iMac as Dual Boot. After a while I needed more space for Kali so I decided to shrink my Mac Partition (APFS) using MacOS Disk Utility Tool.

  • I created a new 100 GB Partition (exFat).
  • I tried to reboot my Computer and only Kali Linux showed up as bootable.

So far I tried to boot in Recovery Mode, but instead of the normal MacOS High Sierra recovery menu the recovery menu from MacOS Lion showed up.

kali@kali:~$ sudo fdisk -l /dev/sda

Disk /dev/sda: 931,53 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: CT1000MX500SSD1 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: E1EA0C68-DA59-406C-944A-089B812AD69D

Device          Start        End    Sectors   Size Type
/dev/sda1          40     409639     409600   200M EFI System
/dev/sda2      409640 1561962535 1561552896 744,6G Linux filesystem
/dev/sda3  1561964544 1757014015  195049472    93G Microsoft basic data
/dev/sda4  1757276160 1920016383  162740224  77,6G Linux filesystem
/dev/sda5  1920016384 1953523711   33507328    16G Linux swap

kali@kali:~$ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 1.0.5

Partition table scan:
  MBR: hybrid
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with hybrid MBR; using GPT.

Command (? for help): p
Disk /dev/sda: 1953525168 sectors, 931.5 GiB
Model: CT1000MX500SSD1 
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): E1EA0C68-DA59-406C-944A-089B812AD69D
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 8-sector boundaries
Total free space is 265581 sectors (129.7 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              40          409639   200.0 MiB   EF00  EFI System Partition
   2          409640      1561962535   744.6 GiB   8300                                                                                                   
   3      1561964544      1757014015   93.0 GiB    0700                                                                                                   
   4      1757276160      1920016383   77.6 GiB    8300                                                                                                   
   5      1920016384      1953523711   16.0 GiB    8200   

enter image description here

Any ideas to on how to boot in MacOS without losing all my macOS data?

6
  • Try Internet Recovery [cmd/shift/R], then see what the diskutil list command shows from the Terminal in there. Kali can't read APFS & neither can Lion. Also, please tell us precisely which iMac model.
    – Tetsujin
    May 9 '20 at 11:21
  • I installed the rEFInd Boot Manager on my Mac in order to Switch between my two systems. If I try to go into Internet recovery mode it just restarts and goes back to my boot manager. I can only go normally into recovery mode using cmd+r. Then a globe shows up, I have to wait a little bit and then it goes into recovery mode (lion). I have a iMac12,2 May 9 '20 at 11:40
  • ach, my bad Cmd/OPT/r not shift. You need to be able to get it into something that can understand APFS before you can go any further.
    – Tetsujin
    May 9 '20 at 11:45
  • I tried that one too. Didn’t work for me. Still only my Boot Manager shows up when I tried to go in Internet recovery mode. May 9 '20 at 11:49
  • I've tightened up that picture a bit. We're past my ability to help but there are a few guys on here who ought to be able to use that info to help. Wish you luck :)
    – Tetsujin
    May 9 '20 at 11:55
2

The answer below was developed based on your question and the image you posted. A cropped version of this image is posted below.

Enter the following from linux.

Note: I can tell you have taken steps that have not been posted to your question. Therefore, even if the procedure below repairs the partition tables, there may be damage to the APFS container from these steps that are unknown to me.

sudo gdisk /dev/sda
p
x
o
n
m
t
3
8300
n
5
409640
1561962535
AF0A
s
p
w
y

Explanation

Execute gdisk on the internal drive as root user.

sudo gdisk /dev/sda

Print out the GUID Partition Table (GPT) and the Master Boot Record (MBR) partition table.

p
x
o

Change the MBR partition table from hybrid to protective

n

Change the kali volume partition type from Microsoft to linux.

m
t
3
8300

Add back in the APFS partition.

n
5
409640
1561962535
AF0A

Sort the partitions in ascending order.

s

Print the resulting GPT.

p

Write the result back to the internal drive and exit gdisk.

w
y
7
  • Well, it was the right answer. May 9 '20 at 13:15
  • It was the right answer? May 9 '20 at 13:21
  • It was until you entered the command gpt remove -i 2 /dev/disk0. May 9 '20 at 13:24
  • I posted an updated answer. However, since gdisk has indicated /dev/sda is hybrid partitioned, I would first want to see the contents of the MBR partition table. From linux, can you post the results of the commands given in this image? May 9 '20 at 23:04
  • Here are the results of the commands you needed. May 10 '20 at 13:32
1

The second partition of the SSD (disk0s2/sda2) has the wrong GUID (0FC63DAF-8483-4772-8E79-3D69D8477DE4) which identifies it as a Linux native partition.

If you replace disk0s2/sda2 with a partition with the proper type (APFS) it should be a valid macOS boot partition again.

Changing the GUID while keeping the size and the start block won't alter the content of the partition if you don't repair the disk/volume!

In Recovery Mode enter in Terminal:

  1. Get the details (of the internal SSD):

    diskutil list
    gpt -r show disk0 #replace accordingly if the SSD has another device identifier
    
  2. Unmount disk0: diskutil umountDisk /dev/disk0
  3. Remove disk0s2:

    gpt remove -i 2 /dev/disk0
    diskutil umountDisk /dev/disk0
    
  4. Add the partition again with the proper GUID

    gpt add -i 2 -b 409640 -s 1561554904 -t 7C3457EF-0000-11AA-AA11-00306543ECAC /dev/disk0
    
  5. reboot

This (i.e. rebooting to macOS High Sierra) only works if you didn't reformat disk0s2/sda2 to some Linux file system (ext3, ext4, etc.) by accident previously.

9
  • If you have not got a backup of your data then do a backup now before you get it wrong yet again.
    – Solar Mike
    May 9 '20 at 12:33
  • First of all thank you very much for your effort, it means a lot me! I followed all your steps but now I‘m stuck at step 4. I copied your code but gpt only gives me the "usage: gpt add ...", indicating that there is a syntax error in the command. Do you have any idea what the problem is? May 9 '20 at 13:09
  • So it seems that there was a "C" missing at the end of the uuid, but now it says "gpt add: unable to open device /dev/disk0: no such file or directory“. May 9 '20 at 13:36
  • @user10802841 Sorry for the missing C - somehow c&p from another of my answers failed
    – klanomath
    May 9 '20 at 13:47
  • @user10802841 Please add another screenshot with the result of gpt -r show disk0 (or sudo gdisk /dev/sda from inside Kali).
    – klanomath
    May 9 '20 at 13:54

You must log in to answer this question.

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