profile picture

macOS: File vs file - switching to a case-insensitive filesystem for my code

October 30, 2024 - macos

Since moving to macOS for my mobile work, found extremely frustrating that by default, macOS allows File and file be the same thing, leading to issues when deploying or working with Linux.

Here is how I handle it without having to format and re-install the entire OS, something Apple hasn't made easier in newer Apple Silicon devices.

1. Creating a case-insensitive volume

Let's add a volume for my code:

$ diskutil apfs addVolume disk3 "Case-sensitive APFS" luis-repos

We will obtain the identifier of the new volume by doing:

$ VOL_ID=$(diskutil info luis-repos | awk '/Identifier\:.*/ {print $3}')
$ VOL_UUID=$(diskutil info luis-repos | awk '/Volume UUID\:.*/ {print $3}')

You can inspect them:

$ echo $VOL_ID
disk3s7

$ echo $VOL_UUID
C359E755-B401-4727-B577-505790157AA8

2. Mount the new volume

This new volume is mounted automatically under /Volumes, but we want it relative to our home directory (Eg. ~/repos):

$ diskutil unmount $VOL_ID

$ mkdir -p ~/repos

$ diskutil mount -mountPoint $HOME/repos $VOL_ID

3. Make the mount point change persist between reboots

Starting with macOS Ventura, this change is not enough. If you restart your computer, the volume is not longer under ~/repos and needs to be manually mounted again.

For that, we need to create /etc/fstab file and store in it the UUID of the volume an the expected mount point:

$ sudo touch /etc/fstab

$ echo "UUID=$VOL_UUID $HOME/repos apfs rw 1 2" | sudo tee -a /etc/fstab

Verify the contents of /etc/fstab before rebooting:

$ cat /etc/fstab
UUID=C359E755-B401-4727-B577-505790157AA8 /Users/luis/repos apfs rw 1 2

Now you can safely reboot your computer and clone your code repositories in a case-sensitive file system 😊

Enjoy! ❤️