OSX‎ > ‎

Move Swap File to another Drive (ReadBoost like feature)

WHY?

I searched over internet for Readyboost feature for OSX as the SSD life-time is by number of data written to disk, so I prefer to move my swap to another drive like cheap high speed memory stick. (By Basil)


By default, Mac OS X uses a swap file (for virtual memory) which is installed on the same drive as your operating system. For best performance, the swap file would ideally be located on the fastest drive in your machine, which may or may not be the same disk as your OS. Unfortunately, there's no built-in GUI for changing a swap drive location. 

A few days ago, there was a help request on swapping on another hard drive and subsequent comments that figured out how this could be done. I asked if patpro, one of the users involved, would mind writing a step-by-step instruction set on how to transfer swap. Read the rest of this article to see what he had to say ... well worth the time if you have a spare, fast hard drive in your system!

patpro writes: "Well, I'd be glad to help you with that, but in fact, Sven had a lot to do with my success as well:)). He pointed out some important aspects of the boot process (mount especially)." 

With that said, here are patpro and Sven's instructions on relocating your swap file. 

NOTE: This hint now reflects the additional functionality submitted by John in the comments 

  1. Launch a terminal session. 

  2. Backup the rc file into the current directory, which should be ~/ for the current user:
    cp /etc/rc .
  3. Print a partition map, which shows every device mounted on your system, by using df:
    df
  4. In the df output, choose your favorite disk/partition and remember its reference. Each row will look something like this:
    /dev/disk0s9       3134688     1970568  1164120    62%    /apps
    There will be one line for each volume in your system.

  5. During the boot process, mounting a disk other than local file system (MacOS X system drive) appears to occur after swap initialization. So now we're going to edit/ect/rc so that our preferred swap disk is mounted before swap initializes. To do this, we need to become root, transfer to the directory, and edit the file:
    su root
    cd /etc/
    pico rc
  6. In the rc file, replace this
    swapdir=/private/var/vm
    
    # 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
    with this
    swapdir=/disk-name/path_to_swap_directory
    
    # Make sure the swapfile exists,
    # first check existence
    # if not first make sure disk is mounted
    if [ ! -d ${swapdir} ]; then
    ConsoleMessage "mounting directories"
    mount -t hfs /dev/disk**** /disk-name
    mount -uw /
    fi
    # Make sure the swapfile exists,
    # if not, create directory since disk should be mounted
    if [ ! -d ${swapdir} ]; then
    ConsoleMessage "Creating default swap directory"
    mkdir -p -m 755 ${swapdir}
    chown root:wheel ${swapdir}
    else
    rm -rf ${swapdir}/swap*
    fi
    BE CAREFUL: If your preferred disk is NOT hfs you MUST provide the mount command with it's correct file format (mount -t ufs, for example). So the 'mount' line must follow this framework:
    mount -t (disk file format) /dev/(disk-reference) /(disk-name)
  7. Save the file and quit with CTRL-X, Y, and ENTER.

  8. Reboot

That should do it; your swap file should now be on the drive and directory you specified. patpro finishes with: "Thanx to Sven who helped me a lot figuring out what was wrong in my previous attempts."


source : http://hints.macworld.com/article.php?story=20001215021440138

Comments