MacOS – move grub from sd-card to win partition

bootcampgrubmacossd cardunix

i'm not the first one with this kind of problem, but my specific nuance, i did not yet encounter: i have a 2014 macbook pro with os x plus a windows 10 bootcamp partition. now i wanted to have a look at ubuntu and managed to install that on an sd-card. all that worked, but the situation i have now is:

  • if i start without the sd-card inserted and option pressed, i can choose between os x and windows. loading os x works, loading windows does not and results in a grub prompt.
  • if i start with the ubuntu sd-card inserted and option pressed, i get all three options. again, os x works and windows fails, but this time with a grub error message. choosing ubuntu successfully starts grub and gives me the option of booting either ubuntu or windows: which both work.

from my understanding (which might be wrong), part of grub ended up on the windows (or efi??) partition, the rest with the actual configuration on the external ubuntu sd-card. is there any way to move this second part to the windows partition? so i can still start windows without this external sd card? in an ideal world, i would just get rid of grub and use the apple bootloader for all of this, but i assume this is not a possibility, is it?

Best Answer

You can setup a grubless boot of Ubuntu which can be executed by the Mac boot loader, however the Mac Startup Manager will not detect such an arrangement. You would have to use a different boot manager such as rEFInd.

Another solution would be to install grub entirely on the SD card, leaving the EFI partition on the internal drive use by Windows. Or, create a second EFI partition on the internal drive, so the grub and Windows boot files will not overlap.

Moving Grub Boot Files to the SD Card

When installing Ubuntu on the SD card, an EFI partition should be created on this card. The Grub boot files should be installed in the EFI partition. The However, the Ubuntu installation software will install the Grub boot files on internal drive EFI partition instead. Below are instructions for moving these files to the EFI partition on the SD card.

Note: The steps below assume the device name for the SD card is /dev/sdb. If your device name is different, then make the appropriate substitutions when entering the commands.

  1. Boot to Ubuntu.

  2. Turn off automatic updates. Open "Software & Updates" and set "Automatically check for Updates:" to Never. See the image below.

  3. Open a Terminal window.

  4. Verify the first partition on the SD Card is FAT formatted. Enter following command.

    sudo blkid /dev/sdb1
    

    If the TYPE is not equal to vfat, then the first partition on the SD card is not an EFI Partition. If TYPE is equal to vfat, then record the UUID value and proceed with these instructions.

  5. Move the Grub boot files to the SD Card. Enter the following commands.

    cd ~
    mkdir efi
    sudo mount -t vfat /dev/sdb1 efi
    sudo mv /boot/efi/EFI/Boot efi/EFI/boot
    sudo mv /boot/efi/EFI/ubuntu efi/EFI/ubuntu
    sudo umount /dev/sdb1
    rmdir efi
    
  6. Update the /etc/fstab file so Ubuntu will know the new location of the Grub boot files. Enter the following command.

    sudo nano /etc/fstab
    

    Find the line with the mount point /boot/efi. Replace the UUID value on this line with with the value recorded in step 4. Exit the editor and save the change.

  7. The installation of Ubuntu replaced the bootx64 file that was first created by the Boot Camp installation. The following commands rectify this replacement. (The bootx64.efi and bootmgfw.efi files used by Windows are the same.)

    sudo mkdir /boot/efi/EFI/Boot
    sudo cp /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi /boot/efi/EFI/Boot/bootx64.efi
    
  8. Restart the Mac and boot back to Ubuntu.

  9. If necessary, restore automatic updates to the previous setting.