macOS cannot boot. How can I add trailing loader space? I am running El Capitain on a MacBook Pro and I decided to add a Ubuntu dual boot to the system. To do this I installed rEFInd, partitioned 100GB for the linux file system, partitioned 2GB for the Linux OS (as Mac is very funny about booting from USB) and partitioned ~20GB swap space for linux.

The install went successful and even though I had to fiddle about with the boot order to ensure rEFInd was shown instead of going straight to ubuntu everything worked fine. My issue was the extra Linux OS partition still existed and I wanted to get rid of it. 

To do this I used this command eraseVolume deleteme JFS+ /dev/…, which renamed the partition as 'deleteme'. Stupidly, I assumed the Recovery OS partition which seemed to have appeared was part of this process and so I ran that command on that partition too. From this point onwards I could no longer boot into Mac OS.

When booting into Internet Recovery and looking at diskutil I found the partition type of my main partition had become FFFFFFF-FFFF-FFFF-FFFFFFFF. To fix this I used the instructions detailed here: OS volume shows as type &#39;FFFFFFFF-FFFF-FFFF-FFFFFFFF&#39; after attempting to delete some Linux partitions—cannot log in, which seemed to work. But after this rEFInd still wouldn't load and macOS wouldn't show on startup disk or when holding Option on boot, in fact nothing shows in these menus.

When trying to fix the partition via diskutil I obtained these error messages:





Specifically diskutil firstaid says:


  Volume on disk1s2 has 0 bytes of trailing loader space and it needs X bytes. Problems were found with the partition map which might prevent booting.


And diskutil repairDisk says:


  Partition map repair failed file system check when creating loader space for the partition. You should repair that specific partition and then try repairing the partition map again.


Does anyone have any ideas on how to restore the macOS partition?
I nearly had this nightmare after installing MacOS Mojave, then playing around with the partitions with Paragon (the only good disk editor left for MacOS).
Unfortunately it shows the trailing partition as “free” approx 180M.
So not knowing that this was the other GPT partition table reference I cleared it out.



Every time I came to run first aid on the whole disk I got the same error.
Also it says run first aid from recovery which I didn’t have...

So stumbled on the MBR patch from these guys:
https://www.insanelymac.com/forum/files/file/944-mojave-mbr-hfs-firmware-check-patch/

This was brilliant and allows one to install easily to USB without having to use the APFS.
Then you need to disable SIP
So boot the Recovery on the USB
Then choose terminal.
Issue the following command:

csrutil disable
[see https://amp.reddit.com/r/osx/comments/3hv3kk/update_on_rootless_the_configuration_mechanism/#ampf=undefined
For more details]

Then type:

reboot

Hold down Alt key and then boot back into OS on main disk.
Then using Paragon Hard disk Manager (well worth it!)

https://www.paragon-software.com/home/hdm-mac/

Check your recovery partition (you can use diskutil list),
Delete it (make sure you back it up in case!)

I had to add another “empty” or “free space” after my main os (800MB)

I.e :
EFI:
Macintosh HD:
Free Space:
Other MacOS:

Then Copy the Recovery Volume from your USBstick using Diskutil or Paragon.

Now even if you select the Apple_Boot GUID in Paragon you still need to issue the following command: (replace TargetVolume with the volume you have (or have just created at the end of the main OS, ie I my case /dev/disk0s3)

[See the following website for more info on this command.
https://www.lifewire.com/create-os-x-recovery-hd-on-any-drive-2260909]
sudo asr adjust --target /dev/TargetVolume -settype Apple_Boot

Then this makes the volume dissapear from disk Utility (but not from Paragon HDM).

Then reboot into the recovery volume and run the following:

Diskutil umountDisk /dev/disk0
[allows disk to be verified]

DiskUtil verifyDisk /dev/disk0
[verify main disk]

Diskutil repairDisk /dev/disk0
[repair Disk0]

Then issue the final command to restore SIP back to normal

Issue the following command:

csrutil enable 



Then type:

reboot

Hold down Alt key and then boot back into OS on main disk.

You can now run the first aid on the main disk as well as the volumes and it should be fine.



Also CMD -R should now now bring up the Recovery HD.

Good luck to anyone else, just glad I have Paragon and Carbon Copy Cloner, but cmd line options are still needed.