welcome: please sign in
location: LinuxLVM

Content Migrated to Confluence: https://osmium.morningside.edu/confluence/x/awEhAQ

LinuxLVM is the Linux Logical Volume Manager and lets us abstract multiple disks into a single unit for the OS.

Task: Extending a Volume Group (VG) by adding a disk

Add the disk in VMWare, it should be detected by the system:

[866709.554860] vmw_pvscsi: msg type: 0x0 - MSG RING: 1/0 (5) 
[866709.554868] vmw_pvscsi: msg: device added at scsi0:1:0
[866709.557848] scsi 0:0:1:0: Direct-Access     VMware   Virtual disk     1.0  PQ: 0 ANSI: 2
[866709.565517] sd 0:0:1:0: Attached scsi generic sg2 type 0
[866709.568571] sd 0:0:1:0: [sdb] 20971520 512-byte logical blocks: (10.7 GB/10.0 GiB)
[866709.568601] sd 0:0:1:0: [sdb] Write Protect is off
[866709.568605] sd 0:0:1:0: [sdb] Mode Sense: 61 00 00 00
[866709.568636] sd 0:0:1:0: [sdb] Cache data unavailable
[866709.568639] sd 0:0:1:0: [sdb] Assuming drive cache: write through
[866709.569095] sd 0:0:1:0: [sdb] Cache data unavailable
[866709.569099] sd 0:0:1:0: [sdb] Assuming drive cache: write through
[866709.575843]  sdb: unknown partition table
[866709.576033] sd 0:0:1:0: [sdb] Cache data unavailable
[866709.576037] sd 0:0:1:0: [sdb] Assuming drive cache: write through
[866709.576092] sd 0:0:1:0: [sdb] Attached SCSI disk

If it is not (for instance, CentOS 5 systems don't detect this), you will need to rescan the scsi bus:

echo "- - -" > /sys/class/scsi_host/host0/scan

Note the size of the VG:

[root@CentOS7Fantasy ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_centos7fantasy
  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               15.51 GiB
  PE Size               4.00 MiB
  Total PE              3970
  Alloc PE / Size       3970 / 15.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               4yN1qy-jOS8-11sz-I0ge-7xt7-5Msk-ioS528

Try to extend the VG onto it:

[root@CentOS7Fantasy ~]# vgextend centos_centos7fantasy /dev/sdb
  Physical volume "/dev/sdb" successfully created
  Volume group "centos_centos7fantasy" successfully extended

Confirm size changes again:

[root@CentOS7Fantasy ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_centos7fantasy
  ...
  Cur PV                2
  Act PV                2
  VG Size               25.50 GiB
  Total PE              6529
  Alloc PE / Size       3970 / 15.51 GiB
  Free  PE / Size       2559 / 10.00 GiB

Task: Extending a Volume Group (VG) by enlarging a disk

For this example, suppose /dev/sdb is the physical volume that we've just enlarged in VMWare.

We must prompt Linux to rescan it;

[root@CentOS7Fantasy ~]# ls /sys/class/scsi_disk/
0:0:0:0  0:0:1:0
[root@CentOS7Fantasy ~]# echo '1' > /sys/class/scsi_disk/0\:0\:0\:0/device/rescan
[root@CentOS7Fantasy ~]# echo '1' > /sys/class/scsi_disk/0\:0\:1\:0/device/rescan

To rescan all disks:

root@webapps2: ~ 
# for hdd in /sys/class/scsi_disk/*; do echo '1' > $hdd/device/rescan; done

Go ahead and resize the physical volume:

[root@CentOS7Fantasy ~]# pvresize /dev/sdb
  Physical volume "/dev/sdb" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

Confirm changes:

[root@CentOS7Fantasy ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_centos7fantasy
  ...
  Cur PV                2
  Act PV                2
  VG Size               35.50 GiB
  PE Size               4.00 MiB
  Total PE              9089
  Alloc PE / Size       3970 / 15.51 GiB
  Free  PE / Size       5119 / 20.00 GiB
  VG UUID               4yN1qy-jOS8-11sz-I0ge-7xt7-5Msk-ioS528

Task: Extending a Logical Volume within a Volume Group (VG) after increasing VG space

Once a VG has grown, that storage is not yet available to the filesystems that depend on it.

Confirm this:

[root@CentOS7Fantasy ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos_centos7fantasy/swap
  LV Name                swap
  VG Name                centos_centos7fantasy
  LV UUID                zMUd5r-8nsw-05v1-Yh3H-r3C1-hbxS-fxa4E0
  LV Write Access        read/write
  LV Creation host, time localhost, 2014-11-24 13:05:22 -0600
  LV Status              available
  # open                 2
  LV Size                1.60 GiB
  Current LE             410
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos_centos7fantasy/root
  LV Name                root
  VG Name                centos_centos7fantasy
  LV UUID                1SEOKd-i5cP-9Sht-TazJ-uXCo-P5gb-QvDodO
  LV Write Access        read/write
  LV Creation host, time localhost, 2014-11-24 13:05:22 -0600
  LV Status              available
  # open                 1
  LV Size                13.91 GiB
  Current LE             3560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

Task: Enlarge /dev/centos_centos7fantasy/root Logical Volume (LV)

At the moment, /dev/centos_centos7fantasy/root is 13.91GB. Lets extend it to all available space.

[root@CentOS7Fantasy ~]# lvextend /dev/centos_centos7fantasy/root  -l '+100%FREE'
  Extending logical volume root to 20.00 GiB
  Logical volume root successfully resized

You may also enlarge by a given size

[root@CentOS7Fantasy ~]# lvextend /dev/centos_centos7fantasy/root  -L '+10G'
  Extending logical volume root to 20.00 GiB
  Logical volume root successfully resized

Task: Enlarge partition on (recently) enlarged LV

When using XFS

The final step to increasing a partition's size is to grow that partition:

[root@CentOS7Fantasy ~]# xfs_growfs /dev/mapper/centos_centos7fantasy-root 
meta-data=/dev/mapper/centos_centos7fantasy-root isize=256    agcount=4, agsize=911360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=3645440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 3645440 to 5241856

Confirm filesystem changes:

[root@CentOS7Fantasy ~]# df -h /
Filesystem                              Size  Used Avail Use% Mounted on
/dev/mapper/centos_centos7fantasy-root   20G  2.0G   19G  10% /

When using ext[2-4]

The following is the output when resizing /var/ by 450GB.

root@webapps2: ~ 
# time resize2fs /dev/mapper/vg_wa_storage-lv_var 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_wa_storage-lv_var is mounted on /var; on-line resizing required
old desc_blocks = 50, new_desc_blocks = 85
Performing an on-line resize of /dev/mapper/vg_wa_storage-lv_var to 353891328 (4k) blocks.
The filesystem on /dev/mapper/vg_wa_storage-lv_var is now 353891328 blocks long.


real    3m29.244s
user    0m0.072s
sys     0m2.456s


CategoryDocumentation

LinuxLVM (last edited 2017-03-31 10:05:22 by meyersh)