SCHAPPY — 30. November 2016, 17:24

RAM Disk for Mac OS X Sierra (10.12.) and High Sierra (10.13.)

As Apple announced that StartupItems are not longer supported, please find attached an updated version of the RamDisk script of Philipp Klaus making use of the launchctl.

Install

  • Download the code and store it in a file, e.g. ~/MoveTempFoldersToRamDisk.sh
  • Make the file executable, e.g. chmod +x ~/MoveTempFoldersToRamDisk.sh
  • Execute the file to install the launch daemon (/Library/LaunchDaemons/de.schappy.ramdisk.plist) and the RamFS script (/usr/local/bin/RamFS.sh)

Unintall

  • sudo launchctl unload -w /Library/LaunchDaemons/de.schappy.ramdisk.plist
  • Optional remove launch daemon and script (paths see above)

Code of MoveTempFoldersToRamDisk.sh


#!/bin/bash

# +----------------------------------------------------------------------+
# | |
# | Set up Mac OS X >10.12 to store temp folders on RAM disk. |
# | |
# | By Matthieu Schapranow Nov 11, 2017 |
# | |
# | Originally by Ricardo Gameiro
|
# | Changes by Daniel Jenkins |
# |
|
# | and Philipp Klaus
|
# | |
# +----------------------------------------------------------------------+

cat < < "EOF" | sudo tee /usr/local/bin/RamFS.sh > /dev/null
#!/bin/sh
# Create a RAM disk with same perms as mountpoint

RAMDisk() {
mntpt=$1
rdsize=$(($2*1024*1024/512))
echo "Creating RamFS for $mntpt"
# Create the RAM disk.
dev=`hdik -drivekey system-image=yes -nomount ram://$rdsize`
# Successfull creation...
if [ $? -eq 0 ] ; then
# Create HFS on the RAM volume.
newfs_hfs $dev
# Store permissions from old mount point.
eval `/usr/bin/stat -s $mntpt`
# Mount the RAM disk to the target mount point.
mount -t hfs -o union -o nobrowse $dev $mntpt
# Restore permissions like they were on old volume.
chown $st_uid:$st_gid $mntpt
chmod $st_mode $mntpt
fi
}

# Test for arguments.
if [ -z $1 ]; then
echo "Usage: $0 [start|stop|restart] "
exit 1
fi

# Source the common setup functions for startup scripts
test -r /etc/rc.common || exit 1
. /etc/rc.common

StartService () {
ConsoleMessage "Starting RamFS disks..."
RAMDisk /private/tmp 512
RAMDisk /var/run 128
#RAMDisk /var/db 1024
#mkdir -m 1777 /var/db/mds
}
StopService () {
ConsoleMessage "Stopping RamFS disks, nothing will be done here..."
diskutil unmount /private/tmp /private/var/run
diskutil unmount /private/var/run
}

RestartService () {
ConsoleMessage "Restarting RamFS disks, nothing will be done here..."
}

RunService "$1"
EOF
sudo chown root:wheel /usr/local/bin/RamFS.sh
sudo chmod u+x,g+x,o+x /usr/local/bin/RamFS.sh

sudo launchctl unload -w /Library/LaunchDaemons/de.schappy.ramdisk.plist
cat < < EOF | sudo tee /Library/LaunchDaemons/de.schappy.ramdisk.plist > /dev/null
< ?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">
Label
de.schappy.ramdisk
ProgramArguments

/usr/local/bin/RamFS.sh
start

RunAtLoad
EOF

sudo chown root:wheel /Library/LaunchDaemons/de.schappy.ramdisk.plist
sudo chmod 644 /Library/LaunchDaemons/de.schappy.ramdisk.plist
sudo launchctl load -w /Library/LaunchDaemons/de.schappy.ramdisk.plist

No Comments »

RSS feed for comments on this post.

Bisher noch keine Kommentare.

Kommentare verfassen

Sie müssen angemeldet sein, um Kommentare verfassen zu können.