Search This Blog

Wednesday, December 16, 2015

RHEL 7 - Extending a Logical Volume

Outcomes:
A Resized logical volume, 700Mib, called storage in the volume group shazam, mounted at /storage. Resizing done while the file system is still mounted and is use. The volume group extended to include an additional physical volume of 512MiB, giving a total VG size of 1GiB.

1. Check for space in Volume Group
                  Use vgdisplay to check if the VG has sufficient free space to extend the LV to a total size of 700MiB.


[root@server1 /]# vgdisplay shazam
  --- Volume group ---
  VG Name               shazam
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               504.00 MiB
  PE Size               4.00 MiB
  Total PE              126
  Alloc PE / Size       100 / 400.00 MiB
  Free  PE / Size       26 / 104.00 MiB
  VG UUID               wWqgm1-BjlR-yByw-3XVN-11RD-25ay-Hfzj3Y

There is only 104MiB available (25 PEs X 4MiB extents) and we need at least 300Mib to have 700Mib in total. We need to extend the VG.

For later comparison, use df to check current disk space:

[root@server1 /]# df -h /storage
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/shazam-storage  397M   21M  377M   6% /storage

2. Create the Physical Resources
                  2. 1 Use fdisk to create an additional partitions of 512Mib and set to to type LVM.

[root@server1 /]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

                  2.2 Add a new Primary partition of 512Mib.

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (1050624-10485759, default 1050624):
Using default value 1050624
Last sector, +sectors or +size{K,M,G} (1050624-10485759, default 10485759): +512M
Partition 3 of type Linux and of size 512 MiB is set

                  2.3 Change the partition type to Linux Lvm - 0X8e

Command (m for help): t
Partition number (1-3, default 3):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

                  2.4 Write the changes to the partition table and quit

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

                  2.5 Use partprobe to register the new partions with the kernel.

[root@server1 /]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@server1 /]# cat /proc/partitions
major minor  #blocks  name  11        0    3655680 sr0
   8        0   20971520 sda
   8        1    1048576 sda1
   8        2   10485760 sda2
   8       16    5242880 sdb
   8       17     262144 sdb1
   8       18     262144 sdb2
   8       19     524288 sdb3
 253        0     409600 dm-0

3. Extend the Volume Group
                  3.1 Use vgextend to extend the VG named shazam, using the new /dev/sdb3 PV.

[root@server1 /]# vgextend shazam /dev/sdb3
  Physical volume "/dev/sdb3" successfully created
  Volume group "shazam" successfully extended

                  3.2 Use vgdisplay to check the shazam VG free space again. There should be plenty of free space now.

[root@server1 /]# vgdisplay shazam
  --- Volume group ---
  VG Name               shazam
  System ID            
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               1012.00 MiB
  PE Size               4.00 MiB
  Total PE              253
  Alloc PE / Size       100 / 400.00 MiB
  Free  PE / Size       153 / 612.00 MiB
  VG UUID               wWqgm1-BjlR-yByw-3XVN-11RD-25ay-Hfzj3Y

There is now 612MiB Available (153 PEs X 4MiB extents); perfect

4.Extend the logical Volume
Use lvextend to extend the exisitng LV to 700Mib

[root@server1 /]# lvextend -L 700M /dev/shazam//storage
  Extending logical volume storage to 700.00 MiB
  Logical volume storage successfully resized

Note: If our example, we specified the exact size to make the final LV, but we could also have used:
·        -L              +300M to add the new space using size in MiB.
·        -l               175 to specifiy the total number of extents (175PEs X 4MiB)
·        -l               +75 to add the additional extents needed

Some Example:
·        lvextend -l 128                                   Resize the logical volume to exactly 128 extents in size
·        lvextend -l +128                                 Add 128 extents to the current size of the logical volume.
·        lvextend -L 128M                               Resize the logical volume to exactly 128Mib
·        lvextend -L +128M                            Add 128MiB to the current size of the logical volume.
·        lvextend -l +50%FREE                      Add 50 percent of the current free space in the VG to the LV

5. Resize the File System
Use xfs_growfs to extend the XFS file system to the remainder of the free space on the LV.

[root@server1 /]# xfs_growfs /storage
meta-data=/dev/mapper/shazam-storage isize=256    agcount=4, agsize=25600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=102400, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 102400 to 179200

Note: To grow the logical volume size, use lvresize, followed by the -r option to resize the file system used on it.
Example:
·        lvresize -r -l 75%VG /dev/shazam/storage           This resizes the logical volume so that it will take 75% of the total disk spae in the volume group.
·        lvresize -r -l +75%VG /dev/shazam/storage         This tries to add 75% of the total size of the volume group to the logical volume. (Notice the difference with the previous command)
·        lvresize -r -l +75%FREE /dev/shazam/storage     This add 75% of all free disk space to the logical volume.
·        lvresize -r -l 75%FREE /dev/shazam/storage        This resizes the logical volume ta a total size that equals 75% of the amount of free disk space. (Notice the difference with the previous command)

6. Verify Content Availability and New File System Size
Use df and ls|wc  to review the new file system size and verify the existing files are still prestent.

[root@server1 /]# df -h /storage
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/shazam-storage  697M   21M  677M   3% /storage
[root@server1 /]# ls /storage|wc -l
49

The files are still there and the file system is about the size we expect.


Extend a logical volume and ext4 file system

Adding space to a logical Volume:


# pvcreate /dev/sdb3

[[root@localhost ~]# pvcreate /dev/sdb3
  Physical volume "/dev/sdb3" successfully created

[root@localhost ~]# pvs
  PV         VG    Fmt  Attr PSize   PFree 
  /dev/sdb1  volg1 lvm2 a-   484.00M      0
  /dev/sdb2  volg1 lvm2 a-   484.00M 468.00M
  /dev/sdb3        lvm2 --   486.34M 486.34M

# vgextend volg1 /dev/sdb3
vgs to confirm available space

[root@localhost ~]# vgextend /dev/volg1 /dev/sdb3
  Volume group "volg1" successfully extended

[root@localhost ~]# vgs
  VG    #PV #LV #SN Attr   VSize VFree 
  volg1   3   1   0 wz--n- 1.42G 952.00M

#lvextend -L +200M /dev/volg1/logvol1
resize2fs /dev/volg1/logvol1

[root@localhost ~]# lvextend -L 900 /dev/volg1/logvol1
  Extending logical volume logvol1 to 900.00 MB
  Logical volume logvol1 successfully resized

[root@localhost ~]# resize2fs /dev/volg1/logvol1
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/volg1/logvol1 is mounted on /mnt; on-line resizing required
Performing an on-line resize of /dev/volg1/logvol1 to 921600 (1k) blocks.
The filesystem on /dev/volg1/logvol1 is now 921600 blocks long.

Note: The primary difference between xfs_growfs and resize2fs is the argument passed to identify the file system. xfs_growfs takes the mount point and resize2fs take the logical volume.

No comments:

Post a Comment