This is a fairly old hint, but it bears updating for Panther, since previous methods either just plain don't work or fail after a forced reboot (Control - Command - Power Key) ... *and* once they fail, they never work again no matter how many normal reboots you do!
I want to emphasize this point before before I go on. "Panther-ready" utilities such as Xupport 2.0 b1 allow moving the swap, but fail on a forced reboot. And my original hint submission also failed after a few days of solid performance. This was due to my Swap volume overflowing (a 5 GB partition just didn't cut it!). And in both cases, I could not re-establish vm use of the Swap partition without heavy duty human intervention on my part! That said, let's go ahead change some system files! :-)
[robg adds: Read the rest of the hint for the how-to, which I have not tested. As with anything like this that modifies system files, please create a backup of your critical files before you start, just in case!]The change now requires editing two system files instead of just one: /etc/rc and /etc/fstab. Oh, and as before, if you mess up /etc/rc, you can render your computer unbootable. That's two warnings now, so if you're even vaguely faint of heart or haven't backed up your hard drive in the last twenty minutes ... let the buyer beware!)
I have already created a separate partition named "Swap" and ... yep! ... I'll use that for the system swap files. Note that I have Journaling turned off for this partition. In order to mount this partition reliably, we need to get the device number. In the Terminal, execute the following command:
% df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/disk0s3 19477312 6994736 12287804 37% /
devfs 1 1 0 100% /dev
fdesc 1 1 0 100% /dev
<volfs> 512 512 0 100% /.vol
/dev/disk0s7 5300848 79204 5221644 2% /Volumes/Swap
My Swap volume, named under the Mounted On column, is associated with the device /dev/disk0s7 which appears under the Filesystem column. Make sure to check your own, because my device in the Filesystem column will not be the same as yours!
Before we start editing, let's save off the two files we're going to change. As a rule, I always save original system files in the directory where I found them, just in case I have to access them via single user mode. Here's what I do:
% cd /etc
% sudo /bin/cp rc rc.save
% sudo /bin/cp fstab fstab.save
Now for the first -- and less dangerous -- change. Add the Swap volume to the file system mount table.
% sudo /usr/bin/vi /etc/fstab
Note that the every line in the file is commented out (ie does nothing). Place the following at the very end:
LABEL=Swap /Volumes/Swap hfs rw
The first entry is the name of the volume, and the second is where it will be mounted (OS X puts every mounted volume in /Volumes). The third entry means I formatted my Swap volume as HFS+ (note the plus here, but not in the entry!). And, finally, I want the volume mounted as read/write. Use :wq! to save your changes. Ready or not (okay, *only* if you're ready!) ... let's change the rc boot script.
% sudo /usr/bin/vi /etc/rc
Scroll down to the following chunk of code:
echo "Starting virtual memory"
swapdir=/private/var/vm
if [ "${netboot}" = "1" ]; then
...
You want to replace the following line...
swapdir=/private/var/vm
...with the following large chunk of code. Careful! You MUST insert your own device number that you found using the df command above. See the comment in the code below for instructions...
#--------- PASTE START
echo "Starting virtual memory"
#
# Make sure Swap is not mounted in case of hard reboot
# If a Swap directory does exist after a dismount, remove
# that because it's in the way of mounting Swap properly
#
umount -v /Volumes/Swap*
if [ -d /Volumes/Swap ]; then
ConsoleMessage "** DELETING extant Swap directory(s) **"
rm -rf /Volumes/Swap*
mkdir /Volumes/Swap
fi
#
# MAKE YOUR CHANGE HERE!
#
# Replace /dev/disk0s7 to your own Swap volume device path.
# And no matter what you called your swap volume, leave
# the /Volumes/Swap portion as it is because it matches the
# above mkdir and the /etc/fstab entry.
#
# vv-CHANGE-vv vvv-LEAVE-vvv
/sbin/mount_hfs /dev/disk0s7 /Volumes/Swap
sleep 1
swapdir=/Volumes/Swap/vm
#--------- PASTE END
Phew! You need to make one more change a little lower in the file. Go to the line that reads:
appprofiledir=/private/var/vm/app_profile
And replace it with:
appprofiledir=/Volumes/Swap/vm/app_profile
That's it. Now save your changes with ":wq!" and you're done.
While it's a bit more than a one-liner type of change, the beauty of this method is that it will work even if you force reboot (Command - Control - Power Key) your computer, something other methods fail on. In the event of a forced reboot, the system must check out all the volumes on the disk before mounting them. The /etc/fstab change guarantees that the check gets done to your Swap volume *in time* (this is key!). Only things in the /etc/fstab get checked at the beginning of the boot process. And you see, unless the disk has already been checked, mount_hfs will fail! If this happens, virtual memory ends up putting its swap files on the root volume (/). I believe the computer term for this is "screwed!".
To make things even more screwed, once your swap files are in the wrong place, they stay in the wrong place! This is why we need the extra code in /etc/rc -- it gets rid of these errant swap files.
Okay, so here it is in a nutshell... The /etc/fstab entry makes sure your disk gets checked in time (if needed), and the /etc/rc addition gets rid of old swap files that might be in the way. Swap mounts, and virtual memory merrily puts everything on the new partition!
And that, as they say, is that! So what are you waiting for? Go ahead and reboot!
Mac OS X Hints
http://hints.macworld.com/article.php?story=20031104150206554