What is LVM? Understand it with the example

0

Logical Volume Manager (LVM) is a system used to manage disk storage in a Linux operating system. It provides a way to divide a physical disk into one or more logical volumes, which can be resized or moved without affecting the underlying data. LVM also makes it easy to add or remove disks from a system, or to combine multiple disks into a single logical volume.

Here are some basic commands used with LVM:

pvcreate: Initializes a disk or partition as a physical volume, which can be used as part of an LVM setup.

vgcreate: Creates a new volume group, which is a collection of physical volumes that can be used to create logical volumes.

lvcreate: Creates a new logical volume within a volume group.

lvdisplay: Shows information about logical volumes, including their size, filesystem type, and mount point.

lvextend: Increases the size of a logical volume.

lvreduce: Decreases the size of a logical volume.

vgchange: Makes changes to the volume group, such as activating or deactivating it.

pvdisplay: Shows information about physical volumes, including their size and free space.

To use LVM, you will need to create physical volumes, volume groups, and logical volumes. Physical volumes are created using the pvcreate command, and volume groups are created using the vgcreate command. Once you have created a volume group, you can create logical volumes within it using the lvcreate command. You can then format the logical volumes with a filesystem, such as ext4, and mount them to use them as regular storage devices.

Here is an example of how you might use LVM to create a logical volume on a single physical disk:

  1. Initialize the disk as a physical volume using pvcreate /dev/sda.
  2. Create a volume group called "vg0" using vgcreate vg0 /dev/sda.
  3. Create a logical volume called "lv0" within the volume group using lvcreate -n lv0 -L 8G vg0. This creates a logical volume with a size of 8GB.
  4. Format the logical volume with a filesystem using mkfs.ext4 /dev/vg0/lv0.
  5. Mount the logical volume using mount /dev/vg0/lv0 /mnt.

You can then use the /mnt directory as a regular storage location. When you want to unmount the logical volume, use the umount command.

Post a Comment

0Comments
Post a Comment (0)