zettelkasten

Search IconIcon to open search
Dark ModeDark Mode

Accessing APFS Volume from Linux

Date: 2 Jul 2021

#post #writing/guide #linux

This post originally appeared on Blog 2.0


For someone wired like me who runs Windows, MacOS, and Linux on the same laptop and from the same SSD (which I don’t suppose there are many), it is very frustrating if a file you want happens to be on another system. Restarting several times just to get a file from one system to another is probably what I prefer not to do.

The operating systems I am using are listed below. It should also work for some similar configuration. (Disclaimer: I dodn’t test them.)

  • MacOS Catalina
  • Ubuntu 20

H2 Step 1: installing apfs-fuse

APFS FUSE is an open-source linux driver for reading Apple’s file systems. It’s not available through apt so we have to compile and install it.

First, install some necessary libraries by running:

sudo apt update
sudo apt install fuse libfuse-dev libicu-dev bzip2 libbz2-dev cmake clang git libattr1-dev

Then download the source code from the repository:

git clone [<https://github.com/sgan81/apfs-fuse.git>](<https://github.com/sgan81/apfs-fuse.git>)
cd apfs-fuse
git submodule init
git submodule update

Compile:

mkdir build
cd build
cmake ..
make

H2 Step 2: fixing fatal errors

Well that didn’t work. The build process threw me two errors, and this is how I fixed it. If you didn’t see any error skip this step

Error 1:

[ 72%] Building CXX object CMakeFiles/apfs.dir/ApfsLib/Sha256.cpp.o
[ 75%] Building CXX object CMakeFiles/apfs.dir/ApfsLib/TripleDes.cpp.o
[ 77%] Building CXX object CMakeFiles/apfs.dir/ApfsLib/Util.cpp.o/home/chaosarium/apfs-fuse/ApfsLib/Util.cpp:36:10: fatal error: zlib.h: No such file or directory
   36 | #include <zlib.h>
      |          ^~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/apfs.dir/build.make:427: CMakeFiles/apfs.dir/ApfsLib/Util.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:198: CMakeFiles/apfs.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

How to fix:

sudo apt-get install libz-dev

Error 2:

Scanning dependencies of target apfs-fuse
[ 87%] Building CXX object CMakeFiles/apfs-fuse.dir/apfsfuse/ApfsFuse.cpp.o/home/chaosarium/apfs-fuse/apfsfuse/ApfsFuse.cpp:31:10: fatal error: fuse3/fuse.h: No such file or directory
   31 | #include <fuse3/fuse.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/apfs-fuse.dir/build.make:63: CMakeFiles/apfs-fuse.dir/apfsfuse/ApfsFuse.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:115: CMakeFiles/apfs-fuse.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

How to fix:

cmake ..
sudo apt install cmake-curses-gui
ccmake .

Navigate to USE_FUSE3, hit enter to turn toggle the option so that reads “OFF”.

Press c to configure, then press g to exit.

now execute make again

H2 Step 3: installation

First you need to move the binaries files into the proper place.

sudo cp apfs-* /usr/local/bin

H2 Step 4: magic (how to use)

To list partititions on your computer:

sudo fdisk -l

It should show you something like this:

Device              Start        End    Sectors   Size Type
/dev/nvme0n1p1       2048     411647     409600   200M EFI System
/dev/nvme0n1p2     413696  391041023  390627328 186.3G unknown
/dev/nvme0n1p3  391041024  659476479  268435456   128G Microsoft basic data
/dev/nvme0n1p4  659476480  660488191    1011712   494M Windows recovery environment
/dev/nvme0n1p5  660488192 1918377983 1257889792 599.8G Microsoft basic data
/dev/nvme0n1p6 1918377984 1937907711   19529728   9.3G Microsoft basic data
/dev/nvme0n1p7 1937907712 2000408575   62500864  29.8G Linux filesystem

Then you need to create a directory where it mounts:

sudo mkdir -p /media/$USERNAME/macos

To mount:

sudo apfs-fuse -o allow_other <partition> /media/<your userame>/macos

Done :D
No more restarting!


Reference:

  1. How to mount macOS APFS disk volumes in Linux - The Ultimate Linux Newbie Guide
  2. fatal error: fuse3/fuse.h No such file or directory - apfs-fuse