How to Increase the Size of Logical Volume (LVM) on Linux

Share this Article :

There are eight(8) functional steps to resize the logical volume in linux.

1. Increase A VMware Disk Size (VMDK) Formatted As Linux LVM
2. In VM OS, Create Partition
3. Reboot the VM
4. Format the new partition
5. Creates the physical volumes using pvcreate
6. Add physical volumes to a volume group using vgextend. vgextend allows you to add one or more initialized physical volumes to an existing volume group to extend it in size.
7. Extend the size of a logical volume using lvextend
8. Resize the logical volume size using resize2fs. The resize2fs program will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located on device.

    [[email protected] ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           20G  173M   19G   1% /opt
    
    [[email protected] ~]# fdisk -lu
    
    Disk /dev/sda: 21.4 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *          63      208844      104391   83  Linux
    /dev/sda2          208845     2313359     1052257+  82  Linux swap / Solaris
    /dev/sda3         2313360    14667344     6176992+  8e  Linux LVM
    /dev/sda4        14667345    41929649    13631152+  8e  Linux LVM
    
    Disk /dev/sdb: 26.8 GB, 26843545600 bytes
    255 heads, 63 sectors/track, 3263 cylinders, total 52428800 sectors
    Units = sectors of 1 * 512 = 512 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1              63    41929649    20964793+  8e  Linux LVM
    
    [[email protected] ~]# fdisk /dev/sdb
    
    The number of cylinders for this disk is set to 3263.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
       (e.g., DOS FDISK, OS/2 FDISK)
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First cylinder (2611-3263, default 2611):
    Using default value 2611
    Last cylinder or +size or +sizeM or +sizeK (2611-3263, default 3263):
    Using default value 3263
    
    Command (m for help): t
    Partition number (1-4): 2
    Hex code (type L to list codes): 8e
    Changed system type of partition 2 to 8e (Linux LVM)
    
    Command (m for help): p
    
    Disk /dev/sdb: 26.8 GB, 26843545600 bytes
    255 heads, 63 sectors/track, 3263 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1        2610    20964793+  8e  Linux LVM
    /dev/sdb2            2611        3263     5245222+  8e  Linux LVM
    
    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.
    Syncing disks.
    [[email protected] ~]# reboot
    
    [[email protected] ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           20G  173M   19G   1% /opt
    

After the new partition table has been written, format the new partition.

    [[email protected] ~]# mke2fs -j /dev/sdb2
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    656000 inodes, 1311305 blocks
    65565 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=1346371584
    41 block groups
    32768 blocks per group, 32768 fragments per group
    16000 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736
    
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 20 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    

Creates the physical volumes using command below:

    [[email protected] ~]# pvcreate /dev/sdb2
      Physical volume "/dev/sdb2" successfully created
    

Scan all disks for physical volumes.

    [[email protected] ~]# pvscan
      PV /dev/sdb1   VG VolGroup01      lvm2 [19.99 GB / 0    free]
      PV /dev/sda4   VG VolGroup00      lvm2 [13.00 GB / 0    free]
      PV /dev/sdb2                      lvm2 [5.00 GB]
      Total: 3 [37.99 GB] / in use: 2 [32.99 GB] / in no VG: 1 [5.00 GB]
    

Add physical volumes to a volume group. This example add /dev/sdb2 to VolGroup01

    [[email protected] ~]# vgextend VolGroup01 /dev/sdb2
      Volume group "VolGroup01" successfully extended
    
    [[email protected] ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           20G  173M   19G   1% /opt
    

Extend the size of a logical volume using lvextend.

    [[email protected] ~]# lvextend -l +100%FREE /dev/VolGroup01/optvol
      Extending logical volume optvol to 24.99 GB
      Logical volume optvol successfully resized
    

Resize the logical volume size using resize2fs.

    [[email protected] ~]# resize2fs /dev/mapper/VolGroup01-optvol
    resize2fs 1.39 (29-May-2006)
    Filesystem at /dev/mapper/VolGroup01-optvol is mounted on /opt; on-line resizing required
    Performing an on-line resize of /dev/mapper/VolGroup01-optvol to 6551552 (4k) blocks.
    The filesystem on /dev/mapper/VolGroup01-optvol is now 6551552 blocks long.
    
    [[email protected] ~]# df -lh
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3             5.8G  4.3G  1.2G  79% /
    /dev/sda1              99M   12M   83M  13% /boot
    tmpfs                 506M     0  506M   0% /dev/shm
    /dev/mapper/VolGroup00-datavol
                           13G  855M   12G   7% /data
    /dev/mapper/VolGroup01-optvol
                           25G  173M   24G   1% /opt
    


One Response

  1. Amit

Leave a Reply