This hint is based on several prior hints and comments published earlier (see references at the end), and is proven to work under Tiger.
Before proceeding, please make sure you are familiar with the following terms: virtual memory, swapfile, root, sudo, terminal. You'll also need a separate partition on which to store the swap files.
This hint makes virtual memory start a bit later so that your swap volume is already mounted, thus eliminating the problems stated in referenced hints. If the swap volume fails to mount, then the boot volume will be used.
Let's start by making a backup of /etc/rc. If something goes wrong, you'll be able to boot from CD or single-user mode, start Terminal, and restore the original file):
sudo cp /etc/rc /etc/rc.saved
Now create a new text file with the following contents (replace the word Swap after the equal sign in the first line with the name of your volume:
swapvolume=Swap
RMRF_ITEMS="${swapdir}/swap*"
if [ ! -d /Volumes/${swapvolume}/.Trashes ]; then
swapcount=1
echo "Waiting for ${swapvolume} to mount"
while [ "$swapcount" -le 10 ]; do
sleep 1
if [ -d /Volumes/${swapvolume}/.Trashes ]; then
echo "${swapvolume} mounted after $swapcount seconds"
break
fi
swapcount=`expr $swapcount + 1`
done
fi
if [ -d /Volumes/${swapvolume}/.Trashes ]; then
swapdir=/Volumes/${swapvolume}/.vm
echo "Using ${swapdir} for swapfile"
else
echo "Unable to use ${swapvolume} for swapfile"
fi
Save this file to your Desktop as rc.txt and issue the following commands in terminal:
sudo cp ~/Desktop/rc.txt /etc/rc.swap
sudo chown root:wheel /etc/rc.swap
Now we are ready to edit /etc/rc. Type the following line in your terminal to launch TextEdit as root (you may choose another method of course):
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/rc
Find the line (184):
swapdir=/private/var/vm
Insert these three lines of code after that line:
echo Removing $RMRF_ITEMS
rm -rf $RMRF_ITEMS
if [ -f /etc/rc.swap ]; then . /etc/rc.swap; fi # inserted locally
Now select this entire block of code...
if [ -f /etc/rc.swap ]; then . /etc/rc.swap; fi # inserted locally
if [ "${NetBoot}" = "-N" ]; then
sh /etc/rc.netboot setup_vm ${swapdir}
fi
if [ ! -d ${swapdir} ]; then
echo "Creating default swap directory"
mkdir -p -m 755 ${swapdir}
chown root:wheel ${swapdir}
else
RMRF_ITEMS="${RMRF_ITEMS} ${swapdir}/swap*"
fi
echo Removing $RMRF_ITEMS
rm -rf $RMRF_ITEMS
if [ ${ENCRYPTSWAP:=-NO-} = "-YES-" ]; then
encryptswap="-E"
else
encryptswap=""
fi
/sbin/dynamic_pager ${encryptswap} -F ${swapdir}/swapfile
... and move it down to appear just before this line:
/usr/sbin/update
Save the file, reboot, and enjoy.
ps -wax | grep dynamic_pager -m1
References:
Mac OS X Hints
http://hints.macworld.com/article.php?story=20050601094611565