How to resize a logical volume LVM

Ahed Bahri
4 min readDec 30, 2022
Logical Volume Manager

If you need to increase the storage capacity of your partitions in Linux, one option is to use Logical Volume Manager (LVM). LVM allows you to create and manage logical volumes on your system, which can be used to increase the size of your partitions and improve the overall storage management of your system. In this article, we will walk through steps to extend storage in Linux using LVM.

The process is easy as attaching new storage to the system and creating a new PV (Physical Volume) from that exact storage. Adding that PV to a group volume (VG) and finally extending that logical volume and mounting it.

  1. Attaching a new Storage to the system.
Adding a new disk to a virtual machine (Vmware Workstation)

2. By listing information about all available block devices. we can notice the disk added with 10G size named sdb.

lsblk — list block devices

3. Let’s create a physical volume on the block device that you want to add to the volume group.

pvcreate: Physical Volume creation

We can list the physical volumes we have by running this command:

PVS: Physical Volume Show

4. Use the vgcreate command to create a volume group using the physical volume that you just created:

vgcreate: Volume Groupe creation

5. Use the lvcreate command to create a logical volume in the volume group. You can specify the size of the logical volume and the name that you want to give it.

lvcreate: Logical Volume Creation

6. If you want to create a filesystem on the logical volume and mount it, you can use the mkfs command to create a filesystem and the mount command to mount it:

It is important to note that mkfs.ext4 will erase all data on the specified disk or partition, so you should be careful when using it on a used disk and make sure you have a backup of any important data.

Mounting

there is another way to resize your disk:

  1. Check the free space you have, that you want to extend.
lvextend

2. Let's make sure that our file system is in a good health.

e2fsck

e2fsck is a command-line utility that is used to check and repair an ext2, ext3, or ext4 file system. The -f option stands for "force," and it tells e2fsck to repair any problems it finds automatically, without prompting the user for confirmation.

3. Resizing the filesystem:

resizing

4. Finally it is about mounting the logical volume (LV) onto the mount point /mnt. A mount point is a directory on the file system where a file system or device can be attached

Munting

To unmount the LV, you can use the umount command and specify the mount point. For example:

umount /mnt

This would unmount the LV from the /mnt mount point, and you would no longer be able to access the data stored on the LV through that path.

--

--

Ahed Bahri

Computer Engineering Student, i’ve got a big passion in Computer Technology, programming and in solving problems. Https://www.behance.net/BahriAhed 💖