|
| 1 | +--- |
| 2 | +title: LVM Cache |
| 3 | +description: How to create LVM setup with LVM Cache |
| 4 | +weight: 10 |
| 5 | +aliases: |
| 6 | + - ../../os/lvm-cache |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +From lvmcache(7): |
| 11 | + |
| 12 | +> The cache logical volume type uses a small and fast LV to improve the performance of a large and slow LV. It does this by storing the frequently used blocks on the faster LV. LVM refers to the small fast LV as a cache pool LV. The large slow LV is called the origin LV. D |
| 13 | +
|
| 14 | + |
| 15 | +**Setting up the LVM cache** |
| 16 | + |
| 17 | +You can create the LVM setup with [pvcreate](https://linux.die.net/man/8/pvcreate), [vgcreate](https://linux.die.net/man/8/vgcreate), [lvcreate](https://linux.die.net/man/8/lvcreate), and [lvconvert]([https://linux.die.net/man/8/pvcreate](https://linux.die.net/man/8/lvconvert)) traditionally. See below: |
| 18 | + |
| 19 | +For Flatcar you could use a butane configuration file for the same that would be transpiled to ignition for the same purpose (upload a script for your setup based on above somewhere): |
| 20 | + |
| 21 | +The following is a Butane YAML config - replace the `...` placeholders with your desired values: |
| 22 | + |
| 23 | +``` |
| 24 | +variant: flatcar |
| 25 | +version: 1.0.0 |
| 26 | +systemd: |
| 27 | + units: |
| 28 | + - name: lvm-cache-setup.service |
| 29 | + enabled: true |
| 30 | + contents: | |
| 31 | + [Unit] |
| 32 | + Description=LVM Cachesetup |
| 33 | + ConditionFirstBoot=yes |
| 34 | + Before=local-fs-pre.target |
| 35 | + [Service] |
| 36 | + Type=oneshot |
| 37 | + Restart=on-failure |
| 38 | + RemainAfterExit=yes |
| 39 | + ExecStart=.../lvm-cache.sh |
| 40 | + [Install] |
| 41 | + WantedBy=multi-user.target |
| 42 | + - name: llvm-cache.mount |
| 43 | + enabled: true |
| 44 | + contents: | |
| 45 | + [Unit] |
| 46 | + Description=LVM Mount |
| 47 | + [Mount] |
| 48 | + What=/dev/cache-layer-vg/data |
| 49 | + Where="${DIRECTORYTOMOUNTVOLUME}" |
| 50 | + Type=ext4 |
| 51 | + Options=defaults |
| 52 | + [Install] |
| 53 | + WantedBy=local-fs.target |
| 54 | +storage: |
| 55 | + files: |
| 56 | + - path: .../lvm-cache.sh |
| 57 | + mode: 0744 |
| 58 | + contents: |
| 59 | + inline: | |
| 60 | + #!/bin/bash |
| 61 | + set -euo pipefail |
| 62 | + |
| 63 | + # Define variables |
| 64 | + VOLUME="/dev/...." |
| 65 | + DEVA="/dev/..." |
| 66 | + DEVB="/dev/..." |
| 67 | + CACHEDISKSIZE="...G" |
| 68 | + METADISKSIZE="...G" |
| 69 | + DIRECTORYTOMOUNTVOLUME="...." |
| 70 | + |
| 71 | + # Create Physical Volumes |
| 72 | + pvcreate "${VOLUME}" "${DEVA}" "${DEVB}" |
| 73 | + |
| 74 | + # Create Volume Group |
| 75 | + vgcreate cache-layer-vg "$VOLUME" "$DEVA" "$DEVB" |
| 76 | + |
| 77 | + # Create Logical Volume for data |
| 78 | + lvcreate -l 100%FREE -n data cache-layer-vg "$VOLUME" |
| 79 | + |
| 80 | + # Create Logical Volumes for cachedisk and metadisk |
| 81 | + lvcreate -L $"{CACHEDISKSIZE}" -n cachedisk cache-layer-vg |
| 82 | + lvcreate -L $"{METADISKSIZE}" -n metadisk cache-layer-vg |
| 83 | + |
| 84 | + # Convert cachedisk to cache pool with metadisk as pool metadata |
| 85 | + lvconvert --type=cache-pool /dev/cache-layer-vg/cachedisk --poolmetadata /dev/cache-layer-vg/metadisk |
| 86 | + |
| 87 | + # Convert data volume to cache volume using cachedisk as the cache pool |
| 88 | + lvconvert --type cache /dev/cache-layer-vg/data --cachepool /dev/cache-layer-vg/cachedisk |
| 89 | + |
| 90 | + # Format the data volume with ext4 filesystem |
| 91 | + mkfs.ext4 /dev/cache-layer-vg/data |
| 92 | + |
| 93 | + # Create directory for mounting the data volume |
| 94 | + mkdir "${DIRECTORYTOMOUNTVOLUME}" |
| 95 | +
|
| 96 | +``` |
| 97 | + |
| 98 | +Then you transpile it to ignition: |
| 99 | + |
| 100 | +``` |
| 101 | +cat cl.yaml | docker run --rm -i quay.io/coreos/butane:latest > ignition-config.json |
| 102 | +``` |
| 103 | + |
| 104 | + |
0 commit comments