linux 设置Swap分区操作

时间:2021-07-01 17:36:10   收藏:0   阅读:0

一、SWAP分区大小设置参考:

4G以内的物理内存,SWAP 设置为内存的2倍。

4-8G的物理内存,SWAP 等于内存大小。

8-64G 的物理内存,SWAP 设置为8G。

64-256G物理内存,SWAP 设置为16G。

 

二、扩充或缩小SWAP分区:

[root@node1 ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       1048572 0       -1
[root@node1 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1861        402       1458          1         30        136
-/+ buffers/cache:        235       1626
Swap:         1023          0       1023

  

[root@node1 ~]# swapoff  /dev/mapper/vg_node1-lv_swap
[root@node1 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1861        402       1459          1         30        136
-/+ buffers/cache:        235       1626
Swap:            0          0          0

[root@node1 ~]# fdisk -l

Disk /dev/mapper/vg_node1-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

  

[root@node1 ~]# lvextend -L 2G /dev/mapper/vg_node1-lv_swap
  Size of logical volume vg_node1/lv_swap changed from 1.00 GiB (256 extents) to 2.00 GiB (512 extents).
  Logical volume lv_swap successfully resized

最后要使用resizefs2命令重新加载逻辑卷的大小才能生效
resize2fs   
/dev/mapper/vg_node1-lv_swap

[root@node1 ~]# free -m
total used free shared buffers cached
Mem: 1861 403 1458 1 30 136
-/+ buffers/cache: 236 1625
Swap: 2047 0 2047

格式化swap分区命令:  

mkswap /dev/mapper/vg_node1-lv_swap

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!