Hi LeVA,

> I have two disk drives, and each of them has a swap partition. I would 
> like to swap to both of them, but firstly to the "other" disk, which is 
> not used during the running of the system, thus making the swapping 
> less painful (the drives are on separate ide channels/cables).
> 
> The swap partition which is on the disk which has the root partition 
> gets always priority 0, so I thought that I should add this to my 
> fstab:
> 
> /dev/wd1b none swap sw,priority=0 0 0
> /dev/wd0b none swap sw,priority=1 0 0
> 
> But after reboot, both of the swap partitions gets priority 0.
> I can change the wd0b's priority to 1 after the boot, but is this the 
> proper way of doing this, and one can not define the main swap 
> partition's priority in fstab?

On bootup, swap configuration using fstab(5) is done by swapctl(8)
from rc(8).  But, as far as i have seen on 3.9-stable and earlier
systems, the GENERIC kernel adds the "b" partition of the root disk
as a swap partition even before spawning init(8), i.e. long before
/sbin/init can invoke /etc/rc, at least if that partition looks
like a swap partition.

Thus, when /etc/rc gets to the line `swapctl -A -t blk`,
the swap partition is already active.  You can verify this assertion
by commenting out *all* swap lines from /etc/fstab, rebooting
and typing

  [EMAIL PROTECTED] $ swapctl -l 
  Device      512-blocks     Used    Avail Capacity  Priority
  swap_device     524160   241544   282616    46%    0

(Er, well, i *really* ought to get more RAM for idefix, it is not
that expensive any more.)

You see that the swap device is quoted as "swap_device".  As far
as i understand, that's what the kernel will call it if it was
activated during kernel booting, before spawning /sbin/init.

Now, if a swap device is already active, `swapctl -a -p` does
not change its priority, only `swapctl -a -c` does so:

  [EMAIL PROTECTED] # swapctl -l    
  Device      512-blocks     Used    Avail Capacity  Priority
  swap_device     524160   246088   278072    47%    0
  [EMAIL PROTECTED] # swapctl -a -p 1 /dev/wd0b  
  [EMAIL PROTECTED] # swapctl -l                 
  Device      512-blocks     Used    Avail Capacity  Priority
  swap_device     524160   246088   278072    47%    0
  [EMAIL PROTECTED] # swapctl -c -p 1 /dev/wd0b  
  [EMAIL PROTECTED] # swapctl -l                 
  Device      512-blocks     Used    Avail Capacity  Priority
  swap_device     524160   246088   278072    47%    1

This is perhaps not perfectly documented in the man pages - one
might add "If _arg_ is already enabled, nothing is changed, in
particular not the priority" after "If cmd is SWAP_ON, the arg
parameter is used as a pathname of a file to enable swapping to.
The misc parameter is used to set the priority of this swap device"
in swapctl(2) and "If the device is already contained in the list,
nothing is changed, in particular not its priority" after "The
-a option requires that a path also be in the argument list.
The path is added to the kernel's list of swap devices using
the swapctl(2) system call" in swapctl(8).  Jason?  =;-)

In any case, that's how it works.  The kernel adds your wd0b
before rc(8), rc(8) only does `swapctl -a`, not `swapctl -c`,
so your nice entry in /etc/fstab gets ignored.

My suggestion would be to add `swapctl -c -p 1 /dev/wd0b` to
rc.local(8).  But don't forget about it when reconfiguring your disks,
or document it at the proper place in case of multiple admins.

I do *not* suggest to compile a custom kernel containing
something like "config bsd root on wd0a swap on wd1b" in its
configuration file.  In case you forget *that* and change your
disk setup, you will be quite surprised.  On top of that, if
you encounter problems with a custom kernel, most people won't
even try to help you because they assume you have just broken
your kernel.

As far as i understand config(8) and boot_config(8), you cannot
modify the swap device used by an existing kernel after typing
'boot -c' at the boot prompt or `config -e -o /bsd.new /bsd`
from the running system.

Yours,
  Ingo

-- 
Ingo Schwarze <[EMAIL PROTECTED]>

Reply via email to