Linux 增加 swap 分区
- 检查当前swap分区
[root@localhost ~]# free -g
total used free shared buffers cached
Mem: 15 0 14 0 0 0
-/+ buffers/cache: 0 15
Swap: 0 0 0
- 增加交换分区文件及大小
检查没有swap,需要增加。
[root@localhost /]# mkdir swap
[root@localhost /]# cd swap/
[root@localhost swap]# ls
[root@localhost swap]# dd if=/dev/zero of=swapfile bs=4k count=1000000
记录了1000000+0 的读入
记录了1000000+0 的写出
4096000000字节(4.1 GB)已复制,4.36106 秒,939 MB/秒
[root@localhost swap]# mkswap swapfile
mkswap: swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 3999996 KiB
no label, UUID=fabcfe27-add9-418a-9666-c5b5d68335f4
- 启用交换分区
[root@localhost swap]# swapon swapfile
[root@localhost swap]# free -g
total used free shared buffers cached
Mem: 15 9 5 0 0 8
-/+ buffers/cache: 0 14
Swap: 3 0 3
- 开机自动挂载
[root@localhost swap]# vim /etc/fstab
/swap/swapfile swap swap defaults 0 0
[root@localhost swap]# mount -a
[root@localhost swap]# free -g
total used free shared buffers cached
Mem: 15 9 5 0 0 8
-/+ buffers/cache: 0 14
Swap: 3 0 3
浙公网安备 33010602011771号