login
Header Space

 
 

Re: Share swapfile between Linux and MSWindows?

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
Date: Tuesday, July 6, 1993 - 4:38 pm

In article <JAFFER.93Jul4233647@camelot.ai.mit.edu> jaffer@zurich.ai.mit.edu (Aubrey Jaffer) writes:


  OK, here we go again: 'windows-linux swap in common?'. Perhaps time for 
moving this into the FAQ (I assume it's not there already, havn't checked...)?

  A swap *file* cannot be shared between, as dos can't access the linux file
system and linux can't swap on the dos file system. However a linux swap
partion can be made into a swap file for windows at the cost of a few
seconds longer time to reboot. If you want to do things the same way as I
have done then follow these steps: (remember to subtitute the sizes and
partions to match your computer, else.... bad luck!)

1) Make sure you don't use swap at the moment, i.e. remove all swapon
commands from your /etc/rc and do a swapoff.

2) Decide how much swap space you need and create a partion to swap on with
fdisk (or any other disk partioning program). I chose to make it about 6M or
to be exact 5967 blocks large and on /dev/hda4. Make the partion a DOS
partion. Mine is a primary 12-bit-fat (id 1) partion.

3) Erase the partion completely so that it will compress to the smallest
possible size. This can be done with :
    dd if=/dev/zero of=/dev/hda4 
while running linux. If you want to you can use norton's wipeinfo instead
to 'Wipe the entire drive' but this must be done after step 3). Neither
'format e:' or 'del e:*.*' will erase the data on the disk, they just delete
the information in the directory block(s) and wont work.

4) (Re)Boot dos. The swap partion will show up as a new 'disk letter' in
dos, which dos wont be able to read (dos says something like 'Invalid
media error on drive E'). My swap partion shows up as E:.  Format
the new drive:

c:\>format e:

5) Start windows (if you are running windows 3.0 you must start it in
real mode: c:\>win /r) and create a permanent swap file as large as the new
partion. Ignore the warning that windows wont use more than the recommended
size, it will. In windows 3.0 this is done by closing ALL active applications
excluding the program manager, selecting File/Run and run 'system/swapfile'. 
In windows 3.1 it's in the control panel under '386 Enh' and 'virtual memory'.

6) Reboot your into linux. DO NOT start windows.

7) Save and compress the swap partion to a file:

dd if=/dev/hda4 | gzip -9 > /.winswap

Since you erased the whole partion the compressed file will become
very small; from my computer:

23:27-oden:/>ls -l .winswap
-r--------   1 root     root         9431 Apr 10 20:23 .winswap

8) Place the following commands in your /etc/rc:

/bin/mkswap /dev/hda4 5967
/bin/swapon -a 

and a line in /etc/fstab describing your swap partion:

/dev/hda4       none    swap    defaults

9) These commands will destroy the dos partion and the windows swap
file and must be restored before windows can be used. I do this when I
reboot linux automatically with this script which I have named
/etc/reboot and with a link to it from /etc/halt:

----/etc/reboot-----snip-----8<--------
#!/bin/sh -
if [ "root" != "`whoami`" ]
then
  echo "Sorry "`whoami`. You must be root to "`basename $0`"!. Exiting."
  exit 1
fi
echo `basename $0` in progress. Please standby
swapoff /dev/hda4
/usr/local/bin/gunzip < /.winswap > /dev/hda4
exec /etc/.hidden/`basename $0` $*
----end /etc/reboot-----snip-----8<----

and I have moved the original /etc/reboot and /etc/halt to 
/etc/.hidden/reboot and /etc/.hidden/halt

10) Enjoy.

11) Realize that 6M of swap isn't enough even with 8M of ram and
feel sad ;-)

I have seen some peolpe suggesting that it is possible to just save
the beginning of the partion (just enough to hold the boot blocks, the
fat and the root directory), and others saying that you must save the
whole partion but I havn't bothered to investigate this matter, the
solution above works just perfect.

/Kristian

p.s. I hope I havn't mistyped anything but anyway: Be careful when
dealing with the disk partions as you will blame yourself to death
when you have erased your whole dos partion with your five years worth
of work on just because you typed /dev/hda4 instead of /dev/hda3 ;-)
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Kristian Ejvind - krej@it.kth.se         I   The best way of accelerating
The Royal Institute of Technology, KTH   I   a macintosh is by 9.82 m/(s*s)
Stockholm, Sweden                        I
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: Share swapfile between Linux and MSWindows?, Kristian Ejvind, (Tue Jul 6, 4:38 pm)
speck-geostationary