本次测试环境,Ubuntu 24.04 ,在安装系统时候已经默认启用了一个swap,以文件方式。且已完成了fstab配置
fstab 配置参考:
ubuntu@ubuntu:~$ cat /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/sda2 during curtin installation
/dev/disk/by-uuid/c5b5e8b7-dfc6-41aa-a908-56ed6e858697 / ext4 defaults 0 1
/swap.img none swap sw 0 0
该方法可对Ubuntu的swap进行扩大或缩小
sudo swapon --show
内容参考:
NAME TYPE SIZE USED PRIO
/swap.img file 2G 0B -2
可以看到当前的swap配置文件路径/swap.img
和swap大小2G
提示:停用swap前请保证物理内存够用当前业务,否则可能导致内存数据丢失哟!!!
sudo swapoff /swap.img
sudo fallocate -l 4G /swap.img
调整权限
sudo chmod 600 /swap.img
设置swap格式
sudo mkswap /swap.img
输出内容参考:
mkswap: /swap.img: warning: wiping old swap signature.
Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
no label, UUID=ce763e5c-8f21-48a2-b153-5255193a8c31
sudo swapon /swap.img
查看启用后的swap信息
sudo swapon --show
搞定
sudo swapon --show
内容参考:
NAME TYPE SIZE USED PRIO
/swap.img file 2G 0B -2
可以看到当前的swap配置文件路径/swap.img
和swap大小2G
提示:停用swap前请保证物理内存够用当前业务,否则可能导致内存数据丢失哟!!!
sudo swapoff /swap.img
sudo mv /swap.img /swap.img.bak
sudo fallocate -l 1G /swap.img
调整权限
sudo chmod 600 /swap.img
设置swap格式
sudo mkswap /swap.img
输出内容参考:
mkswap: /swap.img: warning: wiping old swap signature.
Setting up swapspace version 1, size = 1 GiB (1294963200 bytes)
no label, UUID=ce763e5c-8f21-48a2-b153-5255193a8c31
sudo swapon /swap.img
查看启用后的swap信息
sudo swapon --show
NAME TYPE SIZE USED PRIO
/swap.img file 1G 0B -2
https://blog.xqlee.com/article/2506271452454656.html