本文收集各 Linux 发行版修改交换分区大小的方法
Ubuntu
已测试版本:
18.04
使用下列命令查看系统中的swap分区大小:
Shell
x
1
1
sudo swapon --show
增加swap步骤: < 将swap分区增加到10G >
(1)执行下列命令关闭系统交换分区:
Shell
xxxxxxxxxx
1
1
1
sudo swapoff -a
(2)执行下列命令创建一个用于swap的文件:
Shell
xxxxxxxxxx
1
1
1
sudo fallocate -l 10G /swapfile
(3)执行下列命令为swapfile文件设置权限:
Shell
xxxxxxxxxx
1
1
1
sudo chmod 600 /swapfile
(4)使用mkswap程序在swapfile文件上设置Linux swap区域:
Shell
xxxxxxxxxx
1
1
1
sudo mkswap /swapfile
(5)然后使用下列命令激活swapfile文件:
Shell
xxxxxxxxxx
1
1
1
sudo swapon /swapfile
(6)经过上述过程,创建扩展的交换分区是临时的,我们需要让其永久生效,需要在/etc/fstab配置文件中进行设置:
Shell
xxxxxxxxxx
1
1
1
echo '/swapfile swap swap defaults 0 0' >> /etc/fstab
(7)使用swapon或free命令验证swap是否处于激活状态:
Shell
xxxxxxxxxx
1
3
1
sudo swapon --show
2
3
sudo free -h
经过上述步骤后,在Ubuntu下扩展swap分区就完成了