BCE-C712 Linux System Administration

0 of 74 lessons complete (0%)

Managing Unix File Systems

Logical Volumes

You don’t have access to this lesson

Please register or sign in to access the course content.

Logical Volumes, often abbreviated as LVs, are a fundamental concept in storage management on Linux systems. They are a part of the Logical Volume Management (LVM) system, which provides a flexible and dynamic way to manage storage.

Here are the key points you should know about Logical Volumes:

  1. Overview of Logical Volume Management (LVM):
    • LVM is a storage management system that allows for the dynamic allocation, resizing, and migration of storage volumes. It provides a layer of abstraction between the physical storage devices (such as hard drives or SSDs) and the file systems that use them.
  2. Physical Volumes (PVs):
    • Physical Volumes are the actual storage devices (e.g., hard drives, SSDs, partitions) that contribute storage space to the LVM. These physical volumes are divided into units called Physical Extents (PEs).
  3. Volume Group (VG):
    • A Volume Group is a collection of one or more physical volumes. It acts as a pool of storage that can be dynamically allocated to Logical Volumes. The Volume Group is the highest-level abstraction in LVM.
  4. Logical Volume (LV):
    • A Logical Volume is a virtual partition created within a Volume Group. It behaves like a physical partition, but it can be resized and moved dynamically, allowing for great flexibility in managing storage space.
  5. Creating Logical Volumes:
    • To create a Logical Volume, you need to allocate a portion of the Volume Group’s available space to it. You specify the size and optionally a filesystem type when creating the LV.
  6. Mounting and Using Logical Volumes:
    • Once a Logical Volume is created, it can be formatted with a filesystem and mounted to a directory in the Linux filesystem hierarchy. From the perspective of the operating system and applications, it behaves like any other partition.
  7. Resizing Logical Volumes:
    • One of the key benefits of LVM is the ability to resize Logical Volumes on the fly. This means you can increase or decrease the size of a LV without unmounting it or affecting the data stored on it.
  8. Snapshot Volumes:
    • LVM allows the creation of “snapshot” volumes, which are essentially point-in-time copies of a Logical Volume. These snapshots can be used for backup or to create a consistent state for application testing.
  9. Striping and Mirroring:
    • LVM supports features like striping (spreading data across multiple physical devices for improved performance) and mirroring (maintaining redundant copies of data for increased reliability).
  10. Managing Logical Volumes:
    • LVM provides a set of commands (lvcreate, lvresize, lvremove, etc.) to create, modify, and delete Logical Volumes. These commands are used in conjunction with options that specify details like size, filesystem type, and more.
  11. Monitoring and Troubleshooting:
    • LVM provides tools like lvdisplay, vgdisplay, and pvdisplay to inspect the status and properties of logical volumes, volume groups, and physical volumes, respectively. These tools are helpful for monitoring and troubleshooting LVM configurations.

Remember, while LVM provides powerful capabilities for managing storage, it’s important to exercise caution, especially when resizing or removing Logical Volumes, to avoid unintended data loss. Always ensure that you have a backup of critical data before making significant changes to your storage configuration.

How to create Logical Volume

Creating a logical volume involves several steps, including setting up physical volumes, creating a volume group, and finally creating the logical volume itself. Here is a step-by-step guide to creating a logical volume using the lvm2 tools on a Linux system:

  1. Initialize Physical Volumes (PVs):
    • First, you need to identify the storage devices (such as partitions or whole disks) that you want to use as physical volumes. You can initialize them using the pvcreate command. For example, if you have a partition /dev/sdb1 that you want to use:bashCopy codesudo pvcreate /dev/sdb1
  2. Create a Volume Group (VG):
    • Next, you’ll create a volume group and add the initialized physical volumes to it. This can be done using the vgcreate command. For instance, if you want to create a volume group named my_vg with the physical volume /dev/sdb1:bashCopy codesudo vgcreate my_vg /dev/sdb1
  3. Create a Logical Volume (LV):
    • Once you have a volume group, you can create a logical volume within it using the lvcreate command. You’ll specify the size and name of the logical volume. For example, to create a logical volume named my_lv with a size of 10GB:Copy codesudo lvcreate -L 10G -n my_lv my_vg
    • In this example, -L specifies the size, and -n assigns a name to the logical volume. my_vg is the name of the volume group.
  4. Format the Logical Volume:
    • After creating the logical volume, you need to format it with a filesystem. For example, if you want to use the ext4 filesystem:bashCopy codesudo mkfs.ext4 /dev/my_vg/my_lv
  5. Create a Mount Point:
    • Choose or create a directory in your filesystem where you want to mount the logical volume. For example, if you want to create a mount point named /mnt/my_mount:bashCopy codesudo mkdir /mnt/my_mount
  6. Mount the Logical Volume:
    • Finally, you can mount the logical volume using the mount command. For example:bashCopy codesudo mount /dev/my_vg/my_lv /mnt/my_mount
    • Now, the logical volume is accessible at /mnt/my_mount and you can use it like any other directory.
  7. Automount at Boot (Optional):
    • If you want the logical volume to be mounted automatically at system boot, you can add an entry to the /etc/fstab file. Edit the file and add a line like this:bashCopy code/dev/my_vg/my_lv /mnt/my_mount ext4 defaults 0 0
    • This entry specifies the device, mount point, filesystem type, mount options, and other parameters. It will ensure that the logical volume is mounted at boot.

Remember, this process assumes that you have already installed the lvm2 package, which contains the necessary tools for working with logical volumes. Additionally, always ensure that you have backups of important data before making any significant changes to your storage configuration.