1. 查看磁盘:
[root@localhost ~]# fdisk -l
......
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/sdc:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
......
2. 对两块磁盘进行lvm格式分区
fdisk /dev/sdb/ --> n --> p --> 分区号(默认) --> 起始扇区(默认) --> last扇区(默认)
# 修改分区格式
t --> 8e Linux LVM(分区格式为lvm) --> w (保存)
# 退出后对磁盘/dev/sdc 执行相同操作即可
3. 创建物理卷(PV)
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
[root@localhost ~]#
# pvdisplay 显示详细PV信息
"/dev/sdb1" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID LcLg0U-gofo-MapY-eilj-OpkQ-TYMO-nSDfh3
"/dev/sdc1" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc1
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID r9Dp6u-S1hL-EmXb-6M7c-yefR-Bzts-B0Rdtd
4. 将PV加入到卷组中(VG)
[root@localhost ~]# vgcreate vg-group /dev/sdb1 /dev/sdc1
Volume group "vg-group" successfully created
5. 创建一个10G大小的lvm
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 19.51g 0
vg-group 2 0 0 wz--n- 39.99g 39.99g
[root@localhost ~]# lvcreate -L 10G -n data vg-group
Logical volume "data" created
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.51g
swap centos -wi-ao---- 2.00g
data vg-group -wi-a----- 10.00g
6. 格式化这个lvm成xfs文件系统
[root@localhost ~]# mkfs.xfs /dev/vg-group/data # 注意这个路径是/dev/卷组名/lvm名
meta-data=/dev/vg-group/data isize=256 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.51g
swap centos -wi-ao---- 2.00g
data vg-group -wi-a----- 10.00g
[root@localhost ~]#
7. 逻辑卷扩容
使用 lvextend 命令进行逻辑卷扩容。我把所有剩余空间都分配给了data
[root@localhost ~]# lvextend -l +100%FREE /dev/vg-group/data
Extending logical volume data to 39.99 GiB
Logical volume data successfully resized
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
root centos -wi-ao---- 17.51g
swap centos -wi-ao---- 2.00g
data vg-group -wi-a----- 39.99g
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/vg-group/data /data/
[root@localhost ~]# df -hT | grep "data" # 可以看到这时候的data 只有10G,可是我们的lvm已经有40G
/dev/mapper/vg--group-data xfs 10G 33M 10G 1% /data
8. 使用xfs_growfs命令在线调整xfs格式文件系统大小
[root@localhost ~]# xfs_growfs /dev/vg-group/data
meta-data=/dev/mapper/vg--group-data isize=256 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2621440 to 10483712
[root@localhost ~]# df -hT | grep "data"
/dev/mapper/vg--group-data xfs 40G 33M 40G 1% /data
9 .加入现有的卷组中:
(1)# 查看现有卷组
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 19.51g 0
vg-group 2 1 0 wz--n- 39.99g 0
(2)#查看新加磁盘,还是先分区,然后更改lvm格式(略)
[root@localhost ~]# fdisk -l | grep sdd
磁盘 /dev/sdd:21.5 GB, 21474836480 字节,41943040 个扇区
/dev/sdd1 2048 41943039 20970496 8e Linux LVM
(3)#使用 vgextend 命令把/dev/sdd1加入到centos
[root@localhost ~]# vgextend centos /dev/sdd1
Volume group "centos" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- 39.50g 20.00g
vg-group 2 1 0 wz--n- 39.99g 0
(4)使用 lvextend 命令进行逻辑卷root扩容。我把所有剩余空间都分配给了root
[root@localhost ~]# lvextend -l +100%FREE /dev/centos/root
Extending logical volume root to 37.50 GiB
Logical volume root successfully resized
[root@localhost ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1147392 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=4589568, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4589568 to 9831424
[root@localhost ~]#
# 此时我们的根分区就得到了扩容啦;
[root@localhost ~]# df -hT | grep "root"
/dev/mapper/centos-root xfs 38G 929M 37G 3% /
注意:
pvs -- vgs -- lvs