Accessing APFS on Linux
Converting between filesystems can be fraught with difficulties, especially if one is dealing with a proprietary filesystem. One such system is APFS, the Apple File System, designed by Apple for its devices, introduced originally for macOS Sierra in 2017 and later, iOS 10.3, tvOS 10.2, watchOS 3.2, and all versions of iPadOS, and designed to replace HFS Plus. The question here is how does one access APFS on Linux when a kind individual has provided you, for example, a USB device that has been written with this filesystem. The following are some brief notes on how to do this with Ubuntu Linux 20.04.6 LTS.
The first step is to install libfsapfs-utils, which is a library to access the Apple File System (APFS). One can install this from source if desired for performance or developmental reasons. In this case, we'll just install the package.
$ sudo apt install libfsapfs-utils
The next step is to go into sudo mode and run fdisk, a command to manipulate disk partition table. Understandably, such a command requires privileged access and responsibility. But our purpose here is just to list what devices are present to find the device file of our drive.
$ sudo -s
# fdisk -l
..
Device Start End Sectors Size Type
/dev/sda1 40 409639 409600 200M EFI System
/dev/sda2 409640 15769559 15359920 7.3G unknown
There it is, /dev/sda2
. Now we want to mount it, using fsapfsmount
, which mounts an Apple File System (APFS) volume. The option -f is used to specify the specific file system ("1" is typical), then the dev file and finally where it is being mounted to (in this case, /mnt
.
# fsapfsmount -f 1 /dev/sda2 /mnt
.
From here, it's a simple matter of copying the files over to the directory of choice, in this case the current working directory.
# cp -r /mnt/ACFSPres/ .
After that unmount the device.
# fusermount -u /mnt
Change ownership of the file and directories (because they are currently owned by root) to the user who needs access to them.
# chown -R llafayette:llafayette ACFSPres/