In order not to have a user identifiable path in my demos, I decided to move all my demo code to /code folder. This proved to be a bit more challanging than expected.

Create a root folder on macOS

macOS has System Integrity Protection that prevents the modification of the root file system.

But it makes it possible to create virtual folders via /etc/synthetic.conf

# /etc/synthetic.conf
code

After reboot a read only folder code shows up in ls /.

Create a new APFS volume

I did it in Disk Utility. It is also possible to do it in cli via diskutil partitionDisk.

Mount the volume

To permanently mount the volume use vifs command to add the following line to /etc/fstab

# /etc/fstab
UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX /code apfs rw,auto,nosuid,noatime,owners

Here UUID is the volume UUID which can be viewed in the Disk Utility by right clicking on the volume and selecting Get Info or in cli via diskutil info /dev/diskXsY.

After reboot the volume will be mounted (thanks to the auto option) in the /code folder.