ubuntu添加swap

root@miner:/mnt/data/nvme4# cd ../
root@miner:/mnt/data# ll
total 20
drwxr-xr-x  5 root root 4096 Dec  5 08:28 ./
drwxr-xr-x  4 root root 4096 Dec  5 07:49 ../
drwxr-xr-x  2 root root 4096 Dec  5 08:31 filecoin-proof-parameters/
drwxr-xr-x 33 root root 4096 Dec  5 07:43 lotus/
drwxr-xr-x  3 root root 4096 Dec  5 08:28 nvme4/

一、创建swap文件
root@miner:/mnt/data# fallocate -l 64g swapfile


root@miner:/mnt/data# ll
total 67108892
drwxr-xr-x  5 root root        4096 Dec  6 01:05 ./
drwxr-xr-x  4 root root        4096 Dec  5 07:49 ../
drwxr-xr-x  2 root root        4096 Dec  5 08:31 filecoin-proof-parameters/
drwxr-xr-x 33 root root        4096 Dec  5 07:43 lotus/
drwxr-xr-x  3 root root        4096 Dec  5 08:28 nvme4/
-rw-r--r--  1 root root 68719476736 Dec  6 01:05 swapfile

二、更改权限
root@miner:/mnt/data# chmod 600 swapfile

三、格式swap
root@miner:/mnt/data# mkswap swapfile


Setting up swapspace version 1, size = 64 GiB (68719472640 bytes)
no label, UUID=c1e20314-b107-409c-88c5-67fa31073712

四、启动swap
root@miner:/mnt/data# swapon swapfile

swapon是命令,swapfile是当前目录/mnt/data的文件swapfile

如果你创建的swapfile在其它目录,也可以指定目标,比如:

swapon /*/swapfile  

五、检查swap
root@miner:/mnt/data# free -h
               total        used        free      shared  buff/cache   available
Mem:            31Gi       2.2Gi        28Gi       1.0Mi       287Mi        28Gi
Swap:           71Gi       1.0Gi        70Gi
root@miner:/mnt/data# htop

六、自动挂载和验证

vi /etc/fstab 编辑挂载文件

添加行,自动挂载swap

/mnt/data/swapfile swap swap defaults 0 0
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jekc868

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值