38

Is there any way to mount APFS partition read only or read/write on Linux or Windows?

Vahid
  • 491

6 Answers6

29

Actually there is a free tool for Linux.

These are my everyday use tools on my hackintosh.

14

Install libfsapfs-utils (tested in Ubuntu 20.04)

  1. Mount APFS partition 3 of /dev/sdd in a directory /mnt

    fsapfsmount -f 1 /dev/sdd3 /mnt

where, -f file_system_index mounts a specific file system

  1. Unmount APFS partition mounted in the directory /mnt

    fusermount -u /mnt

Toto
  • 19,304
ESSPEE
  • 139
  • 1
  • 2
6

How to mount Apple APFS filesystems

1. FOSS tools for Linux

I was able to get two really good tools to work:

  1. linux-apfs-rw is by far the best I got working, but its current limitation is that "Encryption is not yet implemented, even in read-only mode". For my 2015 MacBook Air, that wasn't a big deal, but most if not all modern MacBooks come encrypted now I think, which would pose a problem. To install it on Linux Ubuntu (including on an Ubuntu 22.04 live USB), run the following script. It takes a couple minutes to run on a newly-booted Ubuntu 22.04 live USB, but surely beats retyping this every time you need it!:

    install_linux-apfs-rw.sh:

    #!/usr/bin/env bash
    

    Gabriel Staples

    20 May 2023

    Install a linux kernel APFS Apple Filesystem module to allow us

    to mount and read Apple AFPS drives.

    See my instructions online:

    https://github.com/linux-apfs/linux-apfs-rw/issues/42#issuecomment-1556103266

    install_apfs() { STARTING_DIR="$(pwd)"

    sudo add-apt-repository universe -y
    sudo apt update
    sudo DEBIAN_FRONTEND=noninteractive apt install -y \
        linux-headers-$(uname -r) \
        git \
        gcc \
        g++ \
        cmake \
        make \
        ncdu
    
    mkdir -p ~/dev
    cd ~/dev
    git clone https://github.com/linux-apfs/linux-apfs-rw.git
    cd linux-apfs-rw
    time make
    sudo modprobe libcrc32c
    sudo insmod apfs.ko
    
    cd "$STARTING_DIR"
    
    echo "Done installing linux-apfs-rw kernel module"\
         "to allow you to mount and read Apple APFS filesystems!"
    

    }

    install_all() { time install_apfs "$@" }

    Determine if the script is being sourced or executed (run).

    See:

    1. "eRCaGuy_hello_world/bash/if__name__==__main___check_if_sourced_or_executed_best.sh"

    1. My answer: https://stackoverflow.com/a/70662116/4561887

    if [ "${BASH_SOURCE[0]}" = "$0" ]; then # This script is being run. name="main" else # This script is being sourced. name="source" fi

    Only run main if this script is being run, NOT sourced (imported).

    - See my answer: https://stackoverflow.com/a/70662116/4561887

    if [ "$name" = "main" ]; then time install_all "$@" fi

    Mark it executable, and run it:

    chmod +x install_linux-apfs-rw.sh
    ./install_linux-apfs-rw.sh
    

    What's really nice about this tool is that it works with the normal mount command, so clicking on the APFS disk in your GUI file manager automatically mounts and opens it!

    I've asked Parted Magic to install linux-apfs-rw and apfs-fuse into Parted Magic as part of the default image, in this private forum post here: https://partedmagic.com/forums/viewtopic.php?p=8936#p8936. We'll see if they do this. Hopefully they do!

  2. apfs-fuse. This tool installed easily, and allowed me to read the files, but du would show all files on the mounted APFS drive as 0 bytes. I don't know why. I opened an issue here: https://github.com/sgan81/apfs-fuse/issues/180

    Here are my installation and usage instructions, again, on a fresh Ubuntu 20.04 or 22.04 live USB:

    How to build apfs-fuse on a fresh Ubuntu 20.04 live USB

    # See: https://askubuntu.com/a/227788/327339
    sudo add-apt-repository universe
    

    sudo apt install ncdu

    see my comment: https://github.com/sgan81/apfs-fuse/issues/101#issuecomment-1547206616

    sudo apt install fuse libfuse3-dev bzip2 libbz2-dev cmake gcc g++ git libattr1-dev zlib1g-dev

    git clone https://github.com/sgan81/apfs-fuse.git cd apfs-fuse git submodule update --init --recursive mkdir build cd build cmake .. time make

    ./apfs-fuse -h

    mount

    mkdir -p ~/mount/macbook sudo ./apfs-fuse /dev/sda2 ~/mount/macbook/

    unmount

    sudo umount ~/mount/macbook

    And to view the mounted files as root via the default Ubuntu nautilus file manager:

    sudo nautilus /home/ubuntu/mount/macbook/
    

    The cool thing about this tool is that once I built it, even if building it on my main Linux machine, using it on an Ubuntu live USB, or even on a Parted Magic boot disk, was as simple as copying over the executable!

    It would just run.

