lvextend 逻辑卷扩容(xfs_growfs、resize2fs配合扩展文件系统)

lvextend 命令用于逻辑卷在线扩容,也就是说lvextend扩容是不需要停机的,应用服务也不需要关闭,其语法格式如下:

lvextend  [参数] 	LogicalVolume[Path] [ PhysicalVolumePath... ]

常用参数:

-l +  :指定逻辑卷的LE个数,如 -l +200
-L + :表示增加多少空间,如 -L +15G ,单位有bBsSkKmMgGtTpPeE
-l +100%FREE	:表示增加vg的全部可用空间

注意:lvextend 扩展后只是扩展了lv的大小,而此时文件系统并未感知到,所有还需要使用xfs_growfs、resize2fs等命令来扩展文件系统,xfs_growf命令是扩展xfs文件系统,resize2fs是扩展ext4文件系统。

演示示例:

方法一、
[root@localhost ~]# lvextend -L +1G /dev/mysql/lv_data 		#逻辑卷扩容,增加1G的空间
  Size of logical volume mysql/lv_data changed from 6.00 GiB (1536 extents) to 7.00 GiB (1792 extents).
  Logical volume mysql/lv_data successfully resized.
[root@localhost ~]# lvs
  LV      VG      Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root    cl      -wi-ao---- 9.79g                                                    
  swap    cl      -wi-ao---- 1.20g                                                    
  lv_data mysql -wi-ao---- 7.00g    #发现lv_data其实增大到7G了                                              
[root@localhost ~]# df -Th	#发现/dev/mapper/mysql-lv_data逻辑卷还是6G,说明即使lv增大了但文件系统并未感知到lv增大了
Filesystem                  Type      Size  Used Avail Use% Mounted on
/dev/mapper/mysql-lv_data xfs       6.0G   33M  6.0G   1% /lv_data
[root@localhost ~]# 

#哎呀,df -Th 看到的怎么是/dev/mapper/mysql-lv_data,我们的逻辑卷文件明明是/dev/mysql/lv_data的呀,怎么回事?
#原来这是lvm的mapper机制决定的,当我们lvcreate一个逻辑卷的时候,Linux会新建两个软链接文件,
#如/dev/VGName/LVName和/dev/mapper/VGName-LVName,而这2个文件都是指向/dev/dm-X 块文件的,所有,当我们使用df -h看
#到的/dev/mapper/mysql-lv_data其实是和/dev/mysql/lv_data一样的,不管我们使用哪个都是可以的。

#查看你的逻辑卷是什么文件系统类型,如果是xfs文件系统,使用xfs_growfs命令扩展容量:
xfs_growfs /dev/mysql/lv_data
#查看你的逻辑卷是什么文件系统类型,如果是ext4文件系统,使用resize2fs命令扩展容量:
resize2fs /dev/root_vg/root
 
#使用xfs_growfs命令扩展xfs文件系统,如果是ext4文件系统,则使用resize2fs  /dev/mysql/lv_data 
[root@localhost mapper]# xfs_growfs /dev/mysql/lv_data			
meta-data=/dev/mapper/mysql-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/mysql-lv_data xfs       7.0G   33M  7.0G   1% /lv_data				#大小其实增大了1G了
[root@localhost mapper]#
方法二、
[root@localhost mapper]# lvextend  -l +25 /dev/mysql/lv_data         #增加25个LE就是100M
  Size of logical volume mysql/lv_data changed from 7.00 GiB (1792 extents) to 7.10 GiB (1817 extents).
  Logical volume mysql/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/mysql-lv_data   7329792   32980   7296812   1% /lv_data				#查看容量大小
[root@localhost mapper]# xfs_growfs  /dev/mysql/lv_data 							#扩展文件系统大小
meta-data=/dev/mapper/mysql-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/mysql-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 Convert
  root    cl      -wi-ao---- 9.79g                                                    
  swap    cl      -wi-ao---- 1.20g                                                    
  lv_data mysql -wi-ao---- 7.10g                								#还有7.10G                                   
[root@localhost mapper]# lvextend -l +100%FREE /dev/mysql/lv_data 			#把vg的全部剩余空间都加给lv
  Size of logical volume mysql/lv_data changed from 7.10 GiB (1817 extents) to 13.99 GiB (3582 extents).
  Logical volume mysql/lv_data successfully resized.
[root@localhost mapper]# lvs													#lv确实增加了
  LV      VG      Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root    cl      -wi-ao----  9.79g                                                    
  swap    cl      -wi-ao----  1.20g                                                    
  lv_data mysql -wi-ao---- 13.99g                                                    
[root@localhost mapper]# vgs													#mysql卷组显示已经没有剩余空间了										
  VG      #PV #LV #SN Attr   VSize  VFree
  cl        1   2   0 wz--n- 11.00g 4.00m
  mysql   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/mysql-lv_data xfs       7.1G   33M  7.1G   1% /lv_data
[root@localhost mapper]# xfs_growfs  /dev/mysql/lv_data 						#扩展文件系统大小
meta-data=/dev/mapper/mysql-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/mysql-lv_data xfs        14G   33M   14G   1% /lv_data
[root@localhost mapper]# 






你可能感兴趣的:(LVM,逻辑卷管理,linux,运维,lvm)