This shows you the differences between two versions of the page.
Previous revisionLast revision | |||
— | fuss:lvm [2020/06/08 04:15] – office | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Use External Disk for Caching ====== | ||
+ | |||
+ | An external disk, such as an SSD or NVME can be used to cache an existing LVM logical volume. In combination with qemu/kvm virtualization, | ||
+ | |||
+ | Assuming that a physical volume along with a volume group and a few logical volumes exist that have to be cached, the following commands can be used to attach an SSD or NVME drive and enable caching for the various logical volumes. | ||
+ | |||
+ | The physical disk layout is the following (by issuing the '' | ||
+ | < | ||
+ | PV | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | revealing a slow drive (origin drive) ''/ | ||
+ | |||
+ | Now, an NVME drive is used to create a new LVM physical disk: | ||
+ | <code bash> | ||
+ | pvcreate / | ||
+ | </ | ||
+ | |||
+ | resulting in the following configuration: | ||
+ | < | ||
+ | PV | ||
+ | / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Note that the entire NVME drive has been used instead of a partitioning the NVME drive (''/ | ||
+ | |||
+ | Next, it is assumed that a volume group ('' | ||
+ | < | ||
+ | VG #PV #LV #SN Attr VSize VFree | ||
+ | vms | ||
+ | </ | ||
+ | |||
+ | and the volume group must be extended over the new NVME physical disk: | ||
+ | <code bash> | ||
+ | vgextend vms / | ||
+ | </ | ||
+ | |||
+ | Now the setup is ready for a few cache containers to be created for existing logical volumes. Assume the following LVM layout for logical volumes obtained via the '' | ||
+ | < | ||
+ | LV | ||
+ | find.vm | ||
+ | shinobi.vm | ||
+ | |||
+ | </ | ||
+ | |||
+ | where two logical volumes exist, '' | ||
+ | |||
+ | To create a cache for '' | ||
+ | * one logical volume acting as the actual cache, | ||
+ | * one logical volume acting as the cache metadata | ||
+ | |||
+ | using the following commands, in order: | ||
+ | <code bash> | ||
+ | lvcreate -L 20G -n find.vm-cache vms / | ||
+ | </ | ||
+ | where: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * ''/ | ||
+ | |||
+ | <code bash> | ||
+ | lvcreate -L 20M -n find.vm-cache-meta vms / | ||
+ | </ | ||
+ | where: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * ''/ | ||
+ | |||
+ | Issuing '' | ||
+ | |||
+ | < | ||
+ | LV | ||
+ | find.vm | ||
+ | find.vm-cache | ||
+ | find.vm-cache-meta | ||
+ | shinobi.vm | ||
+ | |||
+ | </ | ||
+ | |||
+ | With the two cache and cache metadata logical volumes created, both are then combined: | ||
+ | <code bash> | ||
+ | lvconvert --type cache-pool --cachemode writethrough --poolmetadata vms/ | ||
+ | </ | ||
+ | |||
+ | Now, the logical volume '' | ||
+ | <code bash> | ||
+ | lvconvert --type cache --cachepool vms/ | ||
+ | </ | ||
+ | |||
+ | Issuing the '' | ||
+ | < | ||
+ | find.vm | ||
+ | </ | ||
+ | |||
+ | Now the '' | ||
+ | |||
+ | The result can be seen by issuing the command: | ||
+ | </code bash> | ||
+ | lvs -a -o +devices | ||
+ | </ | ||
+ | |||
+ | ===== Removing the Cache ===== | ||
+ | |||
+ | To remove the caching, simply delete the cache volume: | ||
+ | <code bash> | ||
+ | lvremove vms/ | ||
+ | </ | ||
+ | |||
+ | and LVM will take care to flush the cache to the cached logical drive before removing it. | ||
+ | |||
+ | |||
+ | |||