Logical Volume In Linux

LVM is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes.

With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes. LVM physical volumes can be placed on other block devices which might span two or more disks.

The physical volumes are combined into logical volumes, with the exception of the /boot partition. The /boot partition cannot be on a logical volume group because the boot loader cannot read it. If the root (/) partition is on a logical volume, create a separate /boot partition which is not a part of a volume group.

Since a physical volume cannot span over multiple drives, to span over more than one drive, create one or more physical volumes per drive.

How to create LVM

First insert Disk to your physical device. If you are working in virtual vm then you can attach virtual hard disk.

I am here working on AWS to create LVM storage

create Volume in aws

click on create volume

Select volume type and size of volume

Make sure that you have created your volume in same availablity zone of your instance

Click on attach instance.

you can change device name and select instance

type lsblk command

The lsblk command is a Linux command-line utility used to list information about block devices, including hard drives, solid-state drives, and other storage devices, as well as partitions and logical volumes. It provides a structured view of the block devices and their relationships within the system.

lsblk

fdisk -l /dev/xvdf

Running the fdisk command with the /dev/xvdf device file is typically used for managing and creating disk partitions on a block device in Linux. Here's how you can use fdisk to manage the /dev/xvdf device:

Create physical volumes

The pvcreate command in Linux is used to initialize a physical volume (PV) on a block device, making it ready for use in the Logical Volume Manager (LVM). In your command, you are attempting to create a physical volume on /dev/xvdf1. Here's the correct usage of the pvcreate command:

pvcreate /dev/xvdf1

After running this command, /dev/xvdf1 will be initialized as a physical volume and can be added to a volume group (VG) to create logical volumes or used for other LVM operations.

pvdisplay

Create a volume group

The vgcreate command in Linux is used to create a new volume group (VG) with one or more physical volumes (PVs). In your command, you are attempting to create a volume group named vgone and adding the physical volume /dev/xvdf1 to it. Here's the correct usage of the vgcreate command:

After running this command, a new volume group named vgone will be created, and it will contain the physical volume /dev/xvdf1. You can then create logical volumes (LVs) within this volume group using the lvcreate command, or perform other LVM operations as needed.

The vgdisplay command in Linux is used to display detailed information about a volume group (VG). In your command, you are trying to display information about the volume group named vgone. Here's the correct usage of the vgdisplay command:

Create a logical volume

When you run this command, it will provide detailed information about the vgone volume group, including its size, physical volumes (PVs) included in the group, and any logical volumes (LVs) created within it. This information can be useful for managing and monitoring your volume groups in Logical Volume Manager (LVM).

The lvcreate command in Linux is used to create a logical volume (LV) within a volume group (VG) in the Logical Volume Manager (LVM). In your command, you are creating a logical volume named lgvolume1 with a size of 5000 megabytes within the vgone volume group. Here's the correct usage of the lvcreate command:

After running this command, a logical volume named lgvolume1 will be created within the vgone volume group, with a size of 5000 megabytes (or the size you specified). You can then format and mount this logical volume to start using it for data storage.

Create a filesystem

The mkfs.ext4 command is used to create an ext4 file system on a specified block device or partition. In your command, you are trying to create an ext4 file system on the logical volume /dev/vgone/lgvolume1.

Create a mount point and mount the logical volume

mount logical with directories

Extend the logical volume

The lvextend command in Linux is used to extend the size of an existing logical volume. In your command, you are attempting to increase the size of the logical volume /dev/vgone/lgvolume1 by 1 gigabyte.

lvextend -L+1G /dev/vgone/lgvolume1

if we check storage in file system is not affected yet.

The resize2fs command is used to resize an ext2, ext3, or ext4 file system on a block device. In your command, you are resizing the file system on the logical volume /dev/vgone/lgvolume1 to a new size of 5048 megabytes (M).

Resize the filesystem

resize2fs /dev/vgone/lgvolume1 5048M

If we check file system again we can see storage is increasesd.