Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save KernelGhost/f4cbc61a194ec3640a1f3cc7e9cc34ee to your computer and use it in GitHub Desktop.

Select an option

Save KernelGhost/f4cbc61a194ec3640a1f3cc7e9cc34ee to your computer and use it in GitHub Desktop.
Dual Boot Debian 12 (Bookworm) and macOS Big Sur on a MacBookAir6,1 (11-inch, Early 2014)

Dual Boot Debian 12 (Bookworm) and macOS Big Sur on a MacBookAir6,1 (11-inch, Early 2014)

Author: Rohan Barar
Date: 03/09/2023

Install the rEFInd Boot Manager

The following is based on this guide.

  1. Download rEFInd from here. Choose to download the binary zip file version. Note that the version used at the time of writing was v0.14.0.2.

  2. Disable SIP (System Integrity Protection). This is required to modify the EFI partition.

    1. Reboot into recovery mode (hold Command (⌘) + R on boot).
    2. Run csrutil disable in the terminal.
    3. Reboot.
  3. Install rEFInd in the EFI partition.

    1. Mount the EFI partition.

      sudo mkdir /Volumes/EFI
      sudo mount -t msdos /dev/disk0s1 /Volumes/EFI
    2. Create a new rEFInd folder on the EFI partition.

      cd /Volumes/EFI/EFI
      sudo mkdir REFIND
    3. Copy the contents of the following folders (NOT the folders themselves) into this new folder.

      • refind/drivers_x64/

      • refind/icons/

      • refind/tools_x64/

        sudo cp -r ~/Desktop/refind-bin-0.14.0.2/refind/drivers_x64/ /Volumes/EFI/EFI/REFIND
        
        sudo cp -r ~/Desktop/refind-bin-0.14.0.2/refind/icons/ /Volumes/EFI/EFI/REFIND
        
        sudo cp -r ~/Desktop/refind-bin-0.14.0.2/refind/tools_x64/ /Volumes/EFI/EFI/REFIND
    4. Copy refind/refind_x64.efi and refind/refind.conf-sample into this new folder as well.

      sudo cp ~/Desktop/refind-bin-0.14.0.2/refind/refind_x64.efi /Volumes/EFI/EFI/REFIND
      
      sudo cp ~/Desktop/refind-bin-0.14.0.2/refind/refind.conf-sample /Volumes/EFI/EFI/REFIND
    5. Rename refind.conf-sample to refind.conf.

      sudo mv refind.conf-sample refind.conf
      
    6. Edit refind.conf.

      • Can add default_selection Preboot to set booting into macOS as the default option.
      • Can change timeout 20 to timeout 5 to reduce the timeout to 5 seconds before booting the default selection.
    7. Bless rEFInd.

      sudo bless --mount /Volumes/EFI --setBoot --file /Volumes/EFI/EFI/REFIND/refind_x64.efi --shortform
  4. Enable SIP (System Integrity Protection).

    1. Reboot into recovery mode (hold Command (⌘) + R on boot).
    2. Run csrutil enable in the terminal.
    3. Reboot.

Fixing rEFInd

Note: Whenever you install a new OS or OS updates, one of the operating systems may incorrectly determine that your EFI boot selection is broken and that it 'needs to be fixed'. When this happens, the mac will boot directly into that OS and will skip rEFInd.

  1. Disable SIP.
  2. Restart and hold down Option (⌥). This has the effect of invoking the default bootloader, thereby bypassing the broken EFI settings.
  3. Select the macOS partition to boot from.
  4. In terminal, run the following:
    sudo mkdir /Volumes/EFI
    
    sudo mount -t msdos /dev/disk0s1 /Volumes/EFI
    
    sudo bless --mount /Volumes/EFI --setBoot --file /Volumes/EFI/EFI/REFIND/refind_x64.efi --shortform
  5. Enable SIP.

