目录方式扩展swap分区大小

1.查看swap大小:free  -m  (-k|m|g) --k|m|g为单位用去尾法显示大小

 [root@lbg tmp]# free -m

     total        used        free      shared  buff/cache   available

Mem:   984          583         71      6         329         219

Swap:  199           2         197


2.2G空的目录作为
swap.

 [root@lbg /]# dd if=/dev/zero of=/tmp/swapfile bs=1M count=2048

2048+0 records in

2048+0 records out

2147483648 bytes (2.1 GB) copied, 2.56498 s, 837 MB/s

语句说明:

 上面语句中if|of inputfileoutfile输入输出文件  bsblock size块大小  count指数量.

整体大小=bs*count,而文件/tmp/swapfiiles会自动创建,大小为2G.

[root@lbg tmp]# ll -h /tmp |grep swapfile 

-rw-r--r--  1 root root 2.0G Oct  5 00:07 swapfile


3.创建swap分区

命令: mkswap /tmp/swapfiles

[root@lbg tmp]# mkswap /tmp/swapfile 

Setting up swapspace version 1, size = 2097148 KiB

no label, UUID=d82de212-8ce7-42ed-b5bf-02c647b40b7d


4.
临时挂载swap分区(swap无挂载点)

 挂载: swapon /tmp/swapfiles    卸载:swapoff  /tmp/swapfiles

[root@lbg tmp]# swapon /tmp/swapfile

查看swap大小:

[root@lbg tmp]# free -m

   total        used        free      shared  buff/cache   available

Mem: 984         585          68           6         330         217

Swap: 2247         2        2245


5.开机自动挂载挂载

 配置文件: vim  /etc/fstab   添加一行.

/tmp/swapfile     swap            swap   defaults          0 0

原文地址:https://www.cnblogs.com/lbg-database/p/10109960.html