假设已新增了一块硬盘,对该硬盘做了分区,例如/dev/xvdb1和/dev/xvdb2,然后在xvdb1做了pv,即:pvcreate /dev/xvdb1
[root@localhost ~]# pvcreate /dev/xvdb1
Physical volume "/dev/xvdb1" successfully created
查看一下pv
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/xvda2
VG Name centos
PV Size 99.64 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25506
Free PE 0
Allocated PE 25506
PV UUID DBPkYM-4w0a-FRZZ-IdZn-f5cE-Qiux-npgZu3
--- Physical volume ---
PV Name /dev/xvdb1
VG Name centos
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 1
Allocated PE 1278
PV UUID dFwhMG-GcxN-1PBN-UAmF-n44S-8Jxe-c2as4l
1 查看现在的vg
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 5
Max PV 0
Cur PV 1
Act PV 1
VG Size 99.63 GiB
PE Size 4.00 MiB
Total PE 25506
Alloc PE / Size 25504 / 99.62 GiB
Free PE / Size 2 / 8.00 MiB
VG UUID SYMMXA-ncbq-1mbP-6Sth-Tvw5-0SOQ-N0bCcy
2 对现有的vg拓容
[root@localhost ~]# vgextend centos /dev/xvdb1
Volume group "centos" successfully extended
3 查看当前的lv,准备对data拓容。
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID LaY6Pl-m2Bw-3gu4-9Pi0-cwTL-XFm0-Av50bB
LV Write Access read/write
LV Creation host, time localhost, 2019-09-05 00:48:08 -0400
LV Status available
# open 1
LV Size 30.00 GiB
Current LE 7680
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID rJtnv3-zbn9-8ktB-WgmA-HHaR-znb1-TLoSG3
LV Write Access read/write
LV Creation host, time localhost, 2019-09-05 00:48:08 -0400
LV Status available
# open 2
LV Size 3.62 GiB
Current LE 928
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/data
LV Name data
VG Name centos
LV UUID 5K9XLq-Hbwu-lWVW-v4IM-u4W0-Ueyw-X2GNsz
LV Write Access read/write
LV Creation host, time localhost, 2019-09-05 00:48:09 -0400
LV Status available
# open 1
LV Size 46.00 GiB
Current LE 11776
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/home
LV Name home
VG Name centos
LV UUID aJ5Jc8-A0LF-JeJe-JKQ8-bboA-Ml8t-XfOLAG
LV Write Access read/write
LV Creation host, time localhost, 2019-09-05 00:48:10 -0400
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
--- Logical volume ---
LV Path /dev/centos/var
LV Name var
VG Name centos
LV UUID vjhqnq-i8QY-RESz-wNs0-nk4n-Evrd-kEWa2w
LV Write Access read/write
LV Creation host, time localhost, 2019-09-05 00:48:10 -0400
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:4
4 对data的lv拓容5G
[root@localhost ~]# lvextend -L 5G /dev/centos/data
New size given (1280 extents) not larger than existing size (11776 extents)
Run `lvextend --help' for more information.
发现上面的操作报错了,在网上找到了答案,人家说一定要用+号,参考: https://www.cnblogs.com/zq6041/p/6859268.html
[root@localhost ~]# lvextend -L +5G /dev/centos/data
Size of logical volume centos/data changed from 46.00 GiB (11776 extents) to 51.00 GiB (13056 extents).
Logical volume data successfully resized.
/dev/centos/data现在成功拓容5G,但如果用df -Th看的话,它的大小还是没生效的,要如何生效呢?
5 让其生效
[root@localhost ~]# resize2fs /dev/centos/data
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/centos/data
Couldn't find valid filesystem superblock.
这里也报错了,在google里找到了答案,由于centos7用的是xfs格式,所以不能用resize2fs了,要用xfs_growfs,参考:https://stackoverflow.com/questions/26305376/resize2fs-bad-magic-number-in-super-block-while-trying-to-open
[root@localhost ~]# xfs_growfs /dev/mapper/centos-data
meta-data=/dev/mapper/centos-data isize=256 agcount=4, agsize=3014656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=12058624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=5888, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 12058624 to 13369344
再来df -Th,就可以看到它生效了。
最后用lsblk查看一下前后对比
/data拓容前:
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 603M 0 rom
xvda 202:0 0 100G 0 disk
├─xvda1 202:1 0 300M 0 part /boot
└─xvda2 202:2 0 99.7G 0 part
├─centos-root 253:0 0 30G 0 lvm /
├─centos-swap 253:1 0 3.6G 0 lvm [SWAP]
├─centos-data 253:2 0 46G 0 lvm /data
├─centos-home 253:3 0 10G 0 lvm /home
└─centos-var 253:4 0 10G 0 lvm /var
xvdb 202:16 0 10G 0 disk
├─xvdb1 202:17 0 5G 0 part
└─xvdb2 202:18 0 5G 0 part
/data拓容后:
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 603M 0 rom
xvda 202:0 0 100G 0 disk
├─xvda1 202:1 0 300M 0 part /boot
└─xvda2 202:2 0 99.7G 0 part
├─centos-root 253:0 0 30G 0 lvm /
├─centos-swap 253:1 0 3.6G 0 lvm [SWAP]
├─centos-data 253:2 0 51G 0 lvm /data
├─centos-home 253:3 0 10G 0 lvm /home
└─centos-var 253:4 0 10G 0 lvm /var
xvdb 202:16 0 10G 0 disk
├─xvdb1 202:17 0 5G 0 part
│ └─centos-data 253:2 0 51G 0 lvm /data
└─xvdb2 202:18 0 5G 0 part
大小对比
拓容前:
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 30G 808M 30G 3% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs tmpfs 1.8G 8.4M 1.8G 1% /run
tmpfs tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/mapper/centos-data xfs 46G 33M 46G 1% /data
/dev/mapper/centos-var xfs 10G 66M 10G 1% /var
/dev/mapper/centos-home xfs 10G 33M 10G 1% /home
/dev/xvda1 xfs 297M 113M 185M 38% /boot
tmpfs tmpfs 354M 0 354M 0% /run/user/0
拓容后:
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 30G 808M 30G 3% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs tmpfs 1.8G 8.4M 1.8G 1% /run
tmpfs tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/mapper/centos-data xfs 51G 33M 51G 1% /data
/dev/mapper/centos-var xfs 10G 66M 10G 1% /var
/dev/mapper/centos-home xfs 10G 33M 10G 1% /home
/dev/xvda1 xfs 297M 113M 185M 38% /boot
tmpfs tmpfs 354M 0 354M 0% /run/user/0
总体过程:PV --> VG --> LV
参考资料:https://www.cnblogs.com/gaojun/archive/2012/08/22/2650229.html
https://www.cnblogs.com/xyarn/p/9579972.html
网友评论