LVM分区扩容
应用场景:
新增一块20G硬盘,将/data目录容量扩容至40G
1 创建新磁盘分区
$ parted /dev/sdc
GNU Parted 3.1
使用 /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
# 设置标识
(parted) mklabel gpt
# 设置分区
(parted) mkpart
# 设置分区名称为分区1
分区名称? []? 1
# 设置文件系统类型为ext4
文件系统类型? [ext2]? ext4
# 设置分区容量为20G
起始点? 0
结束点? 20G
警告: The resulting partition is not properly aligned for best performance.
# 忽略错误
忽略/Ignore/放弃/Cancel? ignore
# 查询分区
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 17.4kB 20.0GB 20.0GB q
# 退出分区配置
(parted) quit
信息: You may need to update /etc/fstab.
2 创建PV,加入原有VG组
2.1 创建PV
$ pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
2.2 加入vgdata VG组
$ vgextend vgdata /dev/sdc1
Volume group "vgdata" successfully extended
2.3 查询VG组容量,此时vgdata VG组为37.25 G
$ vgdisplay
--- Volume group ---
VG Name vgdata
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 37.25 GiB
PE Size 4.00 MiB
Total PE 9536
Alloc PE / Size 4768 / 18.62 GiB
Free PE / Size 4768 / 18.62 GiB
VG UUID 0sxWp5-DmBB-GMZV-uEim-Av9j-0i9U-Np0Kb1
2.4 查询LV容量,此时LV容量为18.62G
$ lvdisplay
--- Logical volume ---
LV Path /dev/vgdata/lv-data
LV Name lv-data
VG Name vgdata
LV UUID RDgp1l-1CNo-dhCg-cktx-Gdpa-WfGU-j7xEvL
LV Write Access read/write
LV Creation host, time centos7_4, 2022-12-07 16:41:08 +0800
LV Status available
# open 1
LV Size 18.62 GiB
Current LE 4768
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
3. 扩容VG组所有容量给LV
$ lvextend -r -l +100%FREE /dev/vgdata/lv-data
Size of logical volume vgdata/lv-data changed from 18.62 GiB (4768 extents) to 37.25 GiB (9536 extents).
Logical volume vgdata/lv-data successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vgdata-lv--data is mounted on /data; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 5
The filesystem on /dev/mapper/vgdata-lv--data is now 9764864 blocks long.
4. 验证
此时/data目录容量为37.3G
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 39G 0 part
├─centos-root 253:0 0 37G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 18.6G 0 part
└─vgdata-lv--data 253:2 0 37.3G 0 lvm /data
sdc 8:32 0 20G 0 disk
└─sdc1 8:33 0 18.6G 0 part
└─vgdata-lv--data 253:2 0 37.3G 0 lvm /data
sr0 11:0 1 4.4G 0 rom
5. 扩容指定大小容量
5.1 查询文件系统类型
$ df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 12M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 37G 9.6G 28G 26% /
/dev/sda1 xfs 1014M 151M 864M 15% /boot
/dev/mapper/vgdata-lv--data ext4 37G 48M 35G 1% /data
tmpfs tmpfs 378M 0 378M 0% /run/user/0
5.2 将LV扩容,增加5G
$ lvextend -L +5G /dev/vgdata/lv-data
5.3 刷新文件系统
$ resize2fs /dev/vgdata/lv-data
- 文件系统类型为ext4使用resize2fs命令,如果文件系统类型为xfs则使用xfs_growfs命令
$ xfs_growfs /dev/vgdata/lv-data
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
运维小记!
喜欢就支持一下吧
打赏
微信
支付宝