1.获取root
light@root:~$ su 密码:
2.创建swap文件夹
mkdir /opt/swap
3.创建初始化swap的空间大小 count=5G 这里要从新分配大小,要等待几分钟
dd if=/dev/zero of=/opt/swap/swapfile bs=1024 count=5000000
4.转换成swap文件
mkswap /opt/swap/swapfile
5.挂载或取消挂载
挂载: swapon /opt/swap/swapfile
卸载: swapoff /opt/swap/swapfile
6.free -h查看分区大小
root@root:/home/light# free -h total used free shared buff/cache available Mem: 11G 10G 170M 191M 668M 371M Swap: 12G 244M 12G
7.开机启动后自动挂载swap,编辑/ets/tstab文件,添加如下红色内容就可以了
root@root:/home/light# nano /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
UUID=e9a5c5e0-b57f-4afe-ad25-d13905a48a1b / ext4 errors=remount-ro 0 1
# /home was on /dev/sda8 during installation
UUID=3d6a9e10-7a1d-4927-9b4b-0e436075b748 /home ext4 defaults 0 2
# /tmp was on /dev/sda7 during installation
UUID=f571c2e6-e5fe-4647-a46f-82997a609279 /tmp ext4 defaults 0 2
# /var was on /dev/sda5 during installation
UUID=0f2c8ca9-ddf1-4f87-bc7f-a5f31781945d /var ext4 defaults 0 2
# swap was on /dev/sda6 during installation
UUID=714af2b7-eaff-422d-9db0-e2b4a16cf8b3 none swap sw 0 0
/opt/sawp/swapfile swap swap defaults 0 0