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