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

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.

    [root@server ~]# 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
    
    [root@server ~]# 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
    
    [root@server ~]# 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.
    [root@server ~]# reboot
    
    [root@server ~]# 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.

    [root@server ~]# 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:

    [root@server ~]# pvcreate /dev/sdb2
      Physical volume "/dev/sdb2" successfully created
    

Scan all disks for physical volumes.

    [root@server ~]# 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

    [root@server ~]# vgextend VolGroup01 /dev/sdb2
      Volume group "VolGroup01" successfully extended
    
    [root@server ~]# 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.

    [root@server ~]# 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.

    [root@server ~]# 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.
    
    [root@server ~]# 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
    

How to Reset the Directory Manager Password on RHEL 7 / CentOS 7
How to Reset the Directory Manager Password on RHEL 7 / CentOS 7

It is best practice to remember passwords, but because too many passwords, sometimes we forget. We are not encouraged to write the password on any paper or share the password...

How to Find Big Files Size on Linux RHEL/CentOS
How to Find Big Files Size on Linux RHEL/CentOS

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space. Low disk space can also...

Why Linux users should worry about malware and what they can do about it
Why Linux users should worry about malware and what they can do about it

Don’t drop your guard just because you’re running Linux. Preventing the spread of malware and/or dealing with the consequences of infection are a fact of life when using computers. If...

How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7
How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7

This short howto will explain the steps to reset a lost root password or to reset a forgotten root password on Linux RHEL 7 or CentOS 7. Basically, we will...

How to Update CentOS or Upgrade CentOS to the Latest Version
How to Update CentOS or Upgrade CentOS to the Latest Version

Recently, the latest version of CentOS 7.3 was released. All users of CentOS 7.0, 7.1 and 7.2 can upgrade their system to the most recent. This quick guide will explain...

How to Change your WordPress Username, Nickname and Display Name in MySQL
How to Change your WordPress Username, Nickname and Display Name in MySQL

After you create an account log in WordPress, you may want to change your WordPress username, as appropriate or due to security reason. However, you can not do this from...

How to Enable SSH Root Login on Ubuntu 16.04
How to Enable SSH Root Login on Ubuntu 16.04

As what we wrote in the previous article on how to allow SSH root on Ubuntu 14.04, after installing a fresh new copy of Ubuntu 16.04 LTS, we find that...

How to Change UUID of Linux Partition on CentOS 7
How to Change UUID of Linux Partition on CentOS 7

UUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system. If you cloned a virtual machine from vCenter, the metadata containing...

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *