I received a question about creating a RAMFS for Mac OS X’ /tmp folder, so I’ll post my reply here as well.
It’s really simple;
- Open Terminal (Applications -> Utilities), type “sudo su” and enter your user’s password.
 - Create a new file in /Library/LaunchDaemons, like this: “nano -w /Library/LaunchDaemons/com.yeri.ramfs.plist” (you can rename yeri to whatever you like)
 - And insert following content (ctrl+x to save – y – [enter]):
 - create a second file in /var/root/, like this: “nano -w /var/root/ramfs.sh“
 - And insert following content:
 - chmod +x ramfs.sh and reboot. Check in Terminal with “mount” or “df -h” is everything is fine. To hide the disk icon on your desktop, check my old blog post.
 - In case Mac didn’t do so already, you might want to link /tmp to /private/tmp: “rm -r /tmp && ln -s /private/tmp /tmp“.
 - Should be it !
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>com.yeri.ramfs</string>
        <key>ProgramArguments</key>
        <array>
            <string>/var/root/ramfs.sh</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>
#!/bin/bash
ramfs_size_mb=64
mount_point=/private/tmp
ramfs_size_sectors=$((${ramfs_size_mb}*1024*1024/512))
ramdisk_dev=`hdid -nomount ram://${ramfs_size_sectors}`
newfs_hfs -v 'Volatile HD' ${ramdisk_dev}
mkdir -p ${mount_point}
mount -o noatime -t hfs ${ramdisk_dev} ${mount_point}
chown root:wheel ${mount_point}
chmod 1777 ${mount_point}
Leave a Reply…