This article explains how to set up swap space (page file) so that both Windows and GNU/Linux use it in a dual-boot setup.

This guide assumes that the GNU/Linux installation has an NTFS filesystem driver with read-write capability installed.

Step 1

Prepare a disk partition that will be used as swap space. Create an NTFS volume on the partition. The volume will be used as swap space.

Step 2

Boot into Windows and create a page file on the volume. Set it so that the page file’s size is fixed (i.e. minimum and maximum sizes are the same) and take up as much space as possible.

This is configured in a window accessed via Control Panel → System → Advanced System Settings. Opening a context menu of the My Computer and choosing Properties does the jop, too. Under one of the tabs there is a button for configuring virtual memory.

Step 3

Disable fast boot when on Windows 8 and later. This can be done via the Control Panel → Power Options.

It must be done, because Windows will otherwise save some data to the volume upon every shutdown. It won’t be possible to safely mount it under GNU/Linux then.

Step 4

Windows is not configured. Restart and boot into GNU/Linux.

Step 5

Create an entry in /etc/fstab to automatically mount the volume on startup. It should be accessible by the superuser (root) only, for security.

Step 6

Create two scripts that will run upon startup and upon shutdown. The scripts must run after the volume is mounted, of course. How this is done depends on the system used by your distribution. Look for information on configuring a startup or boot service.

Either way, make the service do the following upon startup: Execute mkswap on the pagefile.sys file under the volume. This will make a Linux swap volume within the file. Then, execute swapon on the just-created swap volume.

Unfortunately, these two operations take some time. It is best to make it into a background process in order not to increase the time it takes for the system to initialize. Swap space can be added while the system is being used without any problems.

Upon shutdown, execute swapoff on the file. Otherwise, the file will be in use and there will be warnings when unmounting the volume.

Done

Well, that’s it.

It would be better if Windows could utilize a partition, but sadly it can’t. Some space is lost due to the filesystem.