Create Free Space for Debian

  1. Run diskutil list.

    /dev/disk0 (internal, physical):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      GUID_partition_scheme                        *251.0 GB   disk0
    1:                        EFI EFI                     209.7 MB   disk0s1
    2:                 Apple_APFS Container disk1         250.8 GB   disk0s2
    
    /dev/disk1 (synthesized):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      APFS Container Scheme -                      +250.8 GB   disk1
                                    Physical Store disk0s2
    1:                APFS Volume Apple SSD - Data        54.2 GB    disk1s1
    2:                APFS Volume Preboot                 584.7 MB   disk1s2
    3:                APFS Volume Recovery                624.2 MB   disk1s3
    4:                APFS Volume VM                      1.1 MB     disk1s4
    5:                APFS Volume Apple SSD               15.3 GB    disk1s5
    6:              APFS Snapshot com.apple.os.update-... 15.3 GB    disk1s5s1
    
  2. Consider the amount of space you would like to dedicate to Debian. Ensure you account for the additional space a Swap partition.

  3. Shrink the APFS container to the desired size. In this case, we will shrink the APFS container disk0s2 to a size of 180 GiB. Note that you can specify whether to use gigabytes with g or gibibytes with gi.

    sudo diskutil apfs resizeContainer disk0s2 180gi
  4. Confirm the desired changes have been made using diskutil list.

    /dev/disk0 (internal, physical):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      GUID_partition_scheme                        *251.0 GB   disk0
    1:                        EFI EFI                     209.7 MB   disk0s1
    2:                 Apple_APFS Container disk1         193.3 GB   disk0s2
                        (free space)                         57.5 GB    -
    
    /dev/disk1 (synthesized):
    #:                       TYPE NAME                    SIZE       IDENTIFIER
    0:      APFS Container Scheme -                      +250.8 GB   disk1
                                    Physical Store disk0s2
    1:                APFS Volume Apple SSD - Data        54.2 GB    disk1s1
    2:                APFS Volume Preboot                 584.7 MB   disk1s2
    3:                APFS Volume Recovery                624.2 MB   disk1s3
    4:                APFS Volume VM                      1.1 MB     disk1s4
    5:                APFS Volume Apple SSD               15.3 GB    disk1s5
    6:              APFS Snapshot com.apple.os.update-... 15.3 GB    disk1s5s1
    

Install Debian

  1. Prepare a Debian amd64 install USB.
  2. Restart and hold down Option (⌥). Select EFI Boot.
    • Note: If using Ventoy, ensure the .iso is booted in grub2 mode instead of normal mode.
  3. Once at the GRUB bootloader, add the kernel argument intel_iommu=off. This is required so that the Debian installer can see the internal SSD.
    1. Press e on the keyboard with the Install option highlighted in GRUB. This will open the boot option for editing.

    2. Add intel_iommu=off to the linux entry. For example:

      setparams 'Install'
      
          set background_color=black
          linux   /install.amd/vmlinuz vga=788 intel_iommu=off --- quiet
          initrd  /install.amd/initrd.gz
      
    3. Press F10 to boot using the modified entry.

  4. Partition disks:
    1. Select Manual for the partitioning method.
    2. Select the FREE SPACE on the internal SSD and create an 8GB swap area partition.
    3. Select the remaining FREE SPACE on the internal SSD and create an Ext4 journaling file system at the mount point / named Debian.
    4. Select Finish partitioning and write changes to disk.

First Boot

Temporary Internet

We do not currently have any WiFi drivers installed. Assuming you do not have access to an ethernet-to-thunderbolt adapter, connect your mobile phone via USB to the computer and enable USB Tethering on the phone to share the phone's internet connection with the computer. This worked flawlessly using a Samsung Galaxy S22.

Fix GRUB

We need to edit the GRUB configuration file so that intel_iommu=off does not need to be specified manually at each boot.

  1. Open /etc/default/grub.
  2. Find the line starting with GRUB_CMDLINE_LINUX_DEFAULT. Modify this to include intel_iommu=off. For example:
    GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=off"
    
  3. Run sudo update-grub.

Add Sources

