Skip to content

Instantly share code, notes, and snippets.

@rakibulinux
Created February 23, 2021 00:59
Show Gist options
  • Save rakibulinux/5a07defbfbd0e7c49ed6434ab45adb7e to your computer and use it in GitHub Desktop.
Save rakibulinux/5a07defbfbd0e7c49ed6434ab45adb7e to your computer and use it in GitHub Desktop.
How to Increase the Size of the Logical Volume on Linux Server

Step 1: Access your Server via SSH

Step 2: Check your current Disk Space

# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/md2                28G  565M   27G   3% /
devtmpfs                16G     0   16G   0% /dev
tmpfs                   16G     0   16G   0% /dev/shm
tmpfs                   16G  1.6G   15G  10% /run
tmpfs                   16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/vg00-usr   9.8G  1.9G  7.5G  20% /usr
none                    16G  4.0K   16G   1% /tmp
/dev/mapper/vg00-var   9.8G  662M  8.7G   7% /var
/dev/mapper/vg00-home  9.8G   37M  9.3G   1% /home
tmpfs                  3.2G     0  3.2G   0% /run/user/0

Step 3: Check the Free Disk Space:

# pvs
  PV         VG   Fmt  Attr PSize    PFree
  /dev/md4   vg00 lvm2 a--  <409.88g <379.88g

Here, we have 379.88 GB free space. Basically the Logical Volume assigned either to /vg00-var , /vg00-usr , or /vg00-home.

Step 4: We will increase /vg00-var by 10GB using the lvextend command. Same steps if you would like to increase either /vg00-usr or /vg00-home.

# lvextend -L +10G /dev/mapper/vg00-var
  Size of logical volume vg00/var changed from 10.00 GiB (2560 extents) to 20.00 GiB (5120 extents).
  Logical volume vg00/var successfully resized.

Input Explanation lvextend The logical volume extend command used to increase logical volumes -L +10G Command option to increase a Logical volume by 10 Gigabytes /dev/mapper/vg00-var The path for the logical volume to increase

Step 5: We will use Command mount, to display the mounted file system, and we use grep, to specify the return value only for /vg00-var

# mount | grep /vg00-var
/dev/mapper/vg00-var on /var type ext4 (rw,noatime,quota,usrquota,data=ordered)

Note: CentOS7 uses XFS file system by default, and CentOS6 uses Ext4 file system. However, on Dedicated Server with CentOS7 Image, the default file system is Ext4. Unlikely with Cloud Server, where default file system is XFS. Therefore, it’s very important to check the mounted File System before increasing the Logical Volume.

Step 6: To increase the file system to match that of the logical volume, we will use the xfs_growfs command if the filesystem uses xfs or resize2fs if the filesystem is ext4.

# resize2fs /dev/mapper/vg00-var
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg00-var is mounted on /var; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/mapper/vg00-var is now 5242880 blocks long.

Command for XFS file System:

# xfs_growfs /dev/mapper/vg00-var

Please Not: Some older operating systems will need to use the resize4fs command if the resize2fs command does not work.

Step 7: use df -h Command again to verify the free space has been added to /vg00-var

# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/md2                28G  565M   27G   3% /
devtmpfs                16G     0   16G   0% /dev
tmpfs                   16G     0   16G   0% /dev/shm
tmpfs                   16G  1.6G   15G  10% /run
tmpfs                   16G     0   16G   0% /sys/fs/cgroup
/dev/mapper/vg00-usr   9.8G  1.9G  7.5G  20% /usr
none                    16G  4.0K   16G   1% /tmp
/dev/mapper/vg00-var    20G  670M   19G   4% /var
/dev/mapper/vg00-home  9.8G   37M  9.3G   1% /home
tmpfs                  3.2G     0  3.2G   0% /run/user/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment