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