Linux创建swap分区

一、 创建swap分区介绍:

1.查看swap分区

  free命令

2. 使用dd命令创建一个swap分区

  dd if=/dev/zero of=/home/swap bs=1M count=2048

   注:if表示infile, of表示outfile, bs=1M代表增加的模块大小,count=2048代表是2048个模块,也就是2G空间大小。count的计算公式:count = size * bs (size以MB为单位)

3. 格式化分区文件

  mkswap /home/swap 

4. swapon命令激活swap

  swapon /home/swap

  注:如果需要关闭swap分区,执行swapoff /home/swap

5. 写入/etc/fstab文件

   在/etc/fstab文件末尾加上     /home/swap swap swap default 0 0

 二、创建示例:

[root@cwcsb-gxcwy832-xnce-1 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:          32010         355       31195           8         459       31275
Swap:             0           0           0
[root@cwcsb-gxcwy832-xnce-1 ~]# dd if=/dev/zero of=/home/swap bs=1M count=32768
32768+0 records in
32768+0 records out
34359738368 bytes (34 GB) copied, 157.983 s, 217 MB/s
[root@cwcsb-gxcwy832-xnce-1 ~]# swapon /home/swap
swapon: /home/swap: insecure permissions 0644, 0600 suggested.
[root@cwcsb-gxcwy832-xnce-1 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:          32010         381         675           8       30953       31161
Swap:         32767           0       32767
[root@cwcsb-gxcwy832-xnce-1 ~]# echo "/home/swap swap swap defaults  0 0" >> /etc/fstab


三、 swap分区大小建议

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值