树莓派4B调整SWAP分区大小
下面以树莓派4B 4g版本为例,安装系统为树莓派官方32为最小的系统,默认swap分区为100M,如图:

在其他系统上,我们都是在硬盘划分出来一定的空间手动挂载到swap分区上,树莓派只需要修改一个文件即可,在硬盘上划分空间手动挂载在此不做介绍,实际也没有在树莓派上进行测试。
下面开始修改树莓派swap大小步骤:
sudo nano /etc/dphys-swapfile #修改swap配置文件
# /etc/dphys-swapfile - user settings for dphys-swapfile package
# author Neil Franklin, last modification 2010.05.05
# copyright ETH Zuerich Physics Departement
# use under either modified/non-advertising BSD or GPL license
# this file is sourced with . so full normal sh syntax applies
# the default settings are added as commented out CONF_*=* lines
# where we want the swapfile to be, this is the default
#CONF_SWAPFILE=/var/swap
# set size to absolute value, leaving empty (default) then uses computed value
# you most likely don't want this, unless you have an special disk situation
#在此修改你需要的swap分配大小,单位为MB,一般在内存小于2G的情况下,交换分区应为内存的2倍!
CONF_SWAPSIZE=8000
# set size to computed value, this times RAM size, dynamically adapts,
# guarantees that there is enough swap without wasting disk space on excess
#CONF_SWAPFACTOR=2
# restrict size (computed and absolute!) to maximally this limit
# can be set to empty for no limit, but beware of filled partitions!
# this is/was a (outdated?) 32bit kernel limit (in MBytes), do not overrun it
# but is also sensible on 64bit to prevent filling /var or even / partition
#此为分配大小限制,需要取消该注释并修改,该值最好大于你需要设置的大小,否则更改最大默认为2048
CONF_MAXSWAP=10000
修改如下图:

然后,重新启动 dphys-swapfile 文件服务:
sudo /etc/init.d/dphys-swapfile restart #重启服务
sudo free -m #查看修改是否生效

是不是很简单,快去试试吧~

































