how to use ramdisk in your mac

Kiyor | Created: 08-07-12 09:01:15



You can simply use command to create a ramdisk.


diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://512000`

This is 250 MB ramdisk, you can change 512000 to change the volume of the ramdisk. If you want to use ramdisk for your safari cache You can close the safari and run these


rm -rf ~/Library/Caches/com.apple.Safari
mkdir /Volumes/ramdisk/com.apple.Safari
ln -s /Volumes/ramdisk/com.apple.Safari/ ~/Library/Caches/com.apple.Safari

Another app’s caches you can just modify path form the code above.

If you need it runs automatically when you reboot. Create a script like ramedisk.sh and chmod u+x ramdisk.sh


#!/bin/sh
if [ ! -d "/Volumes/ramdisk" ]; then
	diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://512000`
fi
if [ ! -d "/Volumes/ramdisk/com.apple.Safari" ]; then
	rm -rf ~/Library/Caches/com.apple.Safari
	mkdir /Volumes/ramdisk/com.apple.Safari
	ln -s /Volumes/ramdisk/com.apple.Safari/ ~/Library/Caches/com.apple.Safari
fi
if [ ! -d "/Volumes/ramdisk/Google" ]; then
	rm -rf ~/Library/Caches/Google
	mkdir /Volumes/ramdisk/Google
	ln -s /Volumes/ramdisk/Google/ ~/Library/Caches/Google
fi
 
if [ -d "/Volumes/ramdisk/com.apple.Safari" ] && [ -d "/Volumes/ramdisk/Google" ]; then
	echo "Ramdisk is enabled!"
else
	echo "Error"
fi

rc.local file might not work, Mac looks not load rc.local, what I do is append these to terminal login sheel and run terminal when Mac start. You need add a check like if [[ $(tty) = /dev/ttys001 ]]; then ~/ramdisk.sh; fi;

You can also modify this if you need. More information Testing software: Blackmagic Disk Speed Test

10 Bit YUV 4:2:2 PAL Default SSD Default Ramdisk
Disk Write Speed MB/s 180 800
Disk Read Speed MB/s 210 800


Category: none

Tags: Mac