LVM扩容(centos7)
一 、LVM扩容准备
1.1 查看fdisk
fdisk -l
# 输出如下
磁盘 /dev/vda:214.7 GB, 214748364800 字节,419430400 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000ad73e
设备 Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 419430399 208665600 8e Linux LVM
磁盘 /dev/vdb:67 MB, 67108864 字节,131072 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/cl-root:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/cl-swap:4160 MB, 4160749568 字节,8126464 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/cl-home:155.8 GB, 155818393600 字节,304332800 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/vdc:322.1 GB, 322122547200 字节,629145600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
1.2 查看所有存储设备
fdisk -l |grep '/dev'
# 输出如下
# 挂载的第一块磁盘 214.7GB
磁盘 /dev/vda:214.7 GB, 214748364800 字节,419430400 个扇区
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 419430399 208665600 8e Linux LVM
磁盘 /dev/vdb:67 MB, 67108864 字节,131072 个扇区
磁盘 /dev/mapper/cl-root:53.7 GB, 53687091200 字节,104857600 个扇区
磁盘 /dev/mapper/cl-swap:4160 MB, 4160749568 字节,8126464 个扇区
磁盘 /dev/mapper/cl-home:155.8 GB, 155818393600 字节,304332800 个扇区
# 挂载的第一块磁盘 322.1GB
磁盘 /dev/vdc:322.1 GB, 322122547200 字节,629145600 个扇区
二、开始LVM扩容
2.1 创建 vdc 分区
fdisk /dev/vdc
# 输出如下
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x5252534b 创建新的 DOS 磁盘标签。
## 在此处输入命令
## n:新建分区
## l: 选择逻辑分区,如果没有,则首先创建主分区(p),然后再添加逻辑分区(硬盘最多四个分区 P-P-P-P 或 P-P-P-E)
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-629145599,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-629145599,默认为 629145599):
将使用默认值 629145599
分区 1 已设置为 Linux 类型,大小设为 300 GiB
## 在此处输入命令
## w:写入磁盘
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
2.1 格式化磁盘
fdisk -l |grep '/dev'
# 输出如下
磁盘 /dev/vda:214.7 GB, 214748364800 字节,419430400 个扇区
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 419430399 208665600 8e Linux LVM
磁盘 /dev/vdb:67 MB, 67108864 字节,131072 个扇区
磁盘 /dev/mapper/cl-root:53.7 GB, 53687091200 字节,104857600 个扇区
磁盘 /dev/mapper/cl-swap:4160 MB, 4160749568 字节,8126464 个扇区
磁盘 /dev/mapper/cl-home:155.8 GB, 155818393600 字节,304332800 个扇区
磁盘 /dev/vdc:322.1 GB, 322122547200 字节,629145600 个扇区
# 新建分区
/dev/vdc1 2048 629145599 314571776 83 Linux
- 格式化磁盘 (由于需要扩容的磁盘格式为 xfs ,所以将待添加的磁盘也格式化为 xfs)
mkfs -t xfs /dev/vdc1
# 输出如下
meta-data=/dev/vdc1 isize=512 agcount=4, agsize=19660736 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=78642944, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=38399, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
2.2 创建PV (Physical volume)
pvcreate /dev/vdc1
# 输出如下
WARNING: xfs signature detected on /dev/vdc1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/vdc1.
Physical volume "/dev/vdc1" successfully created.
2.3 查看创建的PV
pvscan
# 输出如下
PV /dev/vda2 VG cl lvm2 [199.00 GiB / 4.00 MiB free]
PV /dev/vdc1 lvm2 [300.00 GiB]
Total: 2 [499.00 GiB] / in use: 1 [199.00 GiB] / in no VG: 1 [300.00 GiB]
2.4 扩容VG(Volume group)
vgdisplay
# 输出如下
--- Volume group ---
VG Name cl
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 50942 / 198.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID xfaMPr-fYi6-hl5X-clbz-24mx-kZII-BicOtP
vgextend cl /dev/vdc1
# 输出如下
Volume group "cl" successfully extended
2.5 扩容LV(Logical volume)
lvdisplay
# 输出如下
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID 4mo9rw-EfNa-auo1-kmaj-7N0c-2jem-rjqgtD
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-06-26 14:56:07 +0800
LV Status available
# open 2
LV Size 3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/cl/home
LV Name home
VG Name cl
LV UUID 70Qr13-MTC5-k4SQ-DcmU-PUvU-IABZ-iu8QWv
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-06-26 14:56:08 +0800
LV Status available
# open 1
LV Size 145.12 GiB
Current LE 37150
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/cl/root
LV Name root
VG Name cl
LV UUID HISItN-j9Qc-EdJ7-RfD4-fFdl-rLg6-OKzeC0
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-06-26 14:56:09 +0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
- 由于我们要将磁盘扩容至根节点,所以,操作的 LV 为 /dev/cl/root
- 扩容LV ( 将所有的容量都扩容到 /dev/cl/root )
lvextend -l +100%FREE /dev/cl/root
# 输出如下
Size of logical volume cl/root changed from 50.00 GiB (12800 extents) to 350.00 GiB (89600 extents).
Logical volume cl/root successfully resized.
- 磁盘格式为 xfs ,刷新命令为:xfs_growfs /dev/cl/root
- 磁盘格式为 ext4 ,刷新命令为: resize2fs /dev/cl/root
xfs_growfs /dev/cl/root
# 输出如下
meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 91750400
lvdisplay
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID 4mo9rw-EfNa-auo1-kmaj-7N0c-2jem-rjqgtD
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-06-26 14:56:07 +0800
LV Status available
# open 2
LV Size 3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/cl/home
LV Name home
VG Name cl
LV UUID 70Qr13-MTC5-k4SQ-DcmU-PUvU-IABZ-iu8QWv
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-06-26 14:56:08 +0800
LV Status available
# open 1
LV Size 145.12 GiB
Current LE 37150
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/cl/root
LV Name root
VG Name cl
LV UUID HISItN-j9Qc-EdJ7-RfD4-fFdl-rLg6-OKzeC0
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-06-26 14:56:09 +0800
LV Status available
# open 1
LV Size 350.00 GiB
Current LE 89600
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
- 可以看到,最后的 LV : /dev/cl/root 已经由50G增加到了350G