linux系统中扩容逻辑卷步骤


逻辑卷解决的问题为动态调整磁盘空间的大小,而实现这个功能的关键在于逻辑卷可以动态的调整大小。

只要卷组中有足够的存储资源,就可以对逻辑卷扩容

 

1、查看系统中当前的逻辑卷

[root@PC1linuxprobe dev]# lvscan ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit ACTIVE '/dev/rhel/root' [17.51 GiB] inherit  ACTIVE '/dev/vg1/lv1' [100.00 MiB] inherit ACTIVE '/dev/vg1/lv2' [200.00 MiB] inherit

由上可知逻辑卷lv1的大小为100Mb,逻辑卷lv2的大小为200Mb。

 

2、查看系统中当前的卷组

[root@PC1linuxprobe dev]# vgscan Reading all physical volumes. This may take a while... Found volume group "rhel" using metadata type lvm2  Found volume group "vg1" using metadata type lvm2 [root@PC1linuxprobe dev]# vgdisplay --- Volume group --- VG Name rhel System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.51 GiB PE Size 4.00 MiB Total PE 4994 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 0 / 0 VG UUID UWd4dl-0vSA-zern-l7on-XLj0-e3cR-AHmckC --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 59.99 GiB PE Size 4.00 MiB Total PE 15357 Alloc PE / Size 75 / 300.00 MiB Free PE / Size 15282 / 59.70 GiB VG UUID Bjeykx-Lulw-rdC5-s1MV-9MSE-5G1y-hbYaHl

由上可知,卷组vg1的大小剩余为59.70 GiB。

 

3、扩容逻辑卷前,解除逻辑卷与挂载点的关联,即卸载,上一个实验未挂载,因此此处省略卸载

[root@PC1linuxprobe dev]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root   18G  2.9G   15G  17% / devtmpfs 985M 0  985M   0% /dev tmpfs 994M 140K 994M 1% /dev/shm tmpfs 994M 8.9M  986M   1% /run tmpfs 994M 0  994M   0% /sys/fs/cgroup /dev/sda1              497M  119M  379M  24% /boot /dev/sr0               3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64

 

4、将逻辑卷lv2的大小由200Mb扩容为500Mb。

[root@PC1linuxprobe dev]# lvscan ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit ACTIVE '/dev/rhel/root' [17.51 GiB] inherit ACTIVE '/dev/vg1/lv1' [100.00 MiB] inherit ACTIVE '/dev/vg1/lv2' [200.00 MiB] inherit [root@PC1linuxprobe dev]# lvextend -L 500M /dev/vg1/lv2 Extending logical volume lv2 to 500.00 MiB Logical volume lv2 successfully resized [root@PC1linuxprobe dev]# lvscan ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit ACTIVE '/dev/rhel/root' [17.51 GiB] inherit ACTIVE '/dev/vg1/lv1' [100.00 MiB] inherit  ACTIVE '/dev/vg1/lv2' [500.00 MiB] inherit

 

5、检查硬盘完整性(未通过,上一个实验没有挂载,也就没有格式化为exf4文件系统)

[root@PC1linuxprobe dev]# e2fsck -f /dev/vg1/lv2 e2fsck 1.42.9 (28-Dec-2013) ext2fs_open2: Bad magic number in super-block e2fsck: Superblock invalid, trying backup blocks... e2fsck: Bad magic number in super-block while trying to open /dev/vg1/lv2 The superblock could not be read or does not describe a correct ext2 filesystem. If the device is valid and it really contains an ext2 filesystem (and not swap or ufs or something else), then the superblock is corrupt, and you might try running e2fsck with an alternate superblock: e2fsck -b 8193 <device>

 

6、将逻辑卷lv2格式化ext4文件系统

[root@PC1linuxprobe dev]# mkfs.ext4 /dev/vg1/lv2 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 128016 inodes, 512000 blocks 25600 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=34078720
63 block groups 8192 blocks per group, 8192 fragments per group 2032 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done 

 

6、再次检查磁盘的完整性

[root@PC1linuxprobe dev]# e2fsck -f /dev/vg1/lv2 e2fsck 1.42.9 (28-Dec-2013) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg1/lv2: 11/128016 files (0.0% non-contiguous), 26684/512000 blocks

 

7、重置磁盘容量

[root@PC1linuxprobe dev]# resize2fs /dev/vg1/lv2 resize2fs 1.42.9 (28-Dec-2013) The filesystem is already 512000 blocks long.  Nothing to do!

 

8、挂载

[root@PC1linuxprobe dev]# mkdir /lvmounttest [root@PC1linuxprobe dev]# mount /dev/vg1/lv2 /lvmounttest/ [root@PC1linuxprobe dev]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root   18G  2.9G   15G  17% / devtmpfs 985M 0  985M   0% /dev tmpfs 994M 140K 994M 1% /dev/shm tmpfs 994M 8.9M  986M   1% /run tmpfs 994M 0  994M   0% /sys/fs/cgroup /dev/sda1              497M  119M  379M  24% /boot /dev/sr0               3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64 /dev/mapper/vg1-lv2 477M 2.3M 445M 1% /lvmounttest

 

总结:扩容逻辑卷

  • 卸载(解除逻辑卷与挂载点的关联)】
  • 扩容,示例:lvextend -L xxM /dev/vg1/lv1
  • 格式化为exf4文件系统,示例:mkfs.exf4 /dev/vg1/lv1
  • 检查文件系统的完整性,示例:e2fsck -f /dev/vg1/lv1
  • 重置逻辑卷大小,示例:resize2fs /dev/vg1/lv1
  • 重新挂载

注:逻辑卷扩容后(lvextend)之后,还要检查文件系统的完整性,重置逻辑卷容量,才可以挂载使用

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM