Using Windows Swap in FreeBSD

Configure the Windows Swapfile

FreeBSD can be configured to use the Windows swap file as virtual memory. This can be helpful when you need to add more swap but don't have the space in FreeBSD, or if you have Windows on a separate disk and want to get a little benefit out of a different drive for swap.

The first thing you want to do is make sure that the swap file in Windows is contiguous so your drive doesn't do too much work. Start Windows, select Start -> Settings -> Control Panel, then open the System dialog. Click on the performance tab. Click on the Virtual Memory... button, select Let me specify my own virtual memory settings, then click Disable virtual memory. Allow Windows to reboot.

When Windows finishes rebooting you need to defragment your Windows partition. First close any open programs, including the programs running in the task bar, then hit Ctrl-Alt-Del and click End Task for any program that is not Explorer or Systray. This prevents Windows from restarting the defragmentation process every time a program writes to the disk (because nothing is running.) Now Select Start -> Programs -> Accessories -> System Tools -> Disk Defragmenter. If the shortcut does not exist you may need to install it from your Windows CD. Make sure the options are set to Full Defragmentaion and click start. If the defragmenter complains that your drive is only 0% fragmented, defragment anyways. Once the defragmenter is complete, shut down and restart your computer again.

Now that Windows is happily defragmented, return to the System Properties dialog and set your virtual memory size to a fixed value such as twice your system memory size. (If you've forgotten where it is already, just look back two paragraphs.) Allow Windows to reboot one final time, the shutdown and start FreeBSD.

Enable swapping for FreeBSD

Now that FreeBSD is running log in as root and make sure that you have your dos partition mounted. I mount mine on /dos/c, so typing 'mount' at a prompt returns "/dev/da0s1 on /dos/c (msdos, local, ...)." If it is not mounted, add the appropriate entry to your /etc/fstab file, something like "/dev/da0s1 /dos/c msdos rw 0 5", create the proper mount points, and type 'mount -a' as root. Typing 'mount' again should show the drive mounted at the bottom of the list.

Now you'll need to turn the swap file into a vnode swap file. First make sure you have the vn support enabled in your kernel, or have the vn kld loaded. By default, vn isn't enabled, so you can add the line 'pseudo-device vn' to your kernel config and build a new kernel or type 'kldload vn' to start it up. You may need to add the line 'vn_load="YES"' to your /boot/loader.conf to make the module load automatically. Creating the swap device is as simple as 'vnconfig /dev/vn0b /dos/c/WIN386.SWP' and enabling swap on that device is just 'swapon /dev/vn0b' to have this run automatically everytime you boot, just add those two lines to your /etc/rc.local file.