Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SSD Optimizations of Mac OS X 10.6 Operating System
#!/bin/bash
# +----------------------------------------------------------------------+
# | |
# | Mount the root file system / with the option noatime |
# | |
# | By Philipp Klaus <http://blog.philippklaus.de> |
# | Tip found on <http://blogs.nullvision.com/?p=275> |
# | |
# +----------------------------------------------------------------------+
cat << EOF | sudo tee /Library/LaunchDaemons/com.nullvision.noatime.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">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.nullvision.noatime</string>
<key>ProgramArguments</key>
<array>
<string>mount</string>
<string>-vuwo</string>
<string>noatime</string>
<string>/</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
#!/bin/bash
# +----------------------------------------------------------------------+
# | |
# | Set up Mac OS X to store temporary files in RAM rather than on disk.|
# | |
# | By Philipp Klaus <http://blog.philippklaus.de> |
# | |
# | Originally by Ricardo Gameiro <http://blogs.nullvision.com/?p=357> |
# | Changes by Daniel Jenkins |
# | <http://blogs.nullvision.com/?p=357#comment-1140> |
# | |
# +----------------------------------------------------------------------+
cd /System/Library/StartupItems
sudo mkdir RamFS
sudo chown -R root:wheel RamFS
sudo chmod -R u+rwX,g+rX,o+rX RamFS
cat << "EOF" | sudo tee RamFS/RamFS > /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 256
RAMDisk /var/run 64
#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 chmod u+x,g+x,o+x RamFS/RamFS
cat << EOF | sudo tee RamFS/StartupParameters.plist > /dev/null
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Description</key>
<string>RamFS Disks Manager</string>
<key>OrderPreference</key>
<string>Early</string>
<key>Provides</key>
<array>
<string>RamFS</string>
</array>
<key>Uses</key>
<array>
<string>Disks</string>
</array>
</dict>
</plist>
EOF
@elvey

This comment has been minimized.

Show comment
Hide comment
@elvey

elvey Sep 26, 2012

Excellent!

FYI, https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/StartupItems.html implicitly suggests some changes; it says:

Deprecation Note: Startup items are a deprecated technology... use the launchd facility instead...

The /System/Library/StartupItems directory is reserved for startup items that ship with OS X. All other startup items should be placed in the /Library/StartupItems directory. Note that this directory does not exist by default and may need to be created during installation of the startup item...

later:

In OS X v10.4 and later, most low-level services are started with launchd. By the time your startup item starts executing, launchd is running, and any attempt to access any of the services provided by a launchd daemon will result in that daemon starting. Thus, you can safely assume (or at least pretend) that any of these services are running by the time your startup item is called.

elvey commented Sep 26, 2012

Excellent!

FYI, https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/StartupItems.html implicitly suggests some changes; it says:

Deprecation Note: Startup items are a deprecated technology... use the launchd facility instead...

The /System/Library/StartupItems directory is reserved for startup items that ship with OS X. All other startup items should be placed in the /Library/StartupItems directory. Note that this directory does not exist by default and may need to be created during installation of the startup item...

later:

In OS X v10.4 and later, most low-level services are started with launchd. By the time your startup item starts executing, launchd is running, and any attempt to access any of the services provided by a launchd daemon will result in that daemon starting. Thus, you can safely assume (or at least pretend) that any of these services are running by the time your startup item is called.

@elvey

This comment has been minimized.

Show comment
Hide comment
@elvey

elvey Sep 26, 2012

Excellent!

FYI, https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/StartupItems.html implicitly suggests some changes; it says:

Deprecation Note: Startup items are a deprecated technology... use the launchd facility instead...

The /System/Library/StartupItems directory is reserved for startup items that ship with OS X. All other startup items should be placed in the /Library/StartupItems directory. Note that this directory does not exist by default and may need to be created during installation of the startup item...

later:

In OS X v10.4 and later, most low-level services are started with launchd. By the time your startup item starts executing, launchd is running, and any attempt to access any of the services provided by a launchd daemon will result in that daemon starting. Thus, you can safely assume (or at least pretend) that any of these services are running by the time your startup item is called.

elvey commented Sep 26, 2012

Excellent!

FYI, https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/StartupItems.html implicitly suggests some changes; it says:

Deprecation Note: Startup items are a deprecated technology... use the launchd facility instead...

The /System/Library/StartupItems directory is reserved for startup items that ship with OS X. All other startup items should be placed in the /Library/StartupItems directory. Note that this directory does not exist by default and may need to be created during installation of the startup item...

later:

In OS X v10.4 and later, most low-level services are started with launchd. By the time your startup item starts executing, launchd is running, and any attempt to access any of the services provided by a launchd daemon will result in that daemon starting. Thus, you can safely assume (or at least pretend) that any of these services are running by the time your startup item is called.

@qdw

This comment has been minimized.

Show comment
Hide comment
@qdw

qdw Jan 17, 2013

Good stuff! Any clue what the license of the original code was? The links to blogs.nullvision.com redirect to a different site with no info, and there's nothing in the Wayback Machine, either.

Likewise, what's the license for this adaptation? I'm forking it yet again for use in a project, and I want to know what license to use (e.g., I don't want to slap a two-clause BSD license on code that's GPL'ed!)

qdw commented Jan 17, 2013

Good stuff! Any clue what the license of the original code was? The links to blogs.nullvision.com redirect to a different site with no info, and there's nothing in the Wayback Machine, either.

Likewise, what's the license for this adaptation? I'm forking it yet again for use in a project, and I want to know what license to use (e.g., I don't want to slap a two-clause BSD license on code that's GPL'ed!)

@khacpm

This comment has been minimized.

Show comment
Hide comment
@khacpm

khacpm Apr 15, 2014

This script does nothing on my 10.9.2 Mac OS.
Some code deprecated. Please update

khacpm commented Apr 15, 2014

This script does nothing on my 10.9.2 Mac OS.
Some code deprecated. Please update

@albinoz

This comment has been minimized.

Show comment
Hide comment
@albinoz

albinoz Jun 16, 2014

khacpm > SSD Optimizations of Mac OS X 10.6 Operating System

How add more than 1024 Mo ?

albinoz commented Jun 16, 2014

khacpm > SSD Optimizations of Mac OS X 10.6 Operating System

How add more than 1024 Mo ?

@jonaslierschied

This comment has been minimized.

Show comment
Hide comment
@jonaslierschied

jonaslierschied Jan 4, 2015

Dear Philip, do you have an update for OSX Yosemite? The RAM disks have worked fine under OSX Mavericks, but the code does not work in OSX 10.10. Thanks in advance.
Cheers, Jonas

Dear Philip, do you have an update for OSX Yosemite? The RAM disks have worked fine under OSX Mavericks, but the code does not work in OSX 10.10. Thanks in advance.
Cheers, Jonas

@jrnewell

This comment has been minimized.

Show comment
Hide comment
@jrnewell

jrnewell Apr 8, 2015

In case anyone is interested, I tried to modify pklaus's script to be compatible with Yosemite: https://gist.github.com/jrnewell/ef9a6ed1448f041565c7.

jrnewell commented Apr 8, 2015

In case anyone is interested, I tried to modify pklaus's script to be compatible with Yosemite: https://gist.github.com/jrnewell/ef9a6ed1448f041565c7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment