So, I read a while ago that it was considered generally a quite difficult thing to create a swap file (or partition) which could be shared by both windows and linux on a dual boot system.
After all you dont need large redundant files on your system do you ?
Here's how I have my machine set up:
Dual boot Win XP (other versions will work also), and RedHat linux 9.0 (other distros/versions _should_ work also. Feel free to post replies to this if specific variations on this theme are needed to make it work on other OS versions).
First off, you need a partition or drive which is visible to both windows and linux. This could be:
- Your windows partition. Although be warned that if this is NTFS, linux won't be able to write to it (at least my system doesn't) so that's a non-starter. You need to use an alternative.
- A dedicated FAT (16 or 32) swap partition.
- Another drive altogether (with FAT file system). This is the set-up I have.
I am not going to go into here what size swap you should be using (if any), nor do I intend to explain how to create/move/copy/resize partitions on your HD. But, here are the outline apporxiamte steps you need to take for both systems to be happy.
First things first: When installing linux, you should not specify a special linux swap partition. Ignore the warning about not using a swap partition for now. If you already have linux set up (probably most of you, but I did it from scratch), you could go about removing the current reference to the swap partition in /etc/fstab, and then convert your swap partition to FAT, so that you can share it with windows.
Boot windows and change the page/swap file settings to use a file on the shared space of your choice (on my machine this is D: second hard disk). Under Win XP/2K/NT this creates a file called pagefile.sys. On other Windows versions 95/98/ME etc i think it's called win386.swp. You will need to know the precise location and name of this file in order to set it up with linux. You should be able to find it quite easily because of it's enoumous size.
That's windows taken care of. You will probably have to reboot back into windows immediately so that it can create/move the appropriate files.
Configuring linux is a little more tricky (it always is, isn't it ?). There are a couple of things you need to change, and one of these is necessary at every boot of linux, however, this can be taken care of in the startup scripts.
The first thing to do, as a test before we modify the system is issue a couple of commands to check that linux has the appropriate permissions to use the swap file properly. Open up a console, and find the swap/page file that windows created. On my system, under linux this is /mnt/data/pagefile.sys.
Run a quick check with (you should be root to do this):
The first command sets the file up for swap use with linux. The second activates it as a swap space.
Verify that linux is using swap by issuing a 'free' command. It should list the amount of used/free swap and memory. If on of these commands fails, you should check out the write attributes of your drives/partitions/files. Linux needs to write to this file, quite obviously.
Now, you want these things to happen automatically when you boot linux. The second part is easy, you need an entry in your /etc/fstab file which looks remarkably like the old one:
/mnt/data/pagefile.sys swap swap defaults 0 0
Then, when the system calls for all swap spaces to activate, it sees this entry and all is good.
However, not much is going to happen if you booted windows in the meantime and overwrote the file with windows junk. So on every linux boot we need an mkswap command. I put mine in the /etc/rc.sysinit file. I'm not sure if it should really belong in here, but it works for me. A word of warning: Be VERY careful when editing this file. !!
In the file I found the very LAST occurrance of the command 'swapon -a', and just before it I put in:
Now when linux boots, it runs through the rc startup script and automatically configures the use of your windows swap/page file for it's own use.
Sweet! That's all there is to it. I know I've written quite a lot here, but really there is nothing to it.
I hope it works for you.. really there's only a few things you need to change, and they're not difficult.