MacOS – How to mount an APFS volume as a user’s home directory

apfsmacosmount

TLDR;
I can mount an APFS volume on /Users/foobar, where foobar is not an actual user, but mounting fails when trying to mount to /Users/newuser, when newuser is an actual user.

BACKGROUND:

I'm trying put my home directory on an encrypted external SSD so that I don't have to use filevault on my boot drive– I need the machine to boot up and autologin so server processes can start up after a power failure. All the gritty details on what I'm trying to do are in this gist, but I will try to discuss the essential points below.

Before actually trying to move my own home folder, I created a Standard user called newuser to experiment with. I removed /Users/newuser and replaced it with a new empty folder. I also created a /Users/foobar folder (no foobar user). When I try to mount either with

sudo diskutil mount

or

sudo mount_apfs

I get errors when trying to mount on /Users/newuser but both commands work with /Users/foobar. Both directories are empty, have the same Unix permissions and ownership, have no ACLs, flags or extended attributes. /Users also appears to have no special properties that are visible to ls.

I also tried mounting on /home instead /Users as suggested here, and when I first created the /home/newusers directory I was able to mount on it, UNTIL I changed newuser's home directory in the Users & Groups Preference Pane. Once it became the official home directory I could no longer mount.

Evidently something in the system (Mojave 10.14.2) is refusing to mount over a user's home folder.
Is there any way around this?

(I just saw a recent question dealing with this but didn't see any new ideas to try)

Best Answer

I found the workaround was to mount the volume on /home and create a subdirectory as my new home directory. As

sudo mount_apfs -o noauto,nobrowse VOLUME_UUID /home
sudo rsync -a /Users/myhome /home

Then change the user's home directory in User & Groups Preference Pane Advanced Options to /home/myhome

I have updated my gist with the complete instructions for mounting an encrypted external drive as a home directory.

UPDATE: After using this for a while I discovered problems with backup software. Notably, Backblaze will not backup custom mount points, and Time Machine will back it up, but the volume is not visible in the restore GUI. In fact, it confusingly displays localsnapshots of the files "underneath" the mount point in /home.

So I caved and just decided to mount the thing in the default /Volumes. I works swimmingly and the gist has all the details.

Oh and by the way, I used Carbon Copy Cloner to copy the home directory. I recommend using that or equivalent (SuperDuper) as opposed to rsync as the developers of these apps are up-to-date on how to copy all the myriad Apple file attributes, extended attributes, ACLs, flags, etc., etc.