home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / HOWTO / MINI / SWAP-SPA / text0000.txt < prev   
Encoding:
Text File  |  1995-04-20  |  8.8 KB  |  230 lines

  1.        SHARING SWAP SPACES BETWEEN LINUX AND MS-WINDOWS
  2.  
  3.                  A mini-HOWTO
  4.                   by
  5.               Peter Anvin <hpa@nwu.edu>
  6.  
  7.           Copyright (C) 1994 H. Peter Anvin
  8.  
  9. VERSION: 1.2                        Date: 13 Nov 1994
  10.  
  11. 0. ABSTRACT
  12.  
  13. Many people use both Linux and MS-Windows.  The ability to do so is an
  14. important part of "the Linux revolution"; i.e. letting people
  15. experiment with (and get hooked on) Linux while still being able to
  16. run their off-the-shelf software.  Since both Linux and MS-Windows use
  17. virtual memory with swap to disk, a frequently occurring question in
  18. comp.os.linux.help is how to share swap spaces, in order to reduce the
  19. amount of disk space needed.
  20.  
  21. There are several methods for sharing swap spaces, the one described
  22. in this document is probably the most complicated one but is the only
  23. one I have encountered that allows maximum performance for both
  24. environments without the risk of trashing a disk partition.
  25.  
  26. NOTE: If you have used a previous version of this document and have
  27. had problems with swap space not getting properly restored (Windows
  28. claims your permanent swapfile is corrupt), try the slighly revised
  29. shutdown script in this version.
  30.  
  31. 1. WHAT YOU NEED
  32.  
  33. This procedure have a few requirements that need to be filled.  I
  34. strongly recommend that you fill these requirements *anyway*, as there
  35. are several problems with older versions.
  36.  
  37.     * MS-DOS 5.0 or newer
  38.     * MS-Windows 3.1 or newer
  39.     * A shutdown/init that knows to run a file on shutdown.
  40.       (The SysVinit-2.50 package can do this, for example.
  41.       SysVinit-2.50 is available from sunsite.unc.edu in
  42.       /pub/Linux/system/Daemons)
  43.  
  44. 2. THE PROCEDURE
  45.   
  46. * Boot DOS.  Create a DOS partition (using FDISK) the size = the size
  47.   swap space you want.  It will be assigned a drive letter; use that
  48.   drive letter instead of X whenever these instructions lists a
  49.   command like "LABEL X:" or "COPY FOO X:DUMMY.DAT"
  50.  
  51. * Format this partition using the DOS FORMAT command.
  52.     FORMAT X:
  53.  
  54. * Set the volume label on this partition to "SWAP SPACE" using the DOS
  55.   LABEL command.  Verify it by the DIR command.  Please do this as a
  56.   separate step.  Some versions of FORMAT do not seem to put the
  57.   volume label in the boot sector as it should.  [Note: some people
  58.   has written me saying the volume label is stored in the root
  59.   directory.  Yes, but at least since DOS 5.0 it has also been in the
  60.   boot sector.]
  61.     LABEL X:
  62.     DIR X:
  63.  
  64. * Start Windows.  Go to the Control Panel, select "386 Enhanced".
  65.   Select "Virtual Memory" and create a Windows Permanent swap file on
  66.   drive X: of maximum size (Windows will tell you the maximum size).
  67.   Windows may complain saying it will not use a swap file that big.
  68.   Ignore the message and create the file anyway.
  69.  
  70. * Exit Windows.
  71.  
  72. * Boot Linux, then log in as root.
  73.  
  74. * Use the fdisk command to find the name of the partition and its size
  75.   in blocks.  Create a symbolic link from /dev/winswap to this
  76.   partition.  If the paritition is hda7, then type:
  77.     ln -s /dev/hda7 /dev/winswap
  78.  
  79.   [NOTE TO PURISTS: Please use a symlink.  The name of this partition
  80.   is going to go into several configuration files and inconsistencies
  81.   could be fatal.]
  82.  
  83. * The following is a uuencoded binary that analyzes the partition and
  84.   derives some special information; uudecode the following file,
  85.   gunzip it and run it as:
  86.  
  87.     msinfo /dev/winswap
  88.  
  89. begin 755 msinfo.gz
  90. M'XL(`$$YNRT"`Y557TQ;51@_MW]HZ0AM'"$U-.28W([..>84%1%D2QH>',9*
  91. M2S&VC);V=FV]T*;WWBD+1I)K'YH;DOJF#YH80GPR^J""D"R8-K('MS2;#Q*S
  92. M%Y,E-P&592A$V:[?.;?M"FP/?DG/G^_[?7_Z_3G7PL313TT(?8P0<J"CI':8
  93. M$5H^#:=5<KT^MQ`^UAQ1O*QUH0<.]B7S/FC[U!98Y;))]<*N^AG"^LB((J%E
  94. MAFIM[A9U0O`;%:*7N#[L%G!_-IH34V(J,WUZ.CK%O6I#N4DTE,E-144Q-7T)
  95. M>]_PX\M<3@!`'ZZ26[`-I7A.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<]'M8J@'AFA"[JM]0(WCQ!`[.826!F&A@HG4JWU5R_KKL&
  112. M9GNQF$;J[?NZ\YUZ?B].C,OEWI*\94J`:6LB?U,RK^2.([0QRQK(W!D2[K5M
  113. M,G>&0B7A'K03F"'17*&L#9XU@+U2L9K4-GCIG(K(NE:SM,>SM,?;X,T:&U6,
  114. MT./E%NAUTNE_$,^E(A0M!B7K[D'>X6'\FC25Q3W=+V3YLR^CXJW.S0>#54*#
  115. M#ZE^AI+N-35^_>![U4!?@VQ%ET<L!BC>MC5"\GH->"T6'4/2NS>((N0,DT>_
  116. 9K6^!S%65KRS`,`,UVB43\!]-BKG]B`<``#5"
  117. `
  118. end
  119.  
  120.   Take note at the number saying "Total special sectors", and verify
  121.   that the volume label says "SWAP SPACE".  If it does not, reboot DOS
  122.   and re-do the LABEL command.  If it still does not work, please
  123.   inform me about which version of DOS you are running, and I will try
  124.   to help you out.
  125.  
  126. * [Optional step] Windows may occationally leave some space on the
  127.   partition, even if it is told not to.  Don't attempt to use this
  128.   space, since it will be erased any time you run Linux.  If you want
  129.   to avoid accidentally using it (and lose data), you can create a
  130.   dummy file that fills that space by using the following commands:
  131.     mkdir /mnt
  132.     mount -t msdos /dev/winswap /mnt
  133.     dd if=/dev/zero of=/mnt/dummy.fil
  134.     umount /mnt  
  135.  
  136.   The dd command will report "No space left on device".  This is
  137.   exactly what you want.
  138.  
  139. * Check the name of the shutdown file.  For SysVinit this is the file
  140.   listed in the following line of /etc/inittab; add it if you don't
  141.   have it.
  142.  
  143.     # Runlevel 0 means shut down the system
  144.     l0:0:wait:/etc/brc
  145.  
  146.   For the remainder of this file, I will assume the filename was
  147.   /etc/brc.
  148.  
  149. * Type:
  150.  
  151.     dd if=/dev/winswap bs=512 count=XXX | gzip -9 > /etc/winswap.gz
  152.                                         ^^^
  153.                                         Replace
  154.   ... where XXX is replaced with the "Total special sectors" number.
  155.  
  156. * Add the following piece of code to your /etc/rc file (or whatever
  157.   your init calls it), right before the command "swapon -a" (if there
  158.   is no such command, add it to your /etc/rc file right before any
  159.   mount commands). 
  160.  
  161.   If you have a directory /etc/rc.d (like Slackware 2.x), the file you
  162.   want to put this in should be called "/etc/rc.d/rc.S".
  163.  
  164.   If your swapon is in /etc, replace /sbin/swapon with /etc/swapon.
  165.   If it is in /bin, replace with /bin/swapon.  Do the same for mkswap.
  166.  
  167.   Replace XXXXX with the actual size of the partition in blocks, as
  168.   given by fdisk.
  169.  
  170. ---[BEGIN CODE SEGMENT]---
  171. #
  172. # Verify and initialize swap space
  173. #
  174. echo -n 'Verifying swap space... '
  175. if [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=10 skip=4086`" \
  176.    = 'SWAP-SPACE' ]; then
  177.   echo 'Linux signature found'
  178.   /sbin/swapon /dev/winswap
  179. elif [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=11 skip=43`" \
  180.    = 'SWAP SPACE ' ]; then
  181.   echo 'DOS signature found'
  182.   /sbin/mkswap /dev/winswap XXXXX
  183.   /sbin/swapon /dev/winswap
  184. else
  185.   echo 'No signature found'
  186.   echo 'ERROR: Will not swap'
  187. fi
  188. ---[END CODE SEGMENT]---
  189.  
  190. * Add the following piece of code to your /etc/brc file (or whatever
  191.   it is called -- it is /etc/rc.d/rc.0 if you have an /etc/rc.d
  192.   directory); put this after any command that might need swap to be in
  193.   place.
  194.  
  195. ---[BEGIN CODE SEGMENT]---
  196. #
  197. # Terminate swapping and restore DOS/Windows swap info
  198. #
  199. /sbin/swapoff /dev/winswap
  200. if [ "`/bin/dd 2>/dev/null if=/dev/winswap bs=1 count=10 skip=4086`" \
  201.    = 'SWAP-SPACE' ]; then
  202.   echo 'Restoring DOS/Windows swap info'
  203.   /bin/zcat /etc/winswap.gz > /dev/winswap
  204. else
  205.   echo 'ERROR: /dev/winswap lacks swap signature, skipping restore'
  206. fi
  207. ---[END CODE SEGMENT]---
  208.  
  209. * Reboot Linux.  You should now have swapping on the new swap device.
  210.  
  211. 3. A COUPLE OF NOTES
  212.  
  213. * There is no need to add /dev/winswap to your /etc/fstab file.  In
  214.   fact, it is probably wise not to do so (except possibly as a
  215.   comment).
  216.  
  217. * If your Linux session crashes or otherwise exits without running
  218.   /etc/brc, you will need to reboot and exit Linux before swapping in
  219.   Windows will work.  It is also possible to FORMAT X: and re-create
  220.   the Windows swapfile.  The only way around this would be to put the
  221.   equivalent of the /etc/brc commands in the DOS AUTOEXEC.BAT file;
  222.   unfortunately I don't know of any way of doing that in DOS!
  223.  
  224. -- 
  225. INTERNET: hpa@nwu.edu             --- Allah'u'abha ---
  226. IBM MAIL: I0050052 at IBMMAIL     HAM RADIO:   N9ITP or SM4TKN
  227. FIDONET:  1:115/511 or 1:115/512  STORMNET:    181:294/1 or 181:294/101
  228. When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.
  229.  
  230.