<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>LVM · XB Field Notes</title><link>https://hk.xbcatm.com/tags/lvm/</link><description>Illustrated field notes on HTTP, DNS, TLS, Caddy, SSH, releases, and recovery.</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://hk.xbcatm.com/tags/lvm/index.xml" rel="self" type="application/rss+xml"/><item><title>LVM snapshots capture a block device in time</title><link>https://hk.xbcatm.com/posts/lvm-logical-volume-snapshot/</link><pubDate>Mon, 10 Apr 2028 00:00:00 +0000</pubDate><guid>https://hk.xbcatm.com/posts/lvm-logical-volume-snapshot/</guid><description>A classic LVM snapshot preserves changed chunks in a finite COW store; consistent backup and merge availability require separate planning.</description><content:encoded>&lt;p&gt;A classic LVM snapshot uses a copy-on-write exception store attached to an origin logical volume. &lt;code&gt;lvcreate -s -L 5G -n snap vg/data&lt;/code&gt; requests a 5 GiB store, subject to allocation granularity and available volume-group space. It avoids copying the whole origin at creation, but does not guarantee zero work or instant completion. Thin snapshots use a different shared-pool mechanism.&lt;/p&gt;
&lt;p&gt;The exception store must cover distinct changed chunks and metadata for the entire retention window, including writes during backup. A burst can consume it earlier than a quiet-workload estimate predicts. If a classic store fills, the snapshot becomes invalid and reads fail. Monitor validity and growth early enough to extend or finish the backup; a nominal percentage alone is not a recovery plan.&lt;/p&gt;
&lt;h2 id="an-exception-store-not-a-copy"&gt;An exception store, not a copy&lt;/h2&gt;
&lt;p&gt;The origin uses the &lt;code&gt;snapshot-origin&lt;/code&gt; target, while &lt;code&gt;snapshot&lt;/code&gt; combines unchanged origin chunks with preserved exceptions. Writes to the snapshot itself go to its COW device. Repeated changes to an already-excepted chunk do not require another original copy for that snapshot. The earlier million-write, sixteen-chunk, fifteen-exception result has no recovered trace; touching all sixteen distinct chunks would require sixteen data exceptions, plus metadata.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;lvs -a -o lv_name,lv_attr,origin,data_percent,lv_size&lt;/code&gt; exposes type, state and usage. &lt;code&gt;swi-a-s---&lt;/code&gt; is illustrative, not one universal attribute string; the fifth character I means invalid snapshot. Alert thresholds must leave room for observed write rates and response time. &lt;code&gt;lvextend&lt;/code&gt; needs available VG extents. &lt;code&gt;lvchange --monitor y&lt;/code&gt; enables monitoring, not guaranteed extension: dmeventd, configured autoextend policy and free capacity are also required.&lt;/p&gt;
&lt;h2 id="exhaustion-is-invalidation"&gt;Exhaustion is invalidation&lt;/h2&gt;
&lt;p&gt;Kernel documentation says an exhausted classic COW store is disabled and returns errors. The lvcreate manual&amp;rsquo;s twenty-percent-of-origin command is an example, not a general sizing recommendation. Account for chunk granularity, metadata, workload bursts and the full backup duration. Increasing capacity before exhaustion preserves a valid snapshot; an invalid recovery point must not be treated as complete merely because its LV still exists.&lt;/p&gt;
&lt;p&gt;Origin writes normally continue when a classic snapshot overflows, but this does not guarantee that unrelated origin or storage failures cannot occur. An invalid snapshot is unusable as the recovery point; it did exist and may have supplied an earlier verified backup. Do not confuse current snapshot validity with the separate integrity of a copy already completed elsewhere.&lt;/p&gt;
&lt;h2 id="merging-and-why-thin-changes-the-failure"&gt;Merging, and why thin changes the failure&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;lvconvert --merge vg/snap&lt;/code&gt; merges a persistent COW snapshot back into its origin and consumes the snapshot. It starts immediately when both LVs are closed; otherwise LVM defers it until an activation when both are closed. The origin may serve I/O after merging begins, with affected writes deferred as required. This is not a guarantee of interruption-free rollback, and newer origin data can be discarded.&lt;/p&gt;
&lt;p&gt;A thin snapshot shares data and metadata capacity with other thin LVs instead of owning a separately sized COW store. Data exhaustion may queue writes or return errors according to policy; metadata exhaustion is another failure mode. Such failures can affect multiple volumes and filesystems, but do not imply instant destruction of every volume. Monitor both pool percentages, policy and extension capacity.&lt;/p&gt;
&lt;h2 id="when-it-breaks"&gt;When it breaks&lt;/h2&gt;
&lt;p&gt;A block snapshot is not automatically an application-consistent backup. Filesystem and database buffers, logging and data spread across volumes require coordinated handling and recovery. During copying, check snapshot validity and propagate read failures; verify the resulting contents and a restore. A successful command exit or mount alone does not establish completeness, and this review performed no LVM creation, exhaustion, extension or merge experiment.&lt;/p&gt;
&lt;p&gt;Before a merge, identify open users of both origin and snapshot and plan the application outage or activation boundary. Rehearse on disposable volumes and keep an independent backup. Size for all distinct changes across the retention window, not just its busiest hour. Confirm the actual resulting volume and restored application state; do not infer success solely from declining allocation counters.&lt;/p&gt;
&lt;figure class="technical-diagram"&gt;
&lt;img loading="lazy" src="https://hk.xbcatm.com/visuals/posts-lvm-logical-volume-snapshot.detail.en.svg" alt="Classic LVM combines unchanged origin chunks with finite saved exceptions; overflow invalidation, thin-pool capacities and merge conditions are distinct." width="560" height="2262"&gt;
&lt;figcaption&gt;LVM keeps changed chunks — mechanism diagram.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="check-it-quickly"&gt;Check it quickly&lt;/h2&gt;
&lt;p&gt;The unchanged lines below remain held. They contain environment-specific names and require authorized LVM access; &lt;code&gt;lvextend&lt;/code&gt; changes allocation, so this is not a read-only diagnostic block. No device-mapper, kernel, volume or mount operation was executed:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;lvs -a -o lv_name,vg_name,lv_attr,origin,data_percent,lv_size
lvs -a -o lv_name,data_percent,metadata_percent vg/thinpool
dmsetup status vg-snap
lvextend -L +2G vg/snap
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Classic snapshot Data% and its validity state differ from a thin pool&amp;rsquo;s Data% and Meta%. &lt;code&gt;dmsetup status&lt;/code&gt; output is target-specific: normal snapshot allocation need not fall, while snapshot-merge allocation can decrease toward its metadata remainder. The final line neither proves free VG capacity nor revives an invalid snapshot. A separately held complete exercise must bind targets and verify each claimed transition.&lt;/p&gt;
&lt;h2 id="sources"&gt;Sources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://man7.org/linux/man-pages/man8/lvcreate.8.html"&gt;lvcreate(8)&lt;/a&gt;, documents &lt;code&gt;-s&lt;/code&gt;/&lt;code&gt;--snapshot&lt;/code&gt;, COW versus thin snapshots and illustrative sizing commands, checked 2026-09-16.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://man7.org/linux/man-pages/man8/lvs.8.html"&gt;lvs(8)&lt;/a&gt;, defines the &lt;code&gt;lv_attr&lt;/code&gt; state characters including invalid snapshot, checked 2026-09-16.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.kernel.org/admin-guide/device-mapper/snapshot.html"&gt;Device-mapper snapshot support&lt;/a&gt;, the exception store, invalidation and &lt;code&gt;lvconvert --merge&lt;/code&gt; behaviour, checked 2026-09-16.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://man7.org/linux/man-pages/man7/lvmthin.7.html"&gt;lvmthin(7)&lt;/a&gt;, thin snapshots, pool exhaustion and automatic extension, checked 2026-09-16.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://man7.org/linux/man-pages/man8/lvconvert.8.html"&gt;lvconvert(8)&lt;/a&gt;, immediate versus deferred merge and open-volume conditions, checked 2026-10-18.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.postgresql.org/docs/18/backup-file.html"&gt;PostgreSQL filesystem backup&lt;/a&gt;, consistent snapshot scope, WAL and multi-volume recovery requirements, checked 2026-10-18.&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item></channel></rss>