Since Debian was installed without an internet connection, the system lacks a list of sources.

  1. Open /etc/apt/sources.list.
  2. Comment out the first line (starting with deb cdrom:) by appending a # at the start of the line.
  3. Add the following lines to the file:
    deb http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
    deb http://security.debian.org/ bookworm-security non-free contrib main non-free-firmware
    deb http://deb.debian.org/debian/ bookworm-updates non-free contrib main non-free-firmware
    deb http://deb.debian.org/debian/ bookworm-backports main contrib non-free non-free-firmware
    
  4. Run sudo apt update && sudo apt upgrade.

Install the WiFi Driver

sudo apt install broadcom-sta-dkms

Install the Webcam Driver

Note: Although these steps worked for people with the same or similar hardware online, I was unable to get this completely working. The webcam only 'partially' works when using Qt V4L2 test Utility. The video feed is blown out, distorted and completely unusable. Although the webcam is detected as Apple Facetime HD by other applications, they all fail to display the video feed entirely.

  1. Check if the webcam is detected using lspci.

    sudo lspci -v | grep Broad

    Expected output:

    02:00.0 Multimedia controller: Broadcom Inc. and subsidiaries 720p FaceTime HD Camera
        Subsystem: Broadcom Inc. and subsidiaries 720p FaceTime HD Camera
    03:00.0 Network controller: Broadcom Inc. and subsidiaries BCM4360 802.11ac Wireless Network Adapter (rev 03)
    

    Here, the webcam is detected as 720p FaceTime HD Camera.

  2. Create a folder named facetimehd inside /usr/lib/firmware/.

    sudo mkdir /usr/lib/firmware/facetimehd
  3. Place the following inside a new file named install_facetime_camera.sh. This bash script was originally obtained from here.

    #!/bin/bash
    set -e
    
    export CONFIG_MODULE_SIG=n
    export CONFIG_MODULE_SIG_ALL=n
    # For current kernel
    export KERNELRELEASE=$(cat /proc/version | awk '{print $3}')
    
    temp_dir=$(mktemp -d)
    echo "Installing FacetimeHD camera for $KERNELRELEASE"
    cd $temp_dir
    git clone https://github.com/patjak/facetimehd-firmware.git
    git clone https://github.com/patjak/bcwc_pcie.git
    
    cd $temp_dir/facetimehd-firmware
    pwd
    make
    make install
    cd $temp_dir/bcwc_pcie
    pwd
    make
    make install
    rm -rf $temp_dir
    
    if [ ! -d "/etc/modules-load.d" ]; then
      mkdir -p "/etc/modules-load.d"
    fi
    
    cat > "/etc/modules-load.d/facetimehd.conf" << EOL
    videobuf2-core
    videobuf2_v4l2
    videobuf2-dma-sg
    facetimehd
    EOL
    
    
    # Workaround for depmod being skipped above with error:
    # Warning: modules_install: missing 'System.map' file. Skipping depmod
    echo "Generate modules.dep and map files"
    sudo depmod
    
    echo "Adding kernel modules"
    sudo modprobe -r bdc_pci
    sudo modprobe facetimehd
    
    echo "Install complete"
  4. Make the script executable using chmod and run it.

    chmod +x install_facetime_camera.sh
    sudo ./install_facetime_camera.sh

    Expected output:

    Installing FacetimeHD camera for 6.1.0-11-amd64
    Cloning into 'facetimehd-firmware'...
    remote: Enumerating objects: 899, done.
    remote: Counting objects: 100% (14/14), done.
    remote: Compressing objects: 100% (9/9), done.
    remote: Total 899 (delta 5), reused 12 (delta 5), pack-reused 885
    Receiving objects: 100% (899/899), 294.35 KiB | 4.39 MiB/s, done.
    Resolving deltas: 100% (590/590), done.
    Cloning into 'bcwc_pcie'...
    remote: Enumerating objects: 1148, done.
    remote: Counting objects: 100% (65/65), done.
    remote: Compressing objects: 100% (32/32), done.
    remote: Total 1148 (delta 41), reused 46 (delta 33), pack-reused 1083
    Receiving objects: 100% (1148/1148), 415.53 KiB | 5.01 MiB/s, done.
    Resolving deltas: 100% (768/768), done.
    /tmp/tmp.u7XlGZByq0/facetimehd-firmware
    
    Checking dependencies for driver download...
    /usr/bin/curl
    /usr/bin/xzcat
    /usr/bin/cpio
    
    Downloading the driver, please wait...
    
    
    Found matching hash from OS X, El Capitan 10.11.5
    ==> Extracting firmware...
     --> Decompressing the firmware using gzip...
     --> Deleting temporary files...
     --> Extracted firmware version 1.43.0
    
    Copying firmware into '//usr/lib/firmware/facetimehd'
    /tmp/tmp.u7XlGZByq0/bcwc_pcie
    make -C /lib/modules/6.1.0-11-amd64/build M=/tmp/tmp.u7XlGZByq0/bcwc_pcie modules
    make[1]: Entering directory '/usr/src/linux-headers-6.1.0-11-amd64'
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/fthd_ddr.o
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/fthd_hw.o
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/fthd_drv.o
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/fthd_ringbuf.o
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/fthd_isp.o
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/fthd_v4l2.o
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/fthd_buffer.o
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/fthd_debugfs.o
      LD [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/facetimehd.o
      MODPOST /tmp/tmp.u7XlGZByq0/bcwc_pcie/Module.symvers
      CC [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/facetimehd.mod.o
      LD [M]  /tmp/tmp.u7XlGZByq0/bcwc_pcie/facetimehd.ko
      BTF [M] /tmp/tmp.u7XlGZByq0/bcwc_pcie/facetimehd.ko
    Skipping BTF generation for /tmp/tmp.u7XlGZByq0/bcwc_pcie/facetimehd.ko due to unavailability of vmlinux
    make[1]: Leaving directory '/usr/src/linux-headers-6.1.0-11-amd64'
    make -C /lib/modules/6.1.0-11-amd64/build M=/tmp/tmp.u7XlGZByq0/bcwc_pcie modules_install
    make[1]: Entering directory '/usr/src/linux-headers-6.1.0-11-amd64'
      INSTALL /lib/modules/6.1.0-11-amd64/extra/facetimehd.ko
      DEPMOD  /lib/modules/6.1.0-11-amd64
    Warning: modules_install: missing 'System.map' file. Skipping depmod.
    make[1]: Leaving directory '/usr/src/linux-headers-6.1.0-11-amd64'
    Generate modules.dep and map files
    Adding kernel modules
    modprobe: FATAL: Module bdc_pci not found.
    
  5. Manually run sudo modprobe facetimehd since the script fails at sudo modprobe -r bdc_pci. This error can be ignored, as it simply means the kernel did not have the bdc_pci module installed in the first place, so attempting to unload it would obviously fail.

    sudo modprobe facetimehd
  6. Confirm the kernel module has been installed.

    find /lib/modules/$(uname -r) -type f -name '*.ko' | grep facetime

    Expected output:

    /lib/modules/6.1.0-11-amd64/extra/facetimehd.ko
    

    Note: The kernel version may differ.

  7. Install the sensor calibration files. This step is optional, but helps avoid the facetimehd 0000:02:00.0: firmware: failed to load facetimehd/1871_01XX.dat (-2) error on system startup. The instructions to do this were originally obtained from here.

    1. Download Boot Camp Support Software 5.1.5769 from here.
    2. Unzip the downloaded archive.
    3. Navigate to BootCamp/Drivers/Apple/.
    4. Run unrar x AppleCamera64.exe.
    5. Run the following commands to extract the calibration files from AppleCamera.sys:
      1. dd bs=1 skip=1663920 count=33060 if=AppleCamera.sys of=9112_01XX.dat
      2. dd bs=1 skip=1644880 count=19040 if=AppleCamera.sys of=1771_01XX.dat
      3. dd bs=1 skip=1606800 count=19040 if=AppleCamera.sys of=1871_01XX.dat
      4. dd bs=1 skip=1625840 count=19040 if=AppleCamera.sys of=1874_01XX.dat
    6. Confirm the SHA-256 hashes match using sha256sum (e.g. sha256sum '/home/user/Desktop/1871_01XX.dat').
      1. 9112_01XX.dat: 4dd756fa8460d8dc3d78d0d76944b2f92275d1fe9c83181bbc8292c81c005f1a
      2. 1771_01XX.dat: 756c2bb7c5e55b395449e43a0be1cb7c40c37dfc6c2b5abfaffb8ae70ff0fc4b
      3. 1871_01XX.dat: bf36fbde0668ab7e44368b584f9fa64b5945b01003d04c6e3c6f22c0be0fd5f3
      4. 1874_01XX.dat: ffde89e7819ac16a9eb1c8f0bc6dba0e980b508b2022507679d901c190f7cef8
    7. Copy the calibration files to the firmware directory:
      1. sudo cp ~/Desktop/9112_01XX.dat /lib/firmware/facetimehd/
      2. sudo cp ~/Desktop/1771_01XX.dat /lib/firmware/facetimehd/
      3. sudo cp ~/Desktop/1871_01XX.dat /lib/firmware/facetimehd/
      4. sudo cp ~/Desktop/1874_01XX.dat /lib/firmware/facetimehd/
  8. Add facetimehd to /etc/modules.

    sudo nano /etc/modules
  9. Shut down and then power on the system (restarting does not work).

  10. Test the webcam using Qt V4L2 test Utility.

Broken macOS Partition?

The following is based on this and this.

Attempting to delete the Debian and swap partitions from inside macOS can render the entire system unbootable. This happened to me when I wanted to restart the entire installation process. A partition of the correct size with an APFS filesystem was visible using GParted and diskutil, but the system failed to boot from this partition.

This issue appears to be due to the corrupting of the APFS container GUID, and can be fixed from a terminal instance running from a bootable macOS Big Sur recovery USB.

  1. Run gpt -r show /dev/disk0.
    gpt show: disk0: Suspicious MBR at sector 0
        start               size  index  contents
            0                  1         MBR
            1                  1         Pri GPT header
            2                 32         Pri GPT table
            34                 6         
            40            409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
            409640     348937392      2  GPT part - FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF
            349347032  140887687
            490234719         32         Sec GPT table
            490234751          1         Sec GPT header
    

Notice the FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF. For APFS containers, this should be 7C3457EF-0000-11AA-AA11-00306543ECAC.

  1. NOTE DOWN THE ABOVE OUTPUT!!! The start positions, sizes and indices of the partitions will be required later.

  2. Unmount the disk.

    diskutil unmountDisk /dev/disk0
  3. Remove the problematic partition.

    gpt remove -i 2 /dev/disk0
  4. Attempt to recreate the problematic partition by using the parameters noted down in step 2 alongside the correct GUID.

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

If this worked, you are done! If instead you received:

gpt add: disk0: Suspicious MBR at sector 0
gpt add: disk0: error: no space available on device

Then you need to complete a few more steps...

  1. Ensure the disk is still unmounted.

    diskutil unmountDisk /dev/disk0
  2. Destroy the GPT.

    gpt destroy /dev/disk0
  3. Overwrite the MBR with zeroes.

    dd if=/dev/zero count=1 of=/dev/disk0
  4. Create new MBR and GUID partition tables.

    gpt create -f /dev/disk0
  5. Add the previous partitions back using the parameters noted down in step 2 alongside the correct GUID. Here, we first add the EFI partition and then the APFS container.

    gpt add -b 40 -s 409600 -i 1 -t C12A7328-F81F-11D2-BA4B-00A0C93EC93B /dev/disk0
    
    gpt add -b 409640 -s 348937392 -i 2 -t 7C3457EF-0000-11AA-AA11-00306543ECAC /dev/disk0
  6. Reboot the system.

  7. (Optional) Using disk utility, resize the APFS container to reclaim any free space left over after deletion of the Debian partitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment