首页 » Linux » 正文

Linux扩容SWAP交换空间

1、free -h查看当前SWAP空间有多少

[root@linux195 ~]# free -h
total used free shared buff/cache available
Mem: 11G 298M 245M 3.5M 10G 10G
Swap: 3.6G 26M 3.6G

2、用dd命令创建SWAP页面交换文件

dd if=/dev/zero of=/home/.swap bs=1M count=4096

[root@linux195 ~]# dd if=/dev/zero of=/home/.swap bs=1M count=4096
记录了4096+0 的读入
记录了4096+0 的写出
4294967296字节(4.3 GB)已复制,12.6887 秒,338 MB/秒

if:输入文件
of:输出文件
bs:块大小
count:块数量

3、将SWAP文件格式化成SWAP文件系统

mkswap /home/.swap

[root@linux195 ~]# mkswap /home/.swap
正在设置交换空间版本 1,大小 = 4194300 KiB
无标签,UUID=6e28b05e-1868-45c0-82e1-0e20374bd51f

4、更改SWAP文件权限

chmod 0600 /home/.swap

5、使SWAP扩容空间有效

swapon /home/.swap

6、写入开机自动挂载

cat >> /etc/fstab << EOF
/home/.swap swap swap defaults 0 0
EOF

7、再次查看SWAP交换空间大小

[root@linux195 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:            11G        302M        235M        3.5M         10G         10G
Swap:          7.6G         26M        7.6G

发表评论