lvextend 命令用于逻辑卷在线扩容,也就是说lvextend扩容是不需要停机的,应用服务也不需要关闭,其语法格式如下:
lvextend [参数] LogicalVolume[Path] [ PhysicalVolumePath… ]
常用参数:
-l + :指定逻辑卷的LE个数,如 -l +200
-L + :表示增加多少空间,如 -L +15G ,单位有bBsSkKmMgGtTpPeE
-l +100%FREE :表示增加vg的全部可用空间
PS:lvextend 扩展后只是扩展了lv的大小,而此时文件系统并未感知到,所有还需要使用xfs_growfs、resize2fs等命令来扩展文件系统,xfs_growf命令是扩展xfs文件系统,resize2fs是扩展ext4文件系统。
演示示例:
方法一、
[root@localhost lv_data]# lvextend -L +1G /dev/iflytek/lv_data #逻辑卷扩容,增加1个G的空间Size of logical volume iflytek/lv_data changed from 6.00 GiB (1536 extents) to 7.00 GiB (1792 extents).Logical volume iflytek/lv_data successfully resized.
[root@localhost mapper]# lvsLV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertroot cl -wi-ao---- 9.79g swap cl -wi-ao---- 1.20g lv_data iflytek -wi-ao---- 7.00g #发现lv_data其实增大到7G了
[root@localhost lv_data]# df -Th #发现/dev/mapper/iflytek-lv_data逻辑卷还是6G,这说明即使lv增大了但文件系统并未感知到lv增大了
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/cl-root xfs 9.8G 1021M 8.8G 11% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 139M 876M 14% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/mapper/iflytek-lv_data xfs 6.0G 33M 6.0G 1% /lv_data
[root@localhost lv_data]#
#哎呀,df -Th 看到的怎么是/dev/mapper/iflytek-lv_data,我们的逻辑卷文件明明是/dev/iflytek/lv_data的呀,怎么回事?
#原来这是lvm的mapper机制决定的,当我们lvcreate一个逻辑卷的时候,Linux会新建两个软链接文件,如/dev/PVName/PVName和/dev/mapper/PVName-LVName,而这2个文件都是指向/dev/dm-X 块文件的,所有,当我们使用df -h看到的/dev/mapper/iflytek-lv_data其实是和/dev/iflytek/lv_data一样的,不管我们使用哪个都是可以的。如果使用xfs文件系统xfs_growfs /dev/iflytek/lv_data
如果使用ext4文件系统resize2fs /dev/root_vg/root[root@localhost mapper]# xfs_growfs /dev/iflytek/lv_data #使用xfs_growfs命令扩展xfs文件系统,如果是ext4文件系统,则使用resize2fs /dev/iflytek/lv_data
meta-data=/dev/mapper/iflytek-lv_data isize=512 agcount=4, agsize=393216 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1572864, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
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 1572864 to 1835008
[root@localhost mapper]# df -Th #检查
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/cl-root xfs 9.8G 1021M 8.8G 11% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 139M 876M 14% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/mapper/iflytek-lv_data xfs 7.0G 33M 7.0G 1% /lv_data #大小其实增大了1G了
[root@localhost mapper]#
方法二、
[root@localhost mapper]# lvextend -l +25 /dev/iflytek/lv_data #增加25个LE就是100MSize of logical volume iflytek/lv_data changed from 7.00 GiB (1792 extents) to 7.10 GiB (1817 extents).Logical volume iflytek/lv_data successfully resized.
[root@localhost mapper]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/cl-root 10258432 1045568 9212864 11% /
devtmpfs 1921808 0 1921808 0% /dev
tmpfs 1932776 0 1932776 0% /dev/shm
tmpfs 1932776 8776 1924000 1% /run
tmpfs 1932776 0 1932776 0% /sys/fs/cgroup
/dev/sda1 1038336 141608 896728 14% /boot
tmpfs 386556 0 386556 0% /run/user/0
/dev/mapper/iflytek-lv_data 7329792 32980 7296812 1% /lv_data #查看容量大小
[root@localhost mapper]# xfs_growfs /dev/iflytek/lv_data #扩展文件系统大小
meta-data=/dev/mapper/iflytek-lv_data isize=512 agcount=5, agsize=393216 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1835008, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
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 1835008 to 1860608 #显示块已经增大了
[root@localhost mapper]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/cl-root 10258432 1045568 9212864 11% /
devtmpfs 1921808 0 1921808 0% /dev
tmpfs 1932776 0 1932776 0% /dev/shm
tmpfs 1932776 8776 1924000 1% /run
tmpfs 1932776 0 1932776 0% /sys/fs/cgroup
/dev/sda1 1038336 141608 896728 14% /boot
tmpfs 386556 0 386556 0% /run/user/0
/dev/mapper/iflytek-lv_data 7432192 32980 7399212 1% /lv_data #空间增大了
[root@localhost mapper]#
方法三、
[root@localhost mapper]# lvs #查看还有多少空间LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertroot cl -wi-ao---- 9.79g swap cl -wi-ao---- 1.20g lv_data iflytek -wi-ao---- 7.10g #还有7.10G
[root@localhost mapper]# lvextend -l +100%FREE /dev/iflytek/lv_data #把vg的全部剩余空间都加给lvSize of logical volume iflytek/lv_data changed from 7.10 GiB (1817 extents) to 13.99 GiB (3582 extents).Logical volume iflytek/lv_data successfully resized.
[root@localhost mapper]# lvs #lv确实增加了LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convertroot cl -wi-ao---- 9.79g swap cl -wi-ao---- 1.20g lv_data iflytek -wi-ao---- 13.99g
[root@localhost mapper]# vgs #iflytek卷组显示已经没有剩余空间了 VG #PV #LV #SN Attr VSize VFreecl 1 2 0 wz--n- 11.00g 4.00miflytek 2 1 0 wz--n- 13.99g 0
[root@localhost mapper]# df -Th #此时文件系统还没扩展
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/cl-root xfs 9.8G 1021M 8.8G 11% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 139M 876M 14% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/mapper/iflytek-lv_data xfs 7.1G 33M 7.1G 1% /lv_data
[root@localhost mapper]# xfs_growfs /dev/iflytek/lv_data #扩展文件系统大小
meta-data=/dev/mapper/iflytek-lv_data isize=512 agcount=5, agsize=393216 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1860608, imaxpct=25= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
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 1860608 to 3667968
[root@localhost mapper]# df -Th #文件系统已扩展
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/cl-root xfs 9.8G 1021M 8.8G 11% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 139M 876M 14% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/mapper/iflytek-lv_data xfs 14G 33M 14G 1% /lv_data
[root@localhost mapper]#