Questo contenuto non è disponibile nella lingua selezionata.
Chapter 5. Advanced logical volume management
LVM provides advanced features such as snapshots for point in time copies of logical volumes. It supports caching to speed up slower storage using faster devices. It also enables custom thin pools and VDO logical volumes to improve storage efficiency.
5.1. Managing logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
A snapshot is a logical volume (LV) that mirrors the content of another LV at a specific point in time.
5.1.1. Understanding logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
When you create a snapshot, you are creating a new LV that serves as a point-in-time copy of another LV. Initially, the snapshot LV contains no actual data. Instead, it references the data blocks of the original LV at the moment of snapshot creation.
It is important to regularly monitor the snapshot’s storage usage. If a snapshot reaches 100% of its allocated space, it will become invalid.
It is essential to extend the snapshot before it gets completely filled. This can be done manually by using the lvextend command or automatically via the /etc/lvm/lvm.conf file.
- Thick LV snapshots
- When data on the original LV changes, the copy-on-write (CoW) system copies the unchanged data to the snapshot before applying the change. This way, the snapshot grows in size only as changes occur. It stores the state of the original volume at the time of the snapshot’s creation. Thick snapshots are a type of LV that requires you to allocate some amount of storage space upfront. This amount can later be extended or reduced. However, you should consider what type of changes you intend to make to the original LV. This helps you to avoid wasting resources by allocating too much space or frequently increasing the snapshot size by allocating too little.
- Thin LV snapshots
Thin snapshots are a type of LV created from an existing thin-provisioned LV. Thin snapshots do not require allocating extra space upfront. Initially, both the original LV and its snapshot share the same data blocks. When changes are made to the original LV, it writes new data to different blocks. The snapshot continues to reference the original blocks, preserving a point-in-time view of the LV’s data at the snapshot creation.
Thin provisioning is a method of optimizing and managing storage efficiently by allocating disk space on an as-needed basis. This means that you can create multiple LVs without needing to allocate a large amount of storage upfront for each LV. The storage is shared among all LVs in a thin pool, making it a more efficient use of resources. A thin pool allocates space on-demand to its LVs.
- Choosing between thick and thin LV snapshots
- The choice between thick or thin LV snapshots is directly determined by the type of LV you are taking a snapshot of. If your original LV is a thick LV, your snapshots will be thick. If your original LV is thin, your snapshots will be thin.
5.1.2. Managing thick logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
When you create a thick LV snapshot, it is important to consider the storage requirements and the intended lifespan of your snapshot. You need to allocate enough storage for it based on the expected changes to the original volume.
The snapshot must have a sufficient size to capture changes during its intended lifespan. However, it cannot exceed the size of the original LV. If you expect a low rate of change, a smaller snapshot size of 10%-15% might be sufficient. For LVs with a high rate of change, you might need to allocate 30% or more.
It is essential to extend the snapshot before it gets completely filled. If a snapshot reaches 100% of its allocated space, it becomes invalid. You can monitor the snapshot capacity with the lvs -o lv_name,data_percent,origin command.
5.1.2.1. Creating thick logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
You can create a thick LV snapshot with the lvcreate command.
Prerequisites
- Administrative access.
- You have created a physical volume. For more information, see Creating an LVM physical volume.
- You have created a volume group. For more information, see Creating an LVM volume group.
- You have created a logical volume. For more information, see Creating logical volumes.
Procedure
Identify the LV of which you want to create a snapshot:
# lvs -o vg_name,lv_name,lv_sizeVG LV LSize VolumeGroupName LogicalVolumeName 10.00gThe size of the snapshot cannot exceed the size of the LV.
Create a thick LV snapshot:
# lvcreate --snapshot --size SnapshotSize --name SnapshotName VolumeGroupName/LogicalVolumeNameReplace SnapshotSize with the size you want to allocate for the snapshot (e.g. 10G). Replace SnapshotName with the name you want to give to the snapshot logical volume. Replace VolumeGroupName with the name of the volume group that contains the original logical volume. Replace LogicalVolumeName with the name of the logical volume that you want to create a snapshot of.
Verification
Verify that the snapshot is created:
# lvs -o lv_name,originLV Origin LogicalVolumeName SnapshotName LogicalVolumeName
5.1.2.2. Manually extending logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
If a snapshot reaches 100% of its allocated space, it becomes invalid. It is essential to extend the snapshot before it gets completely filled. This can be done manually by using the lvextend command.
Prerequisites
- Administrative access.
Procedure
List the names of volume groups, logical volumes, source volumes for snapshots, their usage percentages, and sizes:
# lvs -o vg_name,lv_name,origin,data_percent,lv_sizeVG LV Origin Data% LSize VolumeGroupName LogicalVolumeName 10.00g VolumeGroupName SnapshotName LogicalVolumeName 82.00 5.00gExtend the thick-provisioned snapshot:
# lvextend --size +AdditionalSize VolumeGroupName/SnapshotNameReplace AdditionalSize with how much space to add to the snapshot (for example, +1G). Replace VolumeGroupName with the name of the volume group. Replace SnapshotName with the name of the snapshot.
Verification
Verify that the LV is extended:
# lvs -o vg_name,lv_name,origin,data_percent,lv_sizeVG LV Origin Data% LSize VolumeGroupName LogicalVolumeName 10.00g VolumeGroupName SnapshotName LogicalVolumeName 68.33 6.00g
5.1.2.3. Automatically extending thick logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
If a snapshot reaches 100% of its allocated space, it becomes invalid. It is essential to extend the snapshot before it gets completely filled. This can be done automatically.
Prerequisites
- Administrative access.
Procedure
-
Open the
/etc/lvm/lvm.conffile in an editor of your choice. Uncomment the
snapshot_autoextend_thresholdandsnapshot_autoextend_percentlines and set each parameter to a required value:snapshot_autoextend_threshold = 70 snapshot_autoextend_percent = 20snapshot_autoextend_thresholddetermines the percentage at which LVM starts to auto-extend the snapshot. For example, setting the parameter to 70 means that LVM will try to extend the snapshot when it reaches 70% capacity.snapshot_autoextend_percentspecifies by what percentage the snapshot should be extended when it reaches the threshold. For example, setting the parameter to 20 means the snapshot will be increased by 20% of its current size.- Save the changes and exit the editor.
Restart the
lvm2-monitor:# systemctl restart lvm2-monitor
5.1.2.4. Merging thick logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
You can merge a thick LV snapshot into the original logical volume from which the snapshot was created. The process of merging means that the original LV is reverted to the state it was in when the snapshot was created. Once the merge is complete, the snapshot is removed.
The merge between the original and snapshot LV is postponed if either is active. It only proceeds once the LVs are reactivated and not in use.
Prerequisites
- Administrative access.
Procedure
List the LVs, their volume groups, and their paths:
# lvs -o lv_name,vg_name,lv_pathLV VG Path LogicalVolumeName VolumeGroupName /dev/VolumeGroupName/LogicalVolumeName SnapshotName VolumeGroupName /dev/VolumeGroupName/SnapshotNameCheck where the LVs are mounted:
# findmnt -o SOURCE,TARGET /dev/VolumeGroupName/LogicalVolumeName# findmnt -o SOURCE,TARGET /dev/VolumeGroupName/SnapshotNameReplace /dev/VolumeGroupName/LogicalVolumeName with the path to your logical volume. Replace /dev/VolumeGroupName/SnapshotName with the path to your snapshot.
Unmount the LVs:
# umount /LogicalVolume/MountPoint# umount /Snapshot/MountPointReplace /LogicalVolume/MountPoint with the mounting point for your logical volume. Replace /Snapshot/MountPoint with the mounting point for your snapshot.
Deactivate the LVs:
# lvchange --activate n VolumeGroupName/LogicalVolumeName# lvchange --activate n VolumeGroupName/SnapshotNameReplace VolumeGroupName with the name of the volume group. Replace LogicalVolumeName with the name of the logical volume. Replace SnapshotName with the name of your snapshot.
Merge the thick LV snapshot into the origin:
# lvconvert --merge VolumeGroupName/SnapshotNameReplace VolumeGroupName with the name of the volume group. Replace SnapshotName with the name of the snapshot.
Activate the LV:
# lvchange --activate y VolumeGroupName/LogicalVolumeNameReplace VolumeGroupName with the name of the volume group. Replace LogicalVolumeName with the name of the logical volume.
Mount the LV:
# mount /dev/VolumeGroupName/LogicalVolumeName /LogicalVolume/MountPointReplace /dev/VolumeGroupName/LogicalVolumeName with the path to your logical volume. Replace /LogicalVolume/MountPoint with the mounting point for your logical volume.
Verification
Verify that the snapshot is removed:
# lvs -o lv_name
5.1.3. Managing thin logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
Thin provisioning is appropriate where storage efficiency is a priority. Storage space dynamic allocation reduces initial storage costs and maximizes the use of available storage resources.
In environments with dynamic workloads or where storage grows over time, thin provisioning allows for flexibility. It enables the storage system to adapt to changing needs without requiring large upfront allocations of the storage space. With dynamic allocation, over-provisioning is possible. The total size of all Logical Volumes (LVs) can exceed the physical size of the thin pool. This can take place under the assumption that not all space will be utilized at the same time.
5.1.3.1. Creating thin logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
You can create a thin LV snapshot with the lvcreate command. When creating a thin LV snapshot, avoid specifying the snapshot size. Including a size parameter results in the creation of a thick snapshot instead.
Prerequisites
- Administrative access.
- You have created a physical volume. For more information, see Creating an LVM physical volume.
- You have created a volume group. For more information, see Creating an LVM volume group.
- You have created a logical volume. For more information, see Creating logical volumes.
Procedure
Identify the LV of which you want to create a snapshot:
# lvs -o lv_name,vg_name,pool_lv,lv_sizeLV VG Pool LSize PoolName VolumeGroupName 152.00m ThinVolumeName VolumeGroupName PoolName 100.00mCreate a thin LV snapshot:
# lvcreate --snapshot --name ThinSnapshotName VolumeGroupName/ThinVolumeNameReplace ThinSnapshotName with the name you want to give to the snapshot logical volume. Replace VolumeGroupName with the name of the volume group that contains the original logical volume. Replace ThinVolumeName with the name of the thin logical volume that you want to create a snapshot of.
Verification
Verify that the snapshot is created:
# lvs -o lv_name,originLV Origin PoolName ThinSnapshotName ThinVolumeName ThinVolumeName
5.1.3.2. Merging thin logical volume snapshots Copia collegamentoCollegamento copiato negli appunti!
You can merge thin LV snapshot into the original logical volume from which the snapshot was created. The process of merging means that the original LV is reverted to the state it was in when the snapshot was created. Once the merge is complete, the snapshot is removed.
Prerequisites
- Administrative access.
Procedure
List the LVs, their volume groups, and their paths:
# lvs -o lv_name,vg_name,lv_pathLV VG Path ThinPoolName VolumeGroupName ThinSnapshotName VolumeGroupName /dev/VolumeGroupName/ThinSnapshotName ThinVolumeName VolumeGroupName /dev/VolumeGroupName/ThinVolumeNameCheck where the original LV is mounted:
# findmnt -o SOURCE,TARGET /dev/VolumeGroupName/ThinVolumeNameReplace VolumeGroupName/ThinVolumeName with the path to your logical volume.
Unmount the LV:
# umount /ThinVolumeName/MountPointReplace /ThinVolumeName/MountPoint with the mounting point for your logical volume. Replace /ThinSnapshot/MountPoint with the mounting point for your snapshot.
Deactivate the LV:
# lvchange --activate n VolumeGroupName/ThinVolumeNameReplace VolumeGroupName with the name of the volume group. Replace ThinVolumeName with the name of the logical volume.
Merge the thin LV snapshot into the origin:
# lvconvert --mergethin VolumeGroupName/ThinSnapshotNameReplace VolumeGroupName with the name of the volume group. Replace ThinSnapshotName with the name of the snapshot.
Mount the LV:
# mount /ThinVolumeName/MountPointReplace /ThinVolumeName/MountPoint with the mounting point for your logical volume.
Verification
Verify that the original LV is merged:
# lvs -o lv_name
5.2. Caching logical volumes Copia collegamentoCollegamento copiato negli appunti!
You can cache logical volumes by using the dm-cache or dm-writecache targets.
dm-cache utilizes solid-state disks (SSD) as cache for slower hard disk drive (HDD). It caches read and write data, optimizing access times for frequently used data. It is beneficial in mixed workload environments where enhancing read and write operations can lead to significant performance improvements.
dm-writecache optimizes write operations by using a faster storage medium (SSD) to temporarily hold write data before it is committed to the primary storage device (HDD). It is beneficial for write-intensive applications where write performance can slow down the data transfer process.
5.2.1. Caching logical volumes with dm-cache Copia collegamentoCollegamento copiato negli appunti!
When caching LV with dm-cache, a cache pool is created. A cache pool is a LV that combines both the cache data, which stores the actual cached content, and cache metadata, which tracks what content is stored in the cache. This pool is then associated with a specific LV to cache its data.
dm-cache targets two types of blocks: frequently accessed (hot) blocks are moved to the cache, while less frequently accessed (cold) blocks remain on the slower device.
Prerequisites
- Administrative access.
Procedure
Display the LV you want to cache and its volume group:
# lvs -o lv_name,vg_nameLV VG LogicalVolumeName VolumeGroupNameCreate the cache pool:
# lvcreate --type cache-pool --name CachePoolName --size Size VolumeGroupName /FastDevicePathReplace CachePoolName with the name of the cache pool. Replace Size with the size for your cache pool. Replace VolumeGroupName with the name of the volume group. Replace /FastDevicePath with the path to your fast device, for example SSD or NVME.
Attach the cache pool to the LV:
# lvconvert --type cache --cachepool VolumeGroupName/CachePoolName VolumeGroupName/LogicalVolumeName
Verification
Verify that the LV is now cached:
# lvs -o lv_name,pool_lvLV Pool LogicalVolumeName [CachePoolName_cpool]
5.2.2. Caching logical volumes with dm-writecache Copia collegamentoCollegamento copiato negli appunti!
When caching LVs with dm-writecache, a caching layer between the logical volume and the physical storage device is created. dm-writecache operates by temporarily storing write operations in a faster storage medium, such as an SSD, before eventually writing them back to the primary storage device, optimizing write-intensive workloads.
Prerequisites
- Administrative access.
Procedure
Display the logical volume you want to cache and its volume group:
# lvs -o lv_name,vg_nameLV VG LogicalVolumeName VolumeGroupNameCreate a cache volume:
# lvcreate --name CacheVolumeName --size Size VolumeGroupName /FastDevicePathReplace CacheVolumeName with the name of the cache volume. Replace Size with the size for your cache pool. Replace VolumeGroupName with the name of the volume group. Replace /FastDevicePath with the path to your fast device, for example SSD or NVME.
Deactivate the cache volume:
# lvchange -an VolumeGroupName/CacheVolumeNameReplace VolumeGroupName with the name of the volume group. Replace CacheVolumeName with the name of the cache volume.
Attach the cache volume to the LV:
# lvconvert --type writecache --cachevol CacheVolumeName VolumeGroupName/LogicalVolumeNameReplace CacheVolumeName with the name of the cache volume. Replace VolumeGroupName with the name of the volume group. Replace LogicalVolumeName with the name of the logical volume.
Verification
Verify that the LV is now cached:
# lvs -o lv_name,pool_lvLV Pool LogicalVolumeName [CacheVolumeName_cvol]
5.2.3. Uncaching a logical volume Copia collegamentoCollegamento copiato negli appunti!
You can remove caching from a logical volume, either by detaching the cache volume while preserving its data, or by completely uncache the logical volume and remove the cache, freeing up storage space.
Use two main ways to remove caching from a LV.
- Splitting
- You can detach the cache from the LV but preserve the cache volume itself. In this case the LV will no longer benefit from the caching mechanism but the cache volume and its data will remain intact. While the cache volume is preserved, the data within the cache cannot be reused and will be erased the next time it is used in a caching setup.
- Uncaching
- You can detaches the cache from the LV and remove the cache volume entirely. This action effectively destroys the cache, freeing up the space.
Prerequisites
- Administrative access.
Procedure
Display the cached LV:
# lvs -o lv_name,pool_lv,vg_nameLV Pool VG LogicalVolumeName [CacheVolumeName_cvol] VolumeGroupNameDetach or remove the cached volume:
To detach the cached volume, use:
# lvconvert --splitcache VolumeGroupName/LogicalVolumeNameTo detach and remove the cached volume, use:
# lvconvert --uncache VolumeGroupName/LogicalVolumeNameReplace VolumeGroupName with the name of the volume group. Replace LogicalVolumeName with the name of the logical volume.
Verification
Verify that the LV is not cached:
# lvs -o lv_name,pool_lv
5.3. Creating a custom thin pool Copia collegamentoCollegamento copiato negli appunti!
You can create custom thin pools to have a better control over the storage.
Prerequisites
- Administrative access.
Procedure
Display available volume groups:
# vgs -o vg_nameVG VolumeGroupNameList available devices:
# lsblkCreate a LV to hold the thin pool data:
# lvcreate --name ThinPoolDataName --size Size VolumeGroupName /DevicePathReplace ThinPoolDataName with the name for your thin pool data LV. Replace Size with the size for your LV. Replace VolumeGroupName with the name of your volume group. Replace /DevicePath with your device path.
Create a LV to hold the thin pool metadata:
# lvcreate --name ThinPoolMetadataName --size Size VolumeGroupName /DevicePathCombine the LVs into a thin pool:
# lvconvert --type thin-pool --poolmetadata ThinPoolMetadataName VolumeGroupName/ThinPoolDataName
Verification
Verify that the custom thin pool is created:
# lvs -o lv_name,seg_typeLV Type ThinPoolDataName thin-pool
5.4. Creating a custom VDO logical volume Copia collegamentoCollegamento copiato negli appunti!
With Logical Volume Manager (LVM), you can create a custom LV that uses Virtual Data Optimizer (VDO) pool for data storage.
Prerequisites
- Administrative access.
Procedure
Display the VGs:
# vgsVG #PV #LV #SN Attr VSize VFree VolumeGroupName 1 0 0 wz--n- 28.87g 28.87gCreate a LV to be converted to a VDO pool:
# lvcreate --name VDOPoolName --size Size VolumeGroupName /DevicePathReplace VDOPoolName with the name for your VDO pool. Replace Size with the size for your VDO pool. Replace VolumeGroupName with the name of the VG. Replace /DevicePath with your device path.
Convert this LV to a VDO pool. In this conversion, you are creating a new VDO LV that uses the VDO pool. Because
lvcreateis creating a new VDO LV, you must specify parameters for the new VDO LV. Use--name|-nto specify the name of the new VDO LV, and--virtualsize|-Vto specify the size of the new VDO LV.# lvconvert --type vdo-pool --name VDOVolumeName --virtualsize VDOVolumeSize VolumeGroupName/VDOPoolNameReplace VDOVolumeName with the name for your VDO volume. Replace VDOVolumeSize with the size for your VDO volume. Replace VolumeGroupName/VDOPoolName with the names for your VG and your VDO pool.
Verification
Verify that the LV is converted to the VDO pool:
# lvs -o lv_name,vg_name,seg_typeLV VG Type VDOPoolName VolumeGroupName vdo-pool VDOVolumeName VolumeGroupName vdo