Re: Using a swap file

From: Rostislav Krasny <rosti.bsd_at_gmail.com>
Date: Fri, 25 Oct 2013 18:00:54 +0200
On Fri, Oct 25, 2013 at 6:31 PM, Rostislav Krasny <rosti.bsd_at_gmail.com> wrote:
> On Fri, Oct 25, 2013 at 3:50 PM, Rostislav Krasny <rosti.bsd_at_gmail.com> wrote:
>> Hi there,
>>
>> I've 10.0-BETA1 i386 installed and I want to use a swap file instead
>> of a swap partition. I created /swapfile and I'm able to enable it
>> manually by following commands:
>>
>> mdconfig -a -t vnode -f /swapfile -u 0
>> swapon /dev/md0
>>
>> This is according to the following section of the Handbook:
>>
>> http://www.freebsd.org/doc/handbook/adding-swap-space.html
>>
>> It still states that adding swapfile="<path to swapfile>" into
>> /etc/rc.conf enables that swap file during a boot automatically.
>> However this is already not true for CURRENT and for the upcoming 10.0
>> release. According to following commit number 252310 this rc.conf
>> parameter is obsolete
>>
>> http://svnweb.freebsd.org/base?view=revision&revision=252310
>>
>> It introduces different configuration and offers to add a line like
>> following into /etc/fstab
>>
>> md    none    swap    sw,file=/swapfile       0       0
>>
>> This is what I did but 'swapon -a' still doesn't work. I didn't try to
>> reboot because I build world in other console. But I believe the
>> result will be the same, because /etc/rc.d/swap runs the same command:
>> '/sbin/swapon -aq'. So what is the right way to enable a swap file
>> during a boot and for commands like 'swapon -a' ?
>>
>> Thanks
>>
>> P.S. The Handbook needs to be updated
>
> After rebooting (into an updated system) the swap file somehow turned
> on and was running through /dev/md0. Unfortunately after running
> 'swapoff -a' it is impossibly to turn it back on and /dev/md0 is
> disappeared. So the swapon(8) program is still broken.


Finally I've figured out how to turn swap on in case it's on a swap file:

root_at_saturn:~ # swapon -aL
swapon: adding /dev/md0 as swap device

This is (with an additional -q parameter) what /etc/rc.d/swaplate does
during the boot. But from the swapon(8) manual page this is not
obvious:

     The swapon utility adds the specified swap devices to the system.  If the
     -a option is used, all swap devices in /etc/fstab will be added, unless
     their ``noauto'' or ``late'' option is also set.  If the -L option is
     specified, swap devices with the ``late'' option will be added as well as
     ones with no option.  If the -q option is used, informational messages
     will not be written to standard output when a swap device is added.

But I have no 'late' option in my /etc/fstab:

root_at_saturn:~ # cat /etc/fstab
# Device    Mountpoint    FStype    Options            Dump    Pass#
/dev/ada0s2a    /        ufs    rw            1    1
md        none        swap    sw,file=/swapfile    0    0

Then why 'swapon -a' (without -L) doesn't work? It's either buggy or confusing.

P.S. Please update the Handbook as well.
Received on Fri Oct 25 2013 - 14:00:56 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:43 UTC