ubuntu20.04调整swap空间大小

1.查看当前Swap大小

zc@192:~/android10/rk3328_q_20210526$ free -m
              total        used        free      shared  buff/cache   available
Mem:          31996         741         242          22       31013       30766
Swap:             0           0           0

2.停止Swap

root@androidserver-3:/# swapoff /swap.img

3.删除当前Swap

root@androidserver-3:~# rm /swap.img 

4.新建Swap

root@androidserver-3:/# dd if=/dev/zero of=/swap.img bs=1024 count=32000000
32000000+0 records in
32000000+0 records out
32768000000 bytes (33 GB, 31 GiB) copied, 225.37 s, 145 MB/s

5.启用新的Swap

root@androidserver-3:~# chmod 600 /swap.img 
root@androidserver-3:/# mkswap -f /swap.img
Setting up swapspace version 1, size = 30.5 GiB (32767995904 bytes)
no label, UUID=6091f578-442b-44f8-8ddb-864f739bca4a
root@androidserver-3:/# swapon /swap.img

6.检查新的Swap是否生效

root@androidserver-3:/# free -m
              total        used        free      shared  buff/cache   available
Mem:          31996         721         248          27       31026       30781
Swap:         31249           0       31249

root@androidserver-3:/# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/swap.img                               file            31999996        1548    -2

你可能感兴趣的:(ubuntu20.04调整swap空间大小)