A question about swap

Lasse H Oestergaard EMP lhoe at iddth.id.dk
Wed Jun 19 21:43:51 AEST 1991


diamond at jit533.swstokyo.dec.com (Norman Diamond) writes:

>In article <1991Jun14.184609.21178 at mlb.semi.harris.com> dcb at dave.mis.semi.harris.com writes:
>>On one of our 5500s, we have configured over 500M of swap space. Someone
>>recommended using the 'a' and 'b' partitions over five drives, with the
>>a/b partitions combined into a larger 'a' partition.

>I believe that if you swap onto your 'a' partition, then you overwrite the
>partition information and corrupt the entire disk.  It might be possible to
>make a really tiny 'a' partition and larger 'b' partition while leaving the
>rest of the disk alone; I haven't tried it.

>I believe that if you swap onto a disk's 'c' partition (an entire disk),
>then you are usually safe, but if a random memory that happens to look like
>a partition table happens to get swapped out onto the lucky block, and then
>you reboot, you have a corrupted disk.

>Warning:  this post is a combination of vague recollections and logical
>thinking, both of which are risky and should not be depended upon when using
>a derivative of the Unix operating system.  Do your own reading and/or obtain
>advice from an expert on the topic before relying on it.


  HOW TO DO IT RIGHT:

  The following is correct, and tested by experience on VAXes, but should
  be true for RISCS also:

  If you swap on a partition, no matter which, it should NOT start at
  segment 0, which the  a  and  c  partitions usually do. Use 

   chpt -p<whatever>  /dev/r...c  64  <size when starting at 0 - 64>

  to leave room for the bootblock, partition table and whatever, by
  starting the partion at 64, and shrinking the size correspondingly. 
  Or change the a-partition to have a small length (64 should do it)
  (while still starting at 0), discard it, and use (for instance) an
  extended b-partition (which can start at 64) for swapping.
  The current (or if no valid partition table exists, the default) size 
  of partitions can be found with

   chpt -q /dev/r...c


  MISUSE:

  If a partition starting at 0 is used to swap on, AND any partition on the
  same disk is used for filesystems, the effect depends on whether

   1. The partitions used for filesystems have been redefined (i.e. 
	have either a non-standard placement or size, or both).
	In this case the disk will become unreadable, probably on the next
	boot, because the partition table has been overwritten, AND THE
	DISK DRIVER THEREFORE APPLIES THE COMPILED-IN DEFAULT.
	Unless (one of) the swappartition(s) is the primary swap partition
	and further, the DEFAULT placement/size for that partition overlays
	part of a filesystem partition, the boot to multi user mode should
	fail, and NO INFORMATION SHOULD BE DESTROYED, and the disk can be
	recovered, PROVIDED THAT you can remember the original partitioning.

   2. The partition is the a-partition (and no partitions have been
        re-defined). THIS SEEMS TO WORK, because the compiled-in default
	is used instead of the destroyed partition table. BUT see below.

   However, WHENEVER a partition starts at 0 is used to swap on (which
   includes, when the whole disk is used as a c-partition), the
   swapping may (as Norman Diamond writes) create a 'false partition table',
   though this is very unlikely.  Then all bets are off, of course, and
   you may get filesystems overwritten.
   (In case 2, and when the whole disk is used as a c-partition, you can 
   probably recover by dd -ing  64 segments of 0-s to the raw disk,
   however).


   CORRECTING:
   To correct the partitioning of a disk, which has a partition, that starts
   at segment 0, that is used as a swapfile, WITHOUT COPYING THE DATA,
   proceed as follows:

      . Make sure, that the partition is not active. This normally implies
	a re-boot to single user mode. If the partition is the primary
	swapfile, make an alternative kernel, or boot from the net.

      . Read the current partition table by  chpt -q /dev/r...c 
	If you know, what the contents should be, and it isn't,
	restore it by successive  chpt -p. /dev/r...c  ... ...
	commands, then use the above commands to modify the 
	(relevant) swapfile. (Also check the filesystems.)

      . Othewise, if the partition table is  NOT standard, it is (probably)
        un-corrupted, so, unless you KNOW different, just use the above 
	commands to modify the (relevant) swapfile.

      . Otherwise set the partition table to the default with  
	  chpt -d /dev/r... , then use the above 
	commands to modify the (relevant) swapfile.c

    NOTE: This may fail, if no filesystem exist, in what would be the
    a-partition, if the default applied (i.e. starting at 0). Then one 
    must make a small dummy filesystem there first (which will NOT
    overwrite anything useful, in this situation):

      . Find a partition, that starts at 0, in the current partition
	table. Either the actual swap-partition or the default a-partition
	must do this. Assume this is  X .
	Use  /etc/mkfs  /dev/r...X  1000   to create a mini-filesystem.
        DO NOT USE  newfs  .

      . Either restore a (known) nonstard partitiontable partition by 
	partition, or set it to the default. This should work now. 
	Then use the above commands to modify the (relevant) swapfile.


		     Lasse H. Ostergaard      lhoe at id.dth.dk



More information about the Comp.unix.ultrix mailing list