lvm 通过增加新硬盘扩容逻辑卷

ls /dev/sda >/dev/null 2>&1;
if [ $? = 0 ]; then
    /sbin/pvcreate /dev/sda
    /sbin/vgcreate domuvg /dev/sda
    /sbin/lvcreate -L 1G -n swap domuvg
    /sbin/mkswap /dev/domuvg/swap
    /sbin/swapon /dev/domuvg/swap
    echo "/dev/domuvg/swap        swap                    swap    defaults        0 0" >> /etc/fstab
    
    mkdir -p /alidata
    /sbin/lvcreate -l +100%FREE -n alidata domuvg
    /sbin/mkfs.ext4 /dev/domuvg/alidata
    if [ `ls -r /alidata |wc -l` = 0 ]; then
       /bin/mount /dev/domuvg/alidata /alidata
       echo "/dev/domuvg/alidata         /alidata                    ext4    defaults        0 0" >> /etc/fstab
    fi

fi

使用此脚本对/dev/sda做LVM,并且分成2个分区。

场景:sda做了lvm,现在容量不够,需要扩容,新添加了sdb,把sdb的容量扩容到sda里面,增加sda的容量。

1、查看现在物理卷情况
[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda
  VG Name               domuvg
  PV Size               8.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2047
  Free PE               0
  Allocated PE          2047
  PV UUID               v8b8aP-6Lq6-I3gR-f1p6-89nu-Bk67-tPA5hh

2、针对sdb建立物理卷
[root@localhost ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
 
3、查看现在物理卷情况
[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda
  VG Name               domuvg
  PV Size               8.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2047
  Free PE               0
  Allocated PE          2047
  PV UUID               v8b8aP-6Lq6-I3gR-f1p6-89nu-Bk67-tPA5hh
   
  "/dev/sdb" is a new physical volume of "5.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               5.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               yOWwty-2dfz-5DN4-aSgH-VijX-1LAT-fb8irp
 
4、添加sdb到现在的卷组中
[root@localhost ~]# vgextend domuvg /dev/sdb
  Volume group "domuvg" successfully extended

5、查看现在物理卷情况  
[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda
  VG Name               domuvg
  PV Size               8.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2047
  Free PE               0
  Allocated PE          2047
  PV UUID               v8b8aP-6Lq6-I3gR-f1p6-89nu-Bk67-tPA5hh
   
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               domuvg
  PV Size               5.00 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              1279
  Free PE               1279
  Allocated PE          0
  PV UUID               yOWwty-2dfz-5DN4-aSgH-VijX-1LAT-fb8irp
 
 
6、查看卷组的情况
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               domuvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               12.99 GiB
  PE Size               4.00 MiB
  Total PE              3326
  Alloc PE / Size       2047 / 8.00 GiB
  Free  PE / Size       1279 / 5.00 GiB
  VG UUID               VJ4tsH-IFB3-Ft1O-Rnxc-nFfw-hDNE-ggB0Az
 
 7、扩展lv的容量
 [root@localhost ~]# lvextend -l +100%FREE /dev/domuvg/alidata                   #全部扩容到/dev/domuvg/alidata此逻辑卷上
  Size of logical volume domuvg/alidata changed from 7.00 GiB (1791 extents) to 11.99 GiB (3070 extents).
  Logical volume alidata successfully resized
 
8、查看容量
[root@localhost ~]# df -Ph
Filesystem                  Size  Used Avail Use% Mounted on
/dev/sdc2                   7.3G  1.1G  5.9G  15% /
tmpfs                       939M     0  939M   0% /dev/shm
/dev/mapper/domuvg-alidata  6.8G   16M  6.4G   1% /alidata       #大小没有扩容

9、使用resize2fs扩容
[root@localhost ~]# resize2fs /dev/domuvg/alidata
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/domuvg/alidata is mounted on /alidata; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/domuvg/alidata to 3143680 (4k) blocks.
The filesystem on /dev/domuvg/alidata is now 3143680 blocks long.

[root@localhost ~]# df -Ph
Filesystem                  Size  Used Avail Use% Mounted on
/dev/sdc2                   7.3G  1.1G  5.9G  15% /
tmpfs                       939M     0  939M   0% /dev/shm
/dev/mapper/domuvg-alidata   12G   18M   12G   1% /alidata
由最初的8G扩容到了12G,增加了5G。

你可能感兴趣的:(lvm扩容,lvm增加容量,lvm增加磁盘)