Click on each book below to review & buy on Amazon.
As an Amazon Associate, I earn from qualifying purchases.
CompTIA Linux+ XK0-005 - 1.3 - Creating & Modifying Volumes Using Logical Volume Manager (LVM)
The Logical Volume Manager (LVM) presents a dynamic and versatile method for managing storage across multiple physical devices within Linux environments. It abstracts the complexities of physical storage into manageable logical units, thereby streamlining tasks such as volume resizing, relocation, and management, while ensuring data integrity and accessibility. This guide is designed to navigate you through the essential commands and operations within LVM, starting with the creation and management of physical volumes. We will then progress to the intricacies of volume groups, and conclude with a detailed look at logical volumes.
Physical Volumes
Understanding the management of physical volumes (PVs) is fundamental in LVM. This section outlines the essential commands for interacting with PVs.
Displaying Physical Volume Information
To view detailed information about your system's physical volumes, the pvs
command is invaluable. It reveals critical details such as the volume's name, size, and available space. For instance:
$ pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 vg01 lvm2 a-- 100.00g 20.00g
/dev/sdb1 vg01 lvm2 a-- 50.00g 50.00g
The pvs
command lists the physical volumes on the system, showing each volume's group, format, attributes, total size, and free space. In this example, /dev/sda2
and /dev/sdb1
are part of the volume group vg01
, indicating that they are managed by LVM and contributing their storage space to the group. The attributes column (Attr
) shows the state of the volume, with a--
indicating that the volume is active.
Creating a Physical Volume
The pvcreate
command initializes a physical storage device as a PV for LVM use. This step is necessary for incorporating the device into your LVM configuration. Here's how you use it:
$ pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
pvcreate
is used to mark a physical storage device as usable by LVM, turning it into a physical volume. By running pvcreate
on /dev/sdc1
, we designate this partition as part of LVM's management domain. This action allows the device to be included in volume groups but erases existing data on the device.
Volume Groups
Volume groups (VGs) are a core component of LVM, allowing for flexible management of physical volumes. This section covers the creation and extension of VGs.
Viewing Volume Group Information
The vgs
command offers insights into your VGs, displaying names, sizes, free space, and the number of PVs included. Executing vgs
without arguments provides information on all VGs:
$ vgs
VG #PV #LV #SN Attr VSize VFree
vg1 1 2 0 wz--n- 100.00g 50.00g
vg2 2 1 0 wz--n- 200.00g 80.00g
vgs
provides a summary of volume groups, including the total size and available space. It lists the number of physical volumes (#PV), logical volumes (#LV), and snapshots (#SN) within each volume group, alongside their attributes (Attr
).
Creating a Volume Group
To establish a new VG, use the vgcreate
command with the desired VG name and the devices you intend to include:
$ vgcreate vg3 /dev/sdb1 /dev/sdc1
Volume group "vg3" successfully created
vgcreate
creates a new volume group named vg3
with /dev/sdb1
and /dev/sdc1
as member physical volumes. This command effectively pools the storage of the specified devices, allowing for flexible allocation of logical volumes within the group.
Extending a Volume Group
The vgextend
command facilitates the expansion of an existing VG by incorporating additional PVs, thus increasing its storage capacity:
$ vgextend vg2 /dev/sdd1
Volume group "vg2" successfully extended
Using vgextend
to add /dev/sdd1
to vg2
increases the group's storage capacity. This command is useful for adding more space to a volume group as storage needs grow.
Logical Volumes
This section delves into the management of logical volumes (LVs), detailing commands for their creation, resizing, and attribute modification.
Listing Logical Volumes
The lvs
command is used to list LVs, providing a snapshot of their configuration, including names, sizes, and allocation policies:
$ lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 10.00g
lv2 vg1 -wi-a----- 20.00g
lv3 vg2 -wi-a----- 30.00g
lvs
displays a list of all logical volumes in the system, showing their volume group, attributes, size, and other relevant details. It helps in monitoring and managing the sizes and statuses of logical volumes.
Creating Logical Volumes
The lvcreate
command is essential for adding new LVs to a VG. Specify the LV name, the VG it will belong to, and its size:
$ lvcreate -L 50G -n lv4 vg2
Logical volume "lv4" created.
lvcreate
is used to create a new logical volume named (-n
) lv4
within the volume group vg2
with a size (-L
) f 50GB
. This command allows for specifying the size and name of the new logical volume, offering flexibility in storage allocation.
Resizing Logical Volumes
Adjusting the size of LVs is straightforward with the lvresize
command, allowing for expansion or reduction as needed:
$ lvresize -L +10G /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 10.00 GiB (2560 extents) to 20.00 GiB (5120 extents).
Logical volume lv1 successfully resized.
lvresize
modifies the size of an existing logical volume. In this case, it increases the size of lv1
in vg1
by 10GB. The command demonstrates the ability to adjust storage allocations dynamically to meet changing requirements.
Changing Logical Volume Attributes
To modify LV properties, such as access permissions or allocation policies, the lvchange
command is used:
$ lvchange -p rw /dev/vg1/lv2
Logical volume vg1/lv2 changed.
lvchange
adjusts the attributes of a logical volume, such as changing its permission to read/write (-p rw
). This command is useful for modifying logical volume settings without affecting the data stored on them.
Conclusion
This guide has walked you through the essentials of managing storage using the Logical Volume Manager (LVM) on Linux systems. Beginning with the initialization of physical volumes using pvcreate
, extending through the creation and extension of volume groups with vgcreate
and vgextend
, and culminating in the nuanced management of logical volumes with commands like lvcreate
, lvresize
, and lvchange
, we've covered a broad spectrum of LVM functionalities. Each section has been crafted to equip you with the knowledge needed to perform these tasks effectively, providing examples to illustrate the practical application of commands in real-world scenarios.
Support DTV Linux
Click on each book below to review & buy on Amazon. As an Amazon Associate, I earn from qualifying purchases.
NordVPN ®: Elevate your online privacy and security. Grab our Special Offer to safeguard your data on public Wi-Fi and secure your devices. I may earn a commission on purchases made through this link.