MacOS – Can I put /tmp and /var/log in a ramdisk on OS X


For non-critical Linux systems, I often move things like /tmp and /var/log to tmpfs to save on some disk writing. I've been doing this for a year or so and if I ever need the logs across reboots, I just comment out a line in /etc/fstab and then start debugging.

In any case, I would like to do the same thing on OS X. I've seen posts on creating a ramdisk for OS X, but I'm looking for a more permanent solution that works on every boot. I always want /tmp and /var/log mounted in a ramdisk, with the ability to turn that off with a bit of command-line editing in vi if I have to.

Best Answer

Here is a script to create ramdisks on OS X. Sorry, it doesn't answer your question. You could use this to build up something that runs on boot and then mounts /tmp and /var/log.


ramdisk_dev=`hdid -nomount ram://${ramfs_size_sectors}`  
newfs_hfs -v 'Volatile' ${ramdisk_dev}  
mkdir -p ${mount_point}  
mount -o noatime -t hfs ${ramdisk_dev} ${mount_point}  

echo "remove with:"  
echo "umount ${mount_point}"  
echo "diskutil eject ${ramdisk_dev}"  

From @salvatore