Ubuntu 20.04安装后,默认SWAP分区容量是2GB,在编译代码时存在交换分区容量不足,导致编译失败的情况,下面展示了调整SWAP分区大小到8G的过程。
1、查看内存分区(15GB+2GB的组合)
$ free -h
total used free shared buff/cache available
Mem: 15Gi 1.6Gi 546Mi 437Mi 13Gi 13Gi
Swap: 2.0Gi 0.4Gi 1.6Gi
2、关闭SWAP分区,再查看内存分区(15GB)
$ sudo swapoff /swapfile
[sudo] password for user1234:
$ free -h
total used free shared buff/cache available
Mem: 15Gi 1.6Gi 546Mi 437Mi 13Gi 13Gi
Swap: 0B 0B 0B
备注:用户名user1234为示意值
3、调整/swapfile到8GB,并格式化。
$ sudo fallocate -l 8G /swapfile
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
mkswap: /swapfile: warning: wiping old swap signature.
Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)
no label, UUID=000a000b-000c-000d-000e-000f00010002
备注:此处UUID被处理成了示意值
4、启用SWAP分区,再查看内存分区(15G + 8G)
$ sudo swapon /swapfile
$ free -h
total used free shared buff/cache available
Mem: 15Gi 2.8Gi 148Mi 567Mi 12Gi 11Gi
Swap: 8Gi 0B 8Gi