From: krej@electrum.kth.se (Kristian Ejvind) Subject: Re: Steal Windows Swap File Date: 14 Jun 1993 23:27:20 GMT
In article <740034673snz@lorien.demon.co.uk> tim@lorien.demon.co.uk (Timothy Towers) writes:
> My HD is not large enough to put aside room for dos, windows & apps,
> 12Mb of Windows Swap space, linux and linux swap space. (indeed, if truth
> were to be known, I cannot afford a linux partition at all yet).
>
> However, looking into the future, where I have finished Ultima, and can
> grit my teeth and remove xwing from the HD, I will have almost enough
> space except for the swap partition.
>
> Since I will not be using both Windows and Linux at the same time I
> wondered if any of the NetGuru's out there had thought of sharing a swapfile
> between them.
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 substitute the sizes and
partions to match your computer, else.... bad luck!)
1) 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.
2) 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 you can use norton's wipeinfo to
'Wipe the entire drive' but this must be done after step 3). Neither
'format f:' or 'del f:*.*' will erase the data on the disk, they just
delete the information in the directory block(s) and wont work.
3) (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 F'). My swap partion shows up as F:. Format
the new drive:
c:\>format f:
4) 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'.
5) Reboot into linux. DO NOT start windows.
6) 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
7) 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
8) 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 reboot!. 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
9) Enjoy.
I have seen some people suggesting that it is possible to just save
the beginning of the partion (just enough to hold the boot blocks, the
fat, the root directory and a few blocks of the swapfile), 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 ;-)