Created
September 6, 2026 20:16
-
-
Save mass6/63efd0c9c3196ebf6b44f1eedcbdafb4 to your computer and use it in GitHub Desktop.
mount-mac-apfs.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Build apfs-fuse on Ubuntu and mount a Mac APFS container read-only. | |
| # Requires internet access to download packages and source code. | |
| # Usage: bash mount-mac-apfs.sh | |
| # Optional APFS volume index: bash mount-mac-apfs.sh 1 | |
| # The default volume index is 0. A separate Data volume may hold user files. | |
| # Source and limitations: https://github.com/sgan81/apfs-fuse | |
| # This driver is read-only and experimental; some compression is unsupported. | |
| # Enter FileVault passwords only at the driver's terminal prompt, never here | |
| # or in a public Gist. Copy recovered files onto a separate external drive. | |
| set -euo pipefail | |
| volume_index="${1:-0}" | |
| if [[ ! "$volume_index" =~ ^[0-9]+$ ]]; then | |
| printf 'Volume index must be a nonnegative integer.\n' >&2 | |
| exit 1 | |
| fi | |
| lsblk -o NAME,SIZE,FSTYPE,LABEL,MOUNTPOINTS | |
| printf '\nIdentify the APFS partition above; device names can change after reboot.\n' | |
| read -r -p 'APFS partition path (example: /dev/sda2): ' mac_partition | |
| if [[ "$mac_partition" != /dev/* || ! -b "$mac_partition" ]]; then | |
| printf 'That path is not a block device.\n' >&2 | |
| exit 1 | |
| fi | |
| filesystem_type="$(sudo blkid -p -s TYPE -o value "$mac_partition")" | |
| if [[ "$filesystem_type" != apfs ]]; then | |
| printf 'Expected APFS; detected: %s. Stopping.\n' "$filesystem_type" >&2 | |
| exit 1 | |
| fi | |
| mount_path=/mnt/mac | |
| if mountpoint -q "$mount_path"; then | |
| printf '%s is already mounted. Unmount it before running this script again.\n' "$mount_path" >&2 | |
| exit 1 | |
| fi | |
| sudo apt update | |
| sudo apt install -y build-essential cmake git libfuse3-dev zlib1g-dev libbz2-dev libattr1-dev | |
| build_directory="$(mktemp -d /tmp/mac-apfs-build.XXXXXX)" | |
| git clone --recursive https://github.com/sgan81/apfs-fuse.git "$build_directory/apfs-fuse" | |
| cmake -S "$build_directory/apfs-fuse" -B "$build_directory/apfs-fuse/build" | |
| cmake --build "$build_directory/apfs-fuse/build" -j2 | |
| sudo mkdir -p "$mount_path" | |
| printf '\nMounting read-only. If prompted, enter your old Mac password or recovery key.\n' | |
| sudo "$build_directory/apfs-fuse/build/apfs-fuse" \ | |
| -v "$volume_index" -o allow_other "$mac_partition" "$mount_path" | |
| printf '\nMounted at %s\n' "$mount_path" | |
| printf 'Open Files and browse to that location, or run: nautilus /mnt/mac\n' | |
| printf 'Look for root/Users/your-old-username.\n' | |
| printf 'If you only see system files, you may need another APFS volume index.\n' | |
| printf 'Unmount with: sudo umount /mnt/mac\n' | |
| printf 'Build files are in: %s\n' "$build_directory" | |
| printf 'Copy recovered files to a separate drive and verify them before erasing the Mac disk.\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment