sudo /sbin/swapoff [-h -V]
sudo /sbin/swapon [-h -V]
sudo /sbin/swapon -a [-v] [-e]
sudo /sbin/swapon [-v] [-p priority] specialfile …
sudo /sbin/swapon [-s]
sudo /sbin/swapoff -a
sudo /sbin/swapoff specialfile …
specialfile may be of the form -L label or -U uuid
Calls to swapon normally occur in the system multi-user initialization file /etc/rc making all swap devices
available, so that the paging and swapping activity is interleaved across several devices and files.
-a |
swapon -v -s Filename Type Size Used Priority /dev/mmcblk0p4 partition 2,097,148 23,040 -2 > sudo swapoff -v -a swapoff /dev/mmcblk0p4 > top KiB Mem : 443080 total, 35980 free, 59072 used, 348028 buff/cache KiB Swap: 0 total, 0 free, 0 used. 312116 avail MemIf Swap is not in use
swapon -a -s -v do not report anything
swapoff disables swapping on the specified devices and files.
Do not use swapon on a file with holes.(like f2fs)
Swap over NFS may not work.
SEE swapon(2), swapoff(2), fstab, init(8), mkswap(8), rc(8), mount(8)
Files:
/dev/hd?? standard paging devices
/dev/sd?? standard (SCSI) paging devices
/etc/fstab ascii filesystem description table
major minor #blocks name 8 0 104846336 sda 8 1 104391 sda1 8 2 103683510 sda2 8 3 1052257 sda3 8 16 2823802880 sdb 8 17 2823802846 sdb1 7 0 512000 loop0
dphys-swapfile setup|install|swapon|swapoff|uninstall
Called from /etc/init.d, computes the size and resizes an existing swap file if necessary,
mounts, unmounts and deletes it if it's no nolonger needed.
setup |
/etc/dphys-swapfile is a sh script fragment of assignments, which is sourced. Standard sh syntax rules apply.
Assignments are:
CONF_SWAPFILE |
/etc/dphys-swapfile config
# /etc/dphys-swapfile settings for dphys-swapfile run from /etc/init.d
# sourced with . so full normal sh syntax applies
# location of swapfile (not partition)
CONF_SWAPFILE=/varnew/swap # default /var/swap
# set size to absolute value, if empty (default) uses computed value
#CONF_SWAPSIZE=100
CONF_SWAPSIZE=200
# restrict size (computed and absolute!)
# set to empty for no limit. Beware of filling up partitions where CONF_SWAPFILE lives
#CONF_MAXSWAP=2048
CONF_MAXSWAP=400
# For setup aka install size is computed as :
# CONF_SWAPFACTOR times RAM size
# dynamically adapts if RAM size changes.
# Not the best way to determine a good size
#CONF_SWAPFACTOR=2
Usually run at system startup and shutdown from an /etc/init.d (or /etc/rc.d)
#!/bin/sh
# /etc/init.d/dphys-swapfile - automatically set up an swapfile
# author franklin, last modification 2004.06.04
# This script is copyright ETH Zuerich Physics Departement,
# use under either modified/non-advertising BSD or GPL license
case "$1" in
start)
/sbin/dphys-swapfile setup
/sbin/dphys-swapfile swapon
;;
stop)
/sbin/dphys-swapfile swapoff
;;
esac
exit 0
sudo dphys-swapfile setup want /var/swap=200MByte, generating swapfile ... of 200MBytes
swapfile has holesf2fs requires filling up the file via sudo dd if=/dev/zero of=swapfile bs=1M count= mb
200+0 records in
200+0 records out
209715200 bytes (210 MB, 200 MiB) copied, 16.7755 s, 12.5 MB/s
read swap header failed
sudo mkswap /varnew/swap