LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices



Reply
 
Search this Thread
Old 10-28-2003, 11:37 AM   #1
Doug Hammond
LQ Newbie
 
Registered: Feb 2003
Distribution: rehdat 8.0
Posts: 14

Rep: Reputation: 0
Sharing a swap file with linux and windows


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.
WRONG. !!

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):
Code:
mkswap /mnt/data/pagefile.sys
swapon /mnt/data/pagefile.sys
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:
Code:
..
/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:
Code:
..
mkswap /mnt/data/pagefile.sys
..
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.

Doug Hammond.
 
Old 08-31-2004, 02:32 AM   #2
rofranco
LQ Newbie
 
Registered: Aug 2004
Posts: 2

Rep: Reputation: 0
Hi,

I would like to share my swap partition (which I had already created and am using for Windows) between Win2K and Linux.
My question is: if I follow the procedure that you described, Windows 2000 will be able to use the swap file even though Linux has overwritten it ? I heard that if I didn't backup the swap partition and restored it before shutting down Linux and starting Windows, that Windows wasn't able to use it.

Thank you in advance for your answer.

Rodolfo.
 
Old 10-03-2004, 01:15 PM   #3
psylocibe
LQ Newbie
 
Registered: Oct 2004
Posts: 4

Rep: Reputation: 0
i found an exhaustive explanation of the way to share the swap file at the url: http://www.mail-archive.com/inspiron.../msg00427.html

i think this link will be useful for you.
 
Old 10-04-2004, 04:01 AM   #4
rofranco
LQ Newbie
 
Registered: Aug 2004
Posts: 2

Rep: Reputation: 0
Thank you for your reply. I think that the link you mention is an earlier version of the: Linux Swap Space Mini-HOWTO

I was a bit worried that maybe Windows wouldn't work if I messed the swap partition (which I did a couple of times before making it work) but I can tell you now that, luckily, Windows 2000 creates a temporary swap file in drive C in case it cannot use the partition that you assigned it.

The only thing that I could say about the tutorial is that nowadays, I think that most Linux distributions use the new style swap space that enables to use big swap partitions. So, you have to read the whole tutorial and beware of the following note:

"The new style swap space: Linux knows about two styles of swap areas, the old style and the new style. By default, you will be using the old style swap space with a signature "SWAP-SPACE". If you want to use the new style swap space, then first of all change "SWAP-SPACE" in all the above scripts to "SWAPSPACE2"."

Having done that, I had no problem to set up a shared swap partition between Linux and Windows 2000.

Another thing that I remember having a bit of trouble, was to rename the swap partition in Windows. Before starting the tutorial, my swap partition under Windows was called "SWAP". The label command didn't seem to really change the swap partitions name. Fortunatelly, I had a boot diskette from Partition Magic with which I was able to change the label and Linux saw it.

Thanks for your help, and hope that my comments can help someone else.
 
Old 11-17-2004, 02:02 AM   #5
aecaudel
LQ Newbie
 
Registered: Nov 2004
Distribution: Gentoo
Posts: 7

Rep: Reputation: 0
From your post regarding:

mkswap /mnt/data/pagefile.sys

I presume that you have to mount the pagefile.sys before the mkswap. Do you then have to have an fstab entry to mount the partition holding the pagefile.sys? Does this entry have to precede the swap entry in fstab?

The reason I ask this is "mkswap /dev/hda5/pagefile.sys" complains about it not being a directory.
 
Old 07-11-2005, 07:06 AM   #6
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
aecaudel

Yes you must mount the windows partition before running the mkswap command. Your /etc/fstab file might look something like this:

/dev/hda5 /mnt/data vfat defaults 0 0
/mnt/data/pagefile.sys swap swap defaults 0 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How file sharing on linux to windows cbcats Linux - Networking 6 01-25-2005 03:58 PM
File Sharing Windows and linux together ? maxboost Linux - Networking 4 12-30-2004 01:24 PM
Linux-Windows file sharing ar1 Linux - General 6 01-23-2004 12:54 AM
re: windows and linux file sharing rahul_jain_9684 Linux - Software 4 07-28-2003 03:42 AM
windows and linux file sharing dpreed7 Linux - Networking 4 04-01-2002 08:08 AM


All times are GMT -5. The time now is 12:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration