LVM: an introductory guide to logical volumes
Logical Volume Management is easily one of the most important and useful tools in storage administration. With LVM you can easily move “partitions” (volumes) around your physical disk, have snapshots, even mirroring or live migrations across disks become possible.
Disclaimer: I take absolutely no responsibility for what you do following this tutorial, thus it is made only as a reference and for learning purpose.
LVM at a glance
Before we fire up the terminal, let’s take a look at the LVM structure. LVM is an abstraction layer, a way to provide higher-level functions using lower-level ones. This enables you to have much more flexibility and in the end a higher level of control over your disks. Let’s now define three important concept: PV, VG and LV.
- Physical Volume: A physical volume is a device or a partition that will be used to support LVM.
- Volume Group: A volume group is a group of one or more PV. VG can span across multiple PV.
- Logical Volume: A logical volume is the final step of this chain, it acts as a partition to the file system. It belongs to a VG, and is physically stored on one of the PV of its VG.
We didn’t cover PE and LE, since they’re not fundamental to understand the basics of LVM. Feel free to learn about them after you’ve done some practice with it.
LVM-ization
Creating your very first LVM volume is really easy. The first step is to create a PV: a partition or an entire device. Remember: that space (and its data) will be lost upon creating a PV, so be warned to back up whatever you’re using. Done? In case of a whole disk:
# pvcreate /dev/sdX
In case of a partition use:
# pvcreate /dev/sdXY
Of course replace X with the letter of the device you want to use and Y with the number of the partition. Once done it is time to create a VG do so by:
# vgcreate NAME /dev/sdXY
Replace NAME with the desired name of the volume group and use the device/partition you used in the precedent step. Once done, you’re practically done, you can now start creating and manipulating your LVs. To create one you just need to issue:
# lvcreate -L SIZE -n NAME VOLUME_GROUP
Replace SIZE with the desired size with a suffix e.g. 10G or 250M. Replace NAME with the desired volume name. Replace VOLUME_GROUP with the volume group you created before. That’s it, you’ve just create a LV that acts exactly like a partition, but is way more flexible. First, to access it you should seek /dev/VG_NAME/LV_NAME . Now let’s take a look at the most used commands associated with LVM.
# Physical Volumes pvcreate /dev/sdXY # Create a PV pvremove /dev/sdXY # Remove a PV pvdisplay # Display detailed information about PVs pvs # Display brief information about PVs # Volume Groups vgcreate NAME /dev/sdXY # Create a VG named NAME on PV /dev/sdXY vgremove NAME # Destroy the VG named NAME vgextend NAME /dev/sdXY # Extend the VG named NAME over PV /dev/sdXY vgreduce NAME /dev/sdXY # Remove PV /dev/sdXY from VG named NAME vgdisplay # Display detailed information about VGs vgs # Display brief information about VGs # Logical Volumes lvcreate -L SIZE -n NAME VG # Create a LV named NAME with SIZE onto VG lvremove /dev/VG/LV # Remove LV from VG lvextend -L SIZE /dev/VG/LV # Add SIZE space to LV lvreduce -L SIZE /dev/VG/LV # Reduce LV by SIZE lvdisplay # Display detailed information about LVs lvs # Display brief information about LVs
Image courtesy of Docklandsboy.
- 2020 A year in review for Marksei.com - 30 December 2020
- Red Hat pulls the kill switch on CentOS - 16 December 2020
- OpenZFS 2.0 released: unified ZFS for Linux and BSD - 9 December 2020
Recent Comments