gatorparrots
~departed~
Many techniques were developed for moving the swap directory in OS X 10.1.x and several applications were even written for that expressed purposes. None of those techniques or applications work very cleanly in OS X 10.2.x (resulting in .vm 1 or duplicate mounts and other oddities); but that's okay, because moving the swap file in Jaguar is easier than it has ever been. [No fstabs, no StartupItems, etc.]. This technique merely requires the editing of a single system file to make the configuration change.
The first step is to back up your /etc/rc, as we will be editing it and want to preserve a backup copy to fallback on in case things go awry:
sudo cp -p /etc/rc /etc/rc.default
Here is the relevant latter half of /etc/rc, which is all that needs to be edited to move the swap location in Jaguar:
Upon the next reboot, first confirm that the volume has mounted successfully with df:
WARNING: Do not execute this command until AFTER rebooting (per the instructions). You are asking to crash your Mac hard if you remove active swap files in use by the OS. It will very likely result in a kernal panic if you do.
The first step is to back up your /etc/rc, as we will be editing it and want to preserve a backup copy to fallback on in case things go awry:
sudo cp -p /etc/rc /etc/rc.default
Here is the relevant latter half of /etc/rc, which is all that needs to be edited to move the swap location in Jaguar:
You might think that changing swapdir=/private/var/vm is all you need to do, but of course Apple didn't make it that easy on us! Not only do you have to change the location of the swapdir by changing the argument, but you also have to move the relevant VM section to the end, just before the exit 0, in order to allow for the pre-heat and other essential sections to run first; also we'll add a mount -a command for an extra margin of safety, just before establishing the swap location (in the example below, the swap directory is moved to a separate partition, /Volumes/.vm:(... more precedes this portion of the script; this is just the latter half)
##
# update flushes the cached blocks from the filesystem using
# the sync system call every 30 seconds. This ensures the
# disk is reasonably up-to-date in the event of a system crash.
##
update
##
# Start the virtual memory system.
##
ConsoleMessage "Starting virtual memory"
swapdir=/private/var/vm
if [ "${netboot}" = "1" ]; then
sh /etc/rc.netboot setup_vm ${swapdir}
fi
# Make sure the swapfile exists
if [ ! -d ${swapdir} ]; then
ConsoleMessage "Creating default swap directory"
mount -uw /
mkdir -p -m 755 ${swapdir}
chown root:wheel ${swapdir}
else
rm -rf ${swapdir}/swap*
fi
dynamic_pager -H 40000000 -L 160000000 -S 80000000 -F ${swapdir}/swapfile
##
# Start daemon to fix incorrectly-prebound binaries
##
if [ -x /usr/libexec/fix_prebinding ]; then
/usr/libexec/fix_prebinding
fi
##
# Clean up and reset files and devices.
##
. /etc/rc.cleanup
##
# Early start for any startup items for performance reasons
##
configd
##
# pre-heat support for working set profiles
##
appprofiledir=/private/var/vm/app_profile
if [ ! -d ${appprofiledir} ]; then
if [ -f ${appprofiledir} ]; then
mv -f ${appprofiledir} "${appprofiledir}_"
fi
mkdir -p -m 711 ${appprofiledir}
chown root:wheel ${appprofiledir}
fi
##
# Insert BootCache prefetch tag
##
if [ "${SafeBoot}" != "-x" -a -x "${BootCacheControl}" ]; then
${BootCacheControl} tag
fi
##
# Start System Services
##
# Set language from CDIS.custom - assumes this is parse-able by sh
. /var/log/CDIS.custom
export LANGUAGE
SystemStarter -g ${VerboseFlag} ${SafeBoot}
exit 0
(If you're very daring, you can try out different pager settings, but I don't necessarily recommend it, unless you are trying to squeeze every drop of performance out of a server machine or something. Apple has given us good general defaults in this regard. Change them at your own risk.)(... more precedes this portion of the script; this is just the latter half)
##
# pre-heat support for working set profiles
##
appprofiledir=/private/var/vm/app_profile
if [ ! -d ${appprofiledir} ]; then
if [ -f ${appprofiledir} ]; then
mv -f ${appprofiledir} "${appprofiledir}_"
fi
mkdir -p -m 711 ${appprofiledir}
chown root:wheel ${appprofiledir}
fi
##
# Insert BootCache prefetch tag
##
if [ "${SafeBoot}" != "-x" -a -x "${BootCacheControl}" ]; then
${BootCacheControl} tag
fi
##
# Start System Services
##
# Set language from CDIS.custom - assumes this is parse-able by sh
. /var/log/CDIS.custom
export LANGUAGE
SystemStarter -g ${VerboseFlag} ${SafeBoot}
##
# Start the virtual memory system.
##
ConsoleMessage "Starting virtual memory"
swapdir=/Volumes/.vm
if [ "${netboot}" = "1" ]; then
sh /etc/rc.netboot setup_vm ${swapdir}
fi
# Make sure the swapfile exists
if [ ! -d ${swapdir} ]; then
ConsoleMessage "Creating default swap directory"
mount -uw /
mkdir -p -m 755 ${swapdir}
chown root:wheel ${swapdir}
else
rm -rf ${swapdir}/swap*
fi
dynamic_pager -H 40000000 -L 160000000 -S 80000000 -F ${swapdir}/swapfile
exit 0
Upon the next reboot, first confirm that the volume has mounted successfully with df:
And then run an ls /Volumes/.vm for good measure to confirm the swapfiles are being written to that partition:gatorparrots% df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/disk0s2 40018068 31444868 8317200 79% /
devfs 1 1 0 100% /dev
fdesc 1 1 0 100% /dev
<volfs> 512 512 0 100% /.vol
/dev/disk2s9 9424512 172944 9251568 2% /Volumes/.vm
If everything looks good, you should be able to sudo rm -f /private/var/vm/swap* to clear the old swap files.gatorparrots% ls /Volumes/.vm
total 78136
0 drwxrwxrwx 9 gator staff 306 Jan 19 13:07 ./
0 drwxrwxrwt 7 root wheel 238 Jan 19 16:58 ../
0 d-wx-wx-wx 3 root staff 102 Dec 26 13:01 .Trashes/
4 -rw-r--r-- 1 root staff 1024 Dec 26 13:00 Desktop DB
4 -rw-r--r-- 1 root staff 2 Dec 26 12:59 Desktop DF
0 drwxrwxrwt 4 gator staff 136 Jan 9 14:54 Temporary Items/
78128 -rw------T 1 root staff 80000000 Jan 19 13:07 swapfile0
WARNING: Do not execute this command until AFTER rebooting (per the instructions). You are asking to crash your Mac hard if you remove active swap files in use by the OS. It will very likely result in a kernal panic if you do.