linux 設定Swap分割槽操作
阿新 • • 發佈:2021-07-01
一、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