How to mount a RAM disk on startup? I'm trying to mount a RAM disk on startup with this:

/Users/Aram/Development/Tools/ramdisk.sh

diskutil erasevolume HFS+ "RamDisk" `hdiutil attach -nomount ram://800000`


com.aram.ramdisk.plist

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
    &lt;dict&gt;
        &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;com.aram.ramdisk&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
            &lt;string&gt;/bin/sh&lt;/string&gt;
            &lt;string&gt;/Users/Aram/Development/Tools/ramdisk.sh&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
    &lt;/dict&gt;
&lt;/plist&gt;


And then running:


sudo chown root:wheel /Library/LaunchDaemons/com.aram.ramdisk.plist
sudo launchctl load -w /Library/LaunchDaemons/com.aram.ramdisk.plist


But I get these in the console:

1/08/12 1:29:25.982 PM fseventsd[64]: could not open &lt;&lt;/Volumes/RamDisk/.fseventsd/fseventsd-uuid&gt;&gt; (No such file or directory)
1/08/12 1:29:25.982 PM fseventsd[64]: log dir: /Volumes/RamDisk/.fseventsd getting new uuid: 102D7293-F1F1-4640-AA50-D547C365339F

1/08/12 1:29:24.561 PM sudo[1193]:     Aram : TTY=ttys000 ; PWD=/Library/LaunchDaemons ; USER=root ; COMMAND=/bin/launchctl load -w /Library/LaunchDaemons/com.aram.ramdisk.plist

1/08/12 1:40:17.052 PM com.apple.launchd[1]: (com.aram.ramdisk) Throttling respawn: Will start in 8 seconds


It works if I set KeepAlive to true, but then it creates a RAM disk every 10 seconds.

Is there a way to delay the script for 10 seconds before running?
You can delay the execution of the diskutil command in your ramdisk.sh script by prepending the line sleep 10.

Sleep suspend the execution for an interval of time, in seconds.

Your new ramdisk.sh becomes:

sleep 10
diskutil erasevolume HFS+ "RamDisk" `hdiutil attach -nomount ram://800000`


Update#1: launching the ramdisk.sh every 10 seconds and only creating the RAM disk when it is not there, is a workaround. See this example script for such a conditional check:

sleep 10
RD=RamDisk
if [ ! -e "/Volumes/$RD" ];  then
    diskutil erasevolume HFS+ "$RD" `hdiutil attach -nomount ram://800000`
fi


Your error might be caused because /Volumes is not already created in the boot process at the moment your launchd job is executed. Thefore you could first check for the existence of /Volumes before even further executing the script, like:

if [ -e "/Volumes" ];  then
    RD=RamDisk
    if [ ! -e "/Volumes/$RD" ];  then
        diskutil erasevolume HFS+ "$RD" `hdiutil attach -nomount ram://800000`
    fi
fi


And when the creation succeeds you might want to unload your com.aram.ramdisk.plist from launchctl until the next boot.