swap on file (By dphys-swapfile)

最後更新: 2018-03-15

介紹

dphys-swapfile - Autogenerate and use a swap file

 


Install

apt-get install dphys-swapfile

Usage

dphys-swapfile setup|install|swapon|swapoff|uninstall

Setup Swap

[1] turn off current swap

dphys-swapfile swapoff

/etc/fstab

#UUID=19d9a79a-c828-442d-b7f5-98e420edf82f none            swap    sw              0       0

# (re-)generate an fitting swap file

dphys-swapfile setup

# direct swapon/off from /etc/fstab is not possible, 因為 /var 未 mount 起 (swap file default 在 /var/swap)

dphys-swapfile swapon

Config

/etc/dphys-swapfile

# where we want the swapfile to be
CONF_SWAPFILE=/var/swap

# set size to absolute value, leaving empty (default) then uses computed value
CONF_SWAPSIZE=512

# restrict size (computed and absolute!) to maximally this limit
CONF_MAXSWAP=2048

Start With System

/etc/init.d/dphys-swapfile start

update-rc.d dphys-swapfile enable

cat /proc/swaps

Filename                                Type            Size    Used    Priority
/var/swap                               file            524284  0       -1

Creative Commons license icon Creative Commons license icon