Logical volumes are an important aspect of storage management in Ubuntu. They allow you to create virtual partitions that can span multiple physical disks, providing greater flexibility and scalability than traditional partitioning. In this article, we’ll explore the basics of logical volumes in Ubuntu, including creating and managing logical volumes.
What are Logical Volumes?
A logical volume is a virtual partition that can span multiple physical disks. Logical volumes are created using the Logical Volume Manager (LVM) tool, which is included in Ubuntu by default. LVM provides a flexible way to manage storage by allowing you to create, resize, and move logical volumes without requiring you to repartition your disks.
Creating Logical Volumes
To create a logical volume, you’ll need to first create a physical volume by formatting a disk or partition as an LVM physical volume. Once you’ve created your physical volumes, you can use the LVM tool to create your logical volumes.
To create a logical volume, follow these steps:
Open the LVM tool by running the command “sudo lvcreate” in a terminal window.
Specify the name of the logical volume, the size of the volume, and the physical volume(s) to use for the volume.
Once you’ve created your logical volume, you can format it with a filesystem using the “sudo mkfs” command.
Managing Logical Volumes
Once you’ve created your logical volumes, you can manage them using the LVM tool. The LVM tool provides a range of commands for managing logical volumes, including resizing, moving, and renaming volumes.
To resize a logical volume, follow these steps:
Use the “sudo lvresize” command to resize the logical volume.
Use the “sudo resize2fs” command to resize the filesystem on the logical volume.
To move a logical volume to a different physical volume, follow these steps:
Use the “sudo pvmove” command to move the data from the old physical volume to the new physical volume.
Use the “sudo vgreduce” command to remove the old physical volume from the volume group.
Some commands for managing logical volumes
Creating Physical Volumes
Before creating logical volumes, you’ll need to create physical volumes by formatting your disks or partitions as LVM physical volumes. You can use the “pvcreate” command to create a physical volume. For example, to create a physical volume on /dev/sdb1, you can use the following command:
sudo pvcreate /dev/sdb1
Creating Volume Groups
After creating physical volumes, you can group them together into volume groups using the “vgcreate” command. For example, to create a volume group named “myvg” using the physical volume /dev/sdb1, you can use the following command:
sudo vgcreate myvg /dev/sdb1
Creating Logical Volumes
Once you’ve created your volume group, you can use the “lvcreate” command to create logical volumes. For example, to create a logical volume named “mylv” with a size of 10 GB in the “myvg” volume group, you can use the following command:
sudo lvcreate -n mylv -L 10G myvg
The “-n” option specifies the name of the logical volume, and the “-L” option specifies the size of the volume.
Resizing Logical Volumes
To resize a logical volume, you can use the “lvresize” command. For example, to increase the size of the “mylv” logical volume by 5 GB, you can use the following command:
sudo lvresize -L +5G /dev/myvg/mylv
To decrease the size of a logical volume, use the “-L” option with a negative value instead.
Resizing Filesystems
After resizing a logical volume, you’ll need to resize the filesystem on the volume to make use of the additional space. The specific command for resizing the filesystem depends on the type of filesystem you’re using. For example, to resize an ext4 filesystem, you can use the “resize2fs” command. For example, to resize the filesystem on the “mylv” logical volume, you can use the following command:
sudo resize2fs /dev/myvg/mylv
Moving Logical Volumes
To move a logical volume to a different physical volume, you can use the “pvmove” command. For example, to move the “mylv” logical volume from the physical volume /dev/sdb1 to /dev/sdc1, you can use the following command:
sudo pvmove /dev/sdb1 /dev/sdc1
After moving the data to the new physical volume, you can remove the old physical volume from the volume group using the “vgreduce” command. For example, to remove /dev/sdb1 from the “myvg” volume group, you can use the following command:
sudo vgreduce myvg /dev/sdb1
These are just some examples of the commands and procedures involved in working with logical volumes in Ubuntu. For more information, be sure to consult the Ubuntu documentation and other resources.
Conclusion
Logical volumes are an important aspect of storage management in Ubuntu. By allowing you to create virtual partitions that span multiple physical disks, logical volumes provide greater flexibility and scalability than traditional partitioning. With the LVM tool, creating and managing logical volumes is straightforward and user-friendly.
References:
Ubuntu Documentation — LVM: https://help.ubuntu.com/community/LogicalVolumeManager
Red Hat Enterprise Linux 7 Logical Volume Manager Administration: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/index
IBM Knowledge Center — LVM: https://www.ibm.com/support/knowledgecenter/ssw_aix_72/com.ibm.aix.lvm/doc/lvmconcepts.htm