Some Linux users, especially those who have experience with Gentoo Linux, usually want some portion of their systems mounted as tmpfs. tmpfs will only keep the files in the system’s memory and is convenient for us to throw away files on system reboot. I am definitely one of the fans of tmpfs because tmpfs helps me keep some software from shitting on my computer.

However, when it comes to macOS, mounting a tmpfs seems to be a little bit complex. When I opened my new Macbook, and put “mount tmpfs on macOS” on Google, some results showed up. what i googled The answers told me that what I can do is to create a virtual ramdisk and format the ramdisk to a normal filesystem, or rather use FUSE implementations. What a shame! Is macOS such a bad OS that does not support tmpfs?

Commandline Tools in macOS

After doing some research, at least macOS does not mess up things – at least this time. Just type mount in your command line, and let zsh list all the possibilities, and we will have

[email protected] ~ $ mount
mount           mount_afp       mount_cddafs    mount_fdesc     mount_lifs      mount_smbfs     mount_virtiofs
mount_9p        mount_apfs      mount_devfs     mount_ftp       mount_msdos     mount_tmpfs     mount_webdav
mount_acfs      mount_cd9660    mount_exfat     mount_hfs       mount_nfs       mount_udf       
 [email protected] ~ $ which mount_tmpfs

There existed mount_tmpfs, which is just what we need for mounting a tmpfs. The man page told me that

     The mount_tmpfs utility first appeared in macOS 11.

At least for those Apple Silicon Macbooks, mount_tmpfs must exist on the system.

Does It Work?

It works like a charm.


[email protected] /tmp $ mkdir mpvcache && sudo mount_tmpfs -o noowners -s 2g mpvcache
 [email protected] /tmp $ mount|grep mpvcache
tmpfs on /private/tmp/mpvcache (tmpfs, local, noowners)

I got a two-gigabyte-sized tmpfs for saving the output of mpv. mount_tmpfs really eases my mind.