转载请注明转载自:忆雨林枫

Linux LVM 扩展磁盘分区

[root@YYINFOR-DB ~]# fdisk -l

[root@YYINFOR-DB ~]# fdisk /dev/sdd             —先创建磁盘分区

[root@YYINFOR-DB ~]# partx -a /dev/sdd1 /dev/sdd
[root@YYINFOR-DB ~]# partx /dev/sdd
# 1: 63-629137529 (629137467 sectors, 322118 MB)
# 2: 0- -1 ( 0 sectors, 0 MB)
# 3: 0- -1 ( 0 sectors, 0 MB)
# 4: 0- -1 ( 0 sectors, 0 MB)
[root@YYINFOR-DB ~]# pvcreate /dev/sdd1        —-创建新的pv 
dev_is_mpath: failed to get device for 8:49
Physical volume “/dev/sdd1” successfully created

[root@YYINFOR-DB ~]# lvs              —显示当前分区的成员和相关信息
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lvdata01 vgdata01 -wi-ao—- 160.00g
lvdata02 vgdata01 -wi-ao—- 39.89g
[root@YYINFOR-DB ~]# vgs               —显示当前组的信息
VG #PV #LV #SN Attr VSize VFree
vgdata01 2 2 0 wz–n- 199.99g 100.00m
[root@YYINFOR-DB ~]# vgextend vgdata01 /dev/sdd1            —–将/dev/sdd1 添加到群组vgdata01中
Volume group “vgdata01” successfully extended
[root@YYINFOR-DB ~]# lvextend -L +100G /dev/vgdata01/lvdata02             — 给lvdata02扩展100G的空间
Extending logical volume lvdata02 to 139.89 GiB
Logical volume lvdata02 successfully resized
[root@YYINFOR-DB ~]# resize2fs /dev/vgdata01/lvdata02          —同步扩展的信息,使得系统显示扩展的大小
resize2fs 1.41.12 (17-May-2010)
resize2fs: Bad magic number in super-block 当尝试打开 /dev/vgdata01/lvdata02 时找不到有效的文件系统超级块.
[root@YYINFOR-DB ~]# vgdisplay
— Volume group —
VG Name vgdata01
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 499.98 GiB
PE Size 4.00 MiB
Total PE 127996
Alloc PE / Size 76773 / 299.89 GiB
Free PE / Size 51223 / 200.09 GiB
VG UUID FccfpX-GNaI-LkU7-01Zo-MmV5-CXXN-AgZ9kq

[root@YYINFOR-DB ~]# lvdisplay
— Logical volume —
LV Path /dev/vgdata01/lvdata01
LV Name lvdata01
VG Name vgdata01
LV UUID wubVG0-YNJe-ZZtW-EqNi-GuBe-AeAu-XwLxqx
LV Write Access read/write
LV Creation host, time YYINFOR-DB, 2017-04-24 18:22:18 +0800
LV Status available
# open 1
LV Size 160.00 GiB
Current LE 40960
Segments 2
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0

— Logical volume —
LV Path /dev/vgdata01/lvdata02
LV Name lvdata02
VG Name vgdata01
LV UUID 5s7bJ0-jeH0-O31U-2znf-lW6S-x1nf-5zPDeY
LV Write Access read/write
LV Creation host, time YYINFOR-DB, 2017-04-24 18:24:20 +0800
LV Status available
# open 1
LV Size 139.89 GiB
Current LE 35813
Segments 2
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:1

[root@YYINFOR-DB ~]# xfs_growfs /dev/vgdata01/lvdata02     —xfs文件格式的方法
meta-data=/dev/mapper/vgdata01-lvdata02 isize=256 agcount=4, agsize=2614528 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=10458112, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=5106, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 10458112 to 36672512
[root@YYINFOR-DB ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 54G 4.7G 46G 10% /
tmpfs 16G 9.7G 6.1G 62% /dev/shm
/dev/sda2 77G 43G 31G 58% /arc_log
/dev/sda7 20G 264M 18G 2% /home
/dev/sda5 39G 9.4G 28G 26% /opt
/dev/sda3 77G 64G 9.5G 87% /oradata
/dev/mapper/vgdata01-lvdata01 160G 40G 120G 26% /db_backup
/dev/mapper/vgdata01-lvdata02 140G 33G 107G 24% /oradata/zhangdata