Note on this question having a duplicate: My question happens to be an answer to the question linked-to as being a duplicate. However the answers on that question to NOT answer my question here.

I'm setting up a new server that has 24 GB of RAM. One of the many ways I'm taking advantage of that, is by storing some heavily used files on a RAM disk. The idea is a startup script creates the disk, and copies the files to it, a shutdown script copies the files off the RAM disk and back to the HDD at shutdown time, and a backup script runs periodically to make a copy of the RAM disk.

The current server I'm setting up is running 10.11.6.

The script I use to create the RAM disk works, but you'll notice the sleep 10 at the top. It only works if you include that. If you don't include that line, the script will create and fill the ram disk, but it won't be mounted. The diskutil mount ... line will do nothing. Once the system is booted, you can manually mount the unmounted RAM disk and there are all the files ready to go, but that's not going to work.

It would seem that some system service is required for mounting the RAM disk, and is not ready yet when LaunchD runs this startup script. But it's in /Library/LaunchDeamons so you'd think all of the system stuff would be up and running by the time it gets to my script?

function create_ramdisk()
    sleep 10

    ## make a ram disk that is approximaly 4GB in size
    DISK_ID=$(/usr/bin/hdiutil attach ram://8000000 -notremovable -nomount)
    /usr/sbin/diskutil erasevolume HFS+ "webfolder" $DISK_ID
    /usr/sbin/diskutil mount $DISK_ID

    ## copy contents of the ramdisk backup to the ramdisk
    cp -R /webfolder-backup/ /Volumes/webfolder/

    ## permissions stuff
    chown -R me /Volumes/webfolder/
    chmod -R 777 /Volumes/webfolder/

Ram disks aren't very popular these days, so it's hard to find info on them. I'd like to be able to create and mount mine without the delay. Ideally, if I knew what service was needed, I could wait for it to be available and then immediately create the RAM disk. But I don't know how to determine that.

  • 1
    Some parts of your question doesn't make sense. If the RAM disk isn't mounted, it is impossible to fill it up with files. So either you're incorrect in saying that it is not mounted, or you're incorrect in determining that it has been filled up with files. Please elaborate on both points. Check for mounts with the "mount" command in the Terminal. Regarding the "filling up" part, remember that the folder can be filled up with files even if the disk is not mounted - then the folder would just be on the hard drive (or whatever it is) instead. Have you tried saving the script output to a logfile?
    – jksoegaard
    Mar 7, 2018 at 23:48
  • You are right that it makes no sense that my script is copying files to an unmounted disk... and yet, it does. On boot, the ram disk is definitely not mounted. If I mount it with Disk Utility.app, it shows up and has the proper files already copied to it. I suppose it's possible my script makes it, mounts it, loads it, then the system instantly unmounts it for some reason. I have no clue what would cause that, or how you would even test to verify it. It's definitely unmounted by the time the gui user logs in.
    – l008com
    Mar 8, 2018 at 11:11
  • No, it doesn't. It is impossible to copy files to an unmounted disk like that. So you need to be looking at other possibilities - add logging to debug your issue.
    – jksoegaard
    Mar 8, 2018 at 14:14
  • Can you suggest a specific kind of logging that might help. I've logged the results of each individual command and there was nothing helpful or unusual shown.
    – l008com
    Mar 8, 2018 at 20:32
  • The idea is to show the log output here for others to help you... without any information, there's nothing to go on for others.
    – jksoegaard
    Mar 8, 2018 at 21:59


Browse other questions tagged .