How to resize a logical volume LVM
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.
- Attaching a new Storage to the system.
2. By listing information about all available block devices. we can notice the disk added with 10G size named sdb.
3. Let’s create a physical volume on the block device that you want to add to the volume group.
We can list the physical volumes we have by running this command:
4. Use the vgcreate
command to create a volume group using the physical volume that you just created:
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.
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.
there is another way to resize your disk:
- Check the free space you have, that you want to extend.
2. Let's make sure that our file system is in a good health.
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:
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
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.