MacOS Home Directory on SD Card

how to seamlessly integrate an SD card into MacOS to increase storage of your aging MacBook



Introduction

I have a middle aged MacBook Pro 2005. It is a perfect laptop in many ways: magnetic charging, pleasant keyboard, good number of ports, real function keys. All these features make it a joy to use but are missing in the latest generation of Apple laptops, therefore I have refrained from upgrading for years. Perhaps one day when Apple comes to their senses and produces a functional equivalent, but not today.

Naturally by now (2021) the laptop shows some age: it still looks perfect and unblemished but 8GM of RAM is somewhat small by today's standards. Worse, the 128GB disk is certainly insufficient (flash drives were quite expensive when I bought it). Yet my applications are getting larger and there is an ever growing amount of user data. Xcode 11 is a 9GB monster, where do I find the space for the rest of my data?

One invaluable feature of my laptop is an SD card slot. I have tried several ways to add more storage with a card - they have become reasonably priced even for the largest of capacities. Ultimately have I settled on a 1TB SanDisk card inside a BaseID adapter for something that looks and works as if my MacBook simply had a larger drive. This guide provides instructions for a seamless integration of an SD card into MacOS file system which will give you quite a few more years of useful life from your gracefully aging MacBook.

Concept

If you examine your drive usage with sudo du -sh /* you will realize that most space is taken up by the Users directory. Some of that are you files but majority is taken up by the Library folder where your applications write their data: your preferences, caches, mail, browsing history, development builds... you name it, anything your programs produce and do not want you to see goes here. Sadly it is rarely cleaned up (e.g. Xcode leaves literally gigabytes of past builds behind in its Developer directory). How difficult is it to move just the Users to a larger drive?

A little of bit of research proves it is trivial to move a user's home directory to another location. Apple HT201548 provides instructions for renaming a user account but also hints (albeit does not discuss) how to change its path. A simple solution but the minimalist in me disliked having a second drive dangling on my desktop. Additionally MacOS unmounts SD card when going to sleep and does not always re-mount it on wake, so the user looses the home directly, which is catastrophic.

All UNIX operating systems allow mounting a drive on a specific root file system directory and MacOS is no exception. We can mount an SD card onto Users while keeping the OS on its default drive. But there are a couple of complications with this appoach. First is the System Integrity Protection, which disallows mounting onto home directories and must be disabled. The second is file ownership: the OS will apply the mount process owner to all files within the mounted directory, which is not that of a specific user. Mounting the card onto a specific user's home directory instead allows us to specify the desired ownership. APFS, the preferred file system for flash storage, supports explicit owner and group via its mount options (see man mount_apfs).

Apple never intended SD card slot as a permanent storage, therefore a special adapter is required to eliminate protrusion and accidental removal. There are several aesthetically pleasing products for seamless physical integration of micro SD cards into MacBooks. I use BaseQI which accepts third party micro-SD cards, but there are also others that work equally well. Beware that SD card adapters are specific for different laptop models since sizes vary slightly.

The reader is strongly advised to use quality brand name SD cards since cheap products have poor longevity. I have had good experience with Delkin, SanDisk and Samsung cards. With flash storage you always get what you pay for: more expensive cards of equivalent capacity have higher speeds and longer lifespans.

Finally, the file paths in this tutorial apply to MacOS Mojave, still my preferred OS. Going forward Catalina and Big Sur have significantly changed OS volume structure. Reader on those OS' be ware, you will need to adjust your paths accordingly.

Instructions

1. Disable SIP

As mentioned previously MacOS System Integrity Protection must be disabled in order to mount external volumes onto /Users directory.

2. Login as administrator

In order to manupulate your own data your Mac should always have a secondary privileged management user account. Since root is disabled by default I usually create administrator with administrative permissions and then a regular user account for myself, e.g. johndoe.

3. Prepare SD card

Format your SD card as a single APFS volume.

4. Add fstab mount

The last step is to add a static entry into fstab to mount the card onto the desired user home directory. Do note that this step will make all existing files in your user directory inaccessible: the files will remain on the original disk but become obscured by the mounted SD card. This is a good time to copy your entire user directory elsewhere with cp -prv /Users/johndoe .... Reverting this step restores the original content of the user directory.

5. Verify

Once your MacBook restarts you can login with your own user account. If you did not copy your existing files onto the new location on SD card, which this guide does not explain and leaves for the reader as an exercise, then your user directory will be empty. This will cause MacOS to believe you are logging in for the first time and launch the user setup wizard: finish it as usual.

Finally confirm SD card mount by opening the Terminal and executing df: among its listed devices you should see your card mounted onto your home directory like so:

Filesystem    512-blocks   Used        Available   Capacity   iused   ifree        %iused   Mounted on /dev/disk3s1  1999339440   266969016   1731961560  1%         91353   922337203    0%       /Users/johndoe

If all went well then your new user directory has as much space as the SD card you installed. Your system drive remains unchanged. If you are happy with the results then the only remaining tasks are to copy your old files into your new user directory and clean them up from the system drive.