That's it for the free and open source tools I was able to get to work, and I tried really flippin' hard on this, probably spending 1 full week and 70 or so hours on it.

2. Paid tools for Windows or Linux

In the future, if I need a tool to work, and I don't want to waste my time, and if one of the above two tools doesn't work immediately (ex: on an encrypted APFS filesystem), I think I'll just fork out the $40 and be done!

  1. For Linux: $40 for personal use: APFS for Linux by Paragon Software --> click "Buy now." It's probably worth it.
  2. For Windows: the trial is free, otherwise it's $50 for personal use: APFS for Windows by Paragon Software --> click "Download" for the trial version, or "Buy now" to buy.

They have business licenses too. I'll let you find the links from there.

The APFS ecosystem of tools

The maker of linux-apfs-rw was kind enough to help me understand the various tools available, here:

I think it would be nice to have an "alternatives" section in the readme

I guess I can do that eventually. For now I'll tell you here quickly:

https://github.com/sgan81/apfs-fuse

This is a fuse driver, not a kernel driver. So it's probably more portable, but it's also much slower. Unlike mine it also supports encryption, but it's read-only and has no plans for write support. Writes take much more work to implement than reads, so that's a big selling point for both my driver and the Paragon one.

https://github.com/libyal/libfsapfs

I've never used this one (though I did get some layout information from the author's work). The first obvious difference is that it's a library. So again, more portable than mine, and it can be built into other tools if that's what you want. I think it includes a way to mount via fuse, so it's similar to the previous one in that regard.

Assuming the README is up to date, it seems to be missing support for snapshots and several compression algorithms, which are all supported in my driver (and also in apfs-fuse, I believe). I don't know where it stands in some stuff it doesn't mention, like sealed volumes. I'm guessing those are not implemented. It does support encryption though.

Like apfs-fuse, this one is also read-only, and there are no plans for write support as far as I can see.

https://www.paragon-software.com/us/home/apfs-linux/

The main disadvantage of this one is that it's paid and closed-source. I've never used it (I'm assuming it's expensive?), so I can't talk about its quality, sorry. It's probably much more complete than mine, and they don't use the 'experimental' disclaimer like I do, so they must be very confident that the writes work correctly. Nobody likes to lose data though, and we don't know much about its development process, so if you are interested in this option you should talk to other customers and see if it's reliable.

See also

  1. If trying to back up stuff from a MacBook, using a Linux live USB booted on the Mac, I recommend the exFAT filesystem, but it's a bit tricky. Here are some answers I wrote for this project that you'll need:
    1. Which filesystem to use for Windows, Mac, and Linux?
    2. How to format an exFAT filesystem on Linux with the desired cluster size to tune your selection along the tradeoff curve between speed and disk usage
    3. Best rsync settings for copying and mirroring to or from FAT and exFAT filesystems
    4. [article on my website] exFAT filesystem speed and disk usage based on cluster size
  2. [article on my website] How to repair your MacBook when it won’t boot
3

There is a dedicated linux-apfs driver, which even has experimental write support: https://github.com/linux-apfs

If you are on Arch Linux or a derivative, you can install it from the AUR.

2

I didn't test it myself, but it seems that a commercial solution is available (currently read-only):

https://backstage.paragon-software.com/business/apfs-linux/

The page doesn't say much, not even the price, though.

Marcelo
  • 177
0

Paragon now has driver with full Read/Write support:

https://www.paragon-software.com/home/apfs-linux/

(it's not free though)