一、 创建swap分区介绍:
1.查看swap分区
free命令
2. 使用dd命令创建一个swap分区
dd if=/dev/zero of=/home/swap bs=1M count=2048
注:if表示infile, of表示outfile, bs=1M代表增加的模块大小,count=2048代表是2048个模块,也就是2G空间大小。count的计算公式:count = size * bs (size以MB为单位)
3. 格式化分区文件
mkswap /home/swap
4. swapon命令激活swap
swapon /home/swap
注:如果需要关闭swap分区,执行swapoff /home/swap
5. 写入/etc/fstab文件
在/etc/fstab文件末尾加上 /home/swap swap swap default 0 0
二、创建示例:
[root@cwcsb-gxcwy832-xnce-1 ~]# free -m
total used free shared buff/cache available
Mem: 32010 355 31195 8 459 31275
Swap: 0 0 0
[root@cwcsb-gxcwy832-xnce-1 ~]# dd if=/dev/zero of=/home/swap bs=1M count=32768
32768+0 records in
32768+0 records out
34359738368 bytes (34 GB) copied, 157.983 s, 217 MB/s
[root@cwcsb-gxcwy832-xnce-1 ~]# swapon /home/swap
swapon: /home/swap: insecure permissions 0644, 0600 suggested.
[root@cwcsb-gxcwy832-xnce-1 ~]# free -m
total used free shared buff/cache available
Mem: 32010 381 675 8 30953 31161
Swap: 32767 0 32767
[root@cwcsb-gxcwy832-xnce-1 ~]# echo "/home/swap swap swap defaults 0 0" >> /etc/fstab
三、 swap分区大小建议