承接上篇文章扩容磁盘空间后增加根分区的大小后,来扩容swap分区的空间
检查当前的swap分区情况
# free -m
# free -g
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem:
Swap:
[root@localhost ~]#
[root@localhost ~]# free -g
total used free shared buff/cache available
Mem:
Swap:
查看磁盘分区挂载情况:
# cat /etc/fstab
[root@localhost ~]# cat /etc/fstab #
# /etc/fstab
# Created by anaconda on Fri Feb ::
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(), findfs(), mount() and/or blkid() for more info
#
/dev/mapper/centos-root / xfs defaults
UUID=a3983c4b-cce5-47b8-b1f7-f9c7d177d034 /boot xfs defaults
/dev/mapper/centos-swap swap swap defaults
[root@localhost ~]#
查看交换分区大小
# fdisk -l /dev/mapper/centos-swap
[root@localhost ~]# fdisk -l /dev/mapper/c
centos-root centos-swap control
[root@localhost ~]# fdisk -l /dev/mapper/centos-swap Disk /dev/mapper/centos-swap: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
查看逻辑卷
# lvdisplay
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID hw5xxY-pk8O-tFdd-RWXj-Kjzd-YlXG-55aifc
LV Write Access read/write
LV Creation host, time localhost.localdomain, -- :: +
LV Status available
# open
LV Size 115.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID Gjc4kX-XGS5-0H42-WVIJ-jllu-W9Ql-TQ7Je8
LV Write Access read/write
LV Creation host, time localhost.localdomain, -- :: +
LV Status available
# open
LV Size 2.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : [root@localhost ~]#
新增分区
#fdisk /dev/sda
需要重启才能生效
#reboot
重启后查看硬盘信息
# lsblk
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda : 150G disk
├─sda1 : 200M part /boot
├─sda2 : 17G part
│ ├─centos-root : 115G lvm /
│ └─centos-swap : 2G lvm [SWAP]
├─sda3 : 100G part
│ └─centos-root : 115G lvm /
└─sda4 : .8G part
sr0 : 4G rom
分区格式化
# mkfs -t ext4 /dev/sda4
[root@localhost ~]# mkfs -t ext4 /dev/sda4
mke2fs 1.42. (-Dec-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , , ,
, Allocating group tables: done
Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done
创建物理卷
# pvcreate /dev/sda4
[root@localhost ~]# pvcreate /dev/sda4
WARNING: ext4 signature detected on /dev/sda4 at offset . Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sda4.
Physical volume "/dev/sda4" successfully created
加入根分区的逻辑卷组
# vgextend centos /dev/sda3
查看确认
# vgdisplay
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 149.79 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / 117.00 GiB
Free PE / Size / 32.79 GiB
VG UUID a27Boi-C0ue-9PCo-1rPZ-BsjW-9IRg-Woh4uX
卸载swap分区
# swapoff /dev/mapper/centos-swap
扩展swap逻辑卷
# lvextend -L +2G /dev/mapper/centos-swap
[root@localhost ~]# swapoff /dev/mapper/centos-swap
[root@localhost ~]#
[root@localhost ~]# lvextend -L +2G /dev/mapper/centos-swap
Size of logical volume centos/swap changed from 2.00 GiB ( extents) to 4.00 GiB ( extents).
Logical volume swap successfully resized.
[root@localhost ~]#
[root@localhost ~]# fdisk -l /dev/mapper/centos-swap Disk /dev/mapper/centos-swap: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes [root@localhost ~]#
格式化新swap分区
# mkswap /dev/mapper/centos-swap
[root@localhost ~]# mkswap /dev/mapper/centos-swap
mkswap: /dev/mapper/centos-swap: warning: wiping old swap signature.
Setting up swapspace version , size = KiB
no label, UUID=05ed5220-b350-4bb1--f75dbe35b0ba
重新挂载swap分区
# swapon /dev/mapper/centos-swap
[root@localhost ~]# swapon /dev/mapper/centos-swap
[root@localhost ~]#
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem:
Swap:
重启系统验证
#reboot
# free -m
[root@localhost ~]# free -m
total used free shared buff/cache available
Mem:
Swap:
[root@localhost ~]#
至此swap分区扩容完毕
参考博客:
Linux swap扩容
https://www.cnblogs.com/rangle/p/9075370.html
end