Adding Another Logical Volume

Adding another LV is a straightforward process.

  1. Add the new hard drive.
  2. Configure the new hard drive with partitions using a command tool such as fdisk. It’s code is 8e within fdisk.
  3. If you’ve created separate partitions, you can dedicate the space of a specific partition to a PV. If you don’t already have an empty logical volume, you’ll need to create more than one. For example, for the first partition /dev/sda1, you can do this with the following command:
    # pvcreate /dev/sda1
  4. Next, you’ll want to create a Volume Group (VG) from two or more empty, properly configured partitions (or drives). One way to do this, assuming you have an empty /dev/sda3 partition, is with the following command:
    # vgcreate Volume01 /dev/sda1
  5. Before proceeding, you should inspect the VG with the vgdisplay command.
  6. You should now be able to add another LV with the lvcreate command.
    # lvcreate -l 20 Volume01 -n LogVol01
  7. You’ve added a new logical volume. Naturally, you’ll need to format and mount a directory on this LV before you can use it. For the example shown, you would use the following commands:
    # mkfs -j /dev/Volume01/LogVol01
    # mount -t ext3 /dev/Volume01/LogVol01 /tmp

Removing Logical Volumes

Removing an existing LV requires a straightforward command. The basic command is lvremove. If you’ve created an LV in the previous section and want to remove it, the basic steps are simple:

  1. Save any data in directories that are mounted on the LV.
  2. Unmount any directories associated with the LV. Based on the example in the previous section, you would use the following command:
    # umount /dev/Volume01/LogVol01
  3. Apply the lvremove command to the LV with a command such as:
    # lvremove /dev/Volume01/LogVol01

Resizing Logical Volumes

If you have an existing LV, you can add a newly created PV to extend the space available on your system. All it takes is appropriate use of the vgextend and lvextend commands. For example, if you want to add PEs to the VG associated with the aforementioned /home directory, you could take the following basic steps:

Just be careful while re-sizing home directories as the computer may crash do take sufficient precaution while handling re-sizing requests as they are prone to system crashes.

  1. Back up any data existing on the /home directory.
  2. Unmount the /home directory from the current logical volume.
  3. Extend the VG to include the new hard drive or partitions that you’ve created. For example, if you wanted to add /dev/sdd1 to the /home VG, you would run the following command:
    # vgextend Volume00 /dev/sda1
  4. Make sure the new partitions are included in the VG with the following vgdisplay command:
    # vgdisplay Volume00
  5. Extend the current LV to include the space you need. For example, if you wanted to extend the LV to 2000MB, you’d run the following command:
    # lvextend -L2000M /dev/Volume00/LogVol00

    The lvextend command can help you configure LVs in KB, MB, GB, or even TB. For example, you could get the same result with the following command:

    # lvextend -L2G /dev/Volume00/LogVol00
  6. Reformat and remount the LV, using commands described earlier:

    use resize2fs when prompted

    # mkfs -j /dev/Volume00/LogVol00
    # mount -t ext3 /dev/Volume00/LogVol00 /home