4.8 KiB
obj |
---|
filesystem |
Logical Volume Management (LVM)
Logical Volume Management (LVM) is a method of managing disk drives in a way that is more flexible and scalable than traditional partitioning. LVM provides a layer of abstraction between the physical storage devices and the operating system, allowing for dynamic resizing and efficient management of storage space.
Key Concepts
1. Physical Volumes (PVs):
- Physical volumes are the actual storage devices, such as hard drives or SSDs, that contribute storage space to the LVM.
2. Volume Groups (VGs):
- Volume groups are created by combining one or more physical volumes. They represent a pool of storage from which logical volumes can be allocated.
3. Logical Volumes (LVs):
- Logical volumes are created within volume groups. They act as flexible partitions that can be resized dynamically. They are what the operating system interacts with as if they were physical partitions.
Advantages of LVM
- Dynamic Volume Resizing:
- LVM allows for the resizing of logical volumes while the file systems they contain are mounted and active.
- Snapshot and Backup:
- LVM supports the creation of snapshots, which are point-in-time copies of a logical volume. These snapshots can be used for backup purposes.
- Improved Storage Management:
- LVM simplifies storage management by providing a flexible and dynamic way to allocate and manage disk space.
- Striping and Mirroring:
- LVM supports data striping (improves performance) and mirroring (provides redundancy) for logical volumes.
Usage
pvcreate
Initialize physical volume(s) for use by LVM
Usage: pvcreate /dev/device
pvdisplay
Display various attributes of physical volume(s)
Usage: pvdisplay /dev/device
pvscan
List all physical volumes
Usage: pvscan
vgcreate
Create volume groups combining multiple mass-storage devices.
Usage: vgcreate vg1 /dev/sda1
vgdisplay
Display information about Logical Volume Manager (LVM) volume groups.
Usage: vgdisplay
vgextend
Add physical volumes to a volume group
Usage: vgextend VG PV
vgreduce
Remove physical volume(s) from a volume group
Usage: vgreduce VG PV
lvcreate
Creates a logical volume in an existing volume group.
Usage:
# Create a logical volume of 10 gigabytes in the volume group vg1:
lvcreate -L 10G vg1
# Create a 1500 megabyte linear logical volume named mylv in the volume group vg1:
lvcreate -L 1500 -n mylv vg1
# Create a logical volume called mylv that uses 60% of the total space in the volume group vg1:
lvcreate -l 60%VG -n mylv vg1
# Create a logical volume called mylv that uses all of the unallocated space in the volume group vg1:
lvcreate -l 100%FREE -n mylv vg1
lvdisplay
Display information about Logical Volume Manager (LVM) logical volumes.
Usage:
# Display information about all logical volumes:
lvdisplay
# Display information about all logical volumes in volume group vg1:
lvdisplay vg1
# Display information about logical volume lv1 in volume group vg1:
lvdisplay vg1/lv1
lvextend
Extends a logical volume in an existing volume group.
Usage:
# Extend volume in volume mylv in group vg0
# (defined by volume path /dev/vg0/mylv)
# to 12 gigabyte:
lvextend -L 12G /dev/vg0/mylv
# Extend volume in volume mylv in group vg0 by 1 gigabyte:
lvextend -L +1G /dev/vg0/mylv
# Extend volume in volume mylv in group vg0 to use all of the unallocated space in the volume group vg0:
lvextend -l +100%FREE /dev/vg0/mylv
# Extend ext4 filesystem after changing a logical volume (takes volume path as parameter):
ext2resize /dev/vg0/mylv
# Extend btrfs filesystem after changing a logical volume (takes the mount point as parameter, not the volume path):
btrfs filesystem resize max /mylv
# Extend xfs filesystem after changing a logical volume (takes the mount point as parameter, not the volume path):
xfs_growfs /mylv
lvreduce
Reduce the size of a logical volume.
Usage: lvreduce --size 120G logical_volume
lvremove
Remove one or more logical volumes.
Usage: lvremove volume_group/logical_volume
lvrename
Rename a logical volume
Usage: lvrename VG LV LV_new
lvresize
Change the size of a logical volume.
# Change the size of a logical volume to 120 GB:
lvresize --size 120G volume_group/logical_volume
# Extend the size of a logical volume as well as the underlying filesystem by 120 GB:
lvresize --size +120G --resizefs volume_group/logical_volume
# Extend the size of a logical volume to 100% of the free physical volume space:
lvresize --size 100%FREE volume_group/logical_volume
# Reduce the size of a logical volume as well as the underlying filesystem by 120 GB:
lvresize --size -120G --resizefs volume_group/logical_volume
lvscan
List all logical volumes in all volume groups
Usage: lvscan