<?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/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>LVM | A DevOps Blog</title><link>https://blog.bsdserver.nl/tag/lvm/</link><description>Hands-on DevOps and homelab content: Kubernetes clusters, self-hosted services, CI/CD pipelines and infrastructure as code, by Patrick de Ruiter of We Build Your Cloud.</description><language>en</language><image><url>https://blog.bsdserver.nl/images/app-icon.svg</url><title>A DevOps Blog</title><link>https://blog.bsdserver.nl/</link></image><lastBuildDate>Wed, 18 Nov 2026 09:00:00 +0100</lastBuildDate><atom:link href="https://blog.bsdserver.nl/tag/lvm/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title>Mastering Physical Volumes and Volume groups</title><link>https://blog.bsdserver.nl/mastering-physical-volumes-and-volume-groups/</link><guid isPermaLink="false">6a5fb25718bfa60001dd6cbc</guid><dc:creator>Patrick de Ruiter</dc:creator><pubDate>Tue, 21 Jul 2026 17:56:44 +0000</pubDate><description>Running out of space on your Linux VM?</description><category>Linux</category><category>LVM</category><category>Storage</category><category>Sysadmin</category><media:content url="https://blog.bsdserver.nl/content/images/2026/07/mastering-lvm-1.png" medium="image"/><content:encoded><![CDATA[<p>Running out of space on your Linux VM? LVM (Logical Volume Manager) and VMware vSphere make disk resizing straightforward, even when an entire unpartitioned disk is part of a volume group.</p>
<p>This post covers the everyday physical volume (PV) and volume group (VG) tasks: growing a disk, adding one, migrating data to a new disk, backing up VG metadata, and moving, cloning, splitting and checking volume groups. Each scenario says when you need it, then shows the commands.</p>
<h2 id="which-scenario-do-you-need">Which scenario do you need? <a class="anchor" data-pagefind-ignore href="#which-scenario-do-you-need" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Scenario</th>
					<th>Use it when</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><a href="#resizing-an-lvm-disk-in-vsphere">Resize a whole-disk PV</a></td>
					<td>You made a VMDK bigger and the PV sits on the raw disk.</td>
			</tr>
			<tr>
					<td><a href="#scenario-expanding-a-partition-backed-pv-with-parted">Resize a partition-backed PV</a></td>
					<td>You made a VMDK bigger and the PV sits on a partition (<code>sdb1</code>).</td>
			</tr>
			<tr>
					<td><a href="#scenario-adding-a-larger-pv-and-migrating-data">Add a larger PV and migrate data</a></td>
					<td>You want to replace old disks with one new disk, online.</td>
			</tr>
			<tr>
					<td><a href="#scenario-backing-up-and-restoring-volume-group-configuration">Back up and restore VG metadata</a></td>
					<td>Before risky changes, or to undo an accidental one.</td>
			</tr>
			<tr>
					<td><a href="#scenario-moving-lvm-pvs-from-one-machine-to-another">Move PVs to another machine</a></td>
					<td>LUNs or disks move to a different server.</td>
			</tr>
			<tr>
					<td><a href="#scenario-using-vgimportclone-for-cloned-volume-groups">vgimportclone</a></td>
					<td>A cloned disk has the same VG name and UUIDs as the original.</td>
			</tr>
			<tr>
					<td><a href="#scenario-using-vgimportdevices-for-importing-volume-groups-from-specific-devices">vgimportdevices</a></td>
					<td>The system uses the LVM devices file and must use a VG&rsquo;s disks.</td>
			</tr>
			<tr>
					<td><a href="#scenario-splitting-a-volume-group-with-vgsplit">vgsplit</a></td>
					<td>Some LVs should become their own VG.</td>
			</tr>
			<tr>
					<td><a href="#scenario-checking-volume-group-metadata-with-vgck">vgck</a></td>
					<td>You suspect damaged VG metadata.</td>
			</tr>
	</tbody>
</table>
<h2 id="whole-disk-or-partition-as-pv">Whole disk or partition as PV? <a class="anchor" data-pagefind-ignore href="#whole-disk-or-partition-as-pv" aria-label="Link to this section">#</a></h2>
<p>You can add either a partition or an entire disk to a VG. Adding the unpartitioned disk skips the partitioning step entirely, which makes growing it simpler.</p>
<table>
	<thead>
			<tr>
					<th></th>
					<th>Whole disk (<code>/dev/sdb</code>)</th>
					<th>Partition (<code>/dev/sdb1</code>)</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Growing</td>
					<td>Rescan + <code>pvresize</code></td>
					<td>Rescan + grow partition + <code>pvresize</code></td>
			</tr>
			<tr>
					<td>Space use</td>
					<td>Whole disk, no partition boundaries</td>
					<td>Up to the partition end</td>
			</tr>
			<tr>
					<td>Portability</td>
					<td>Other systems and tools may not recognise a disk without a partition table</td>
					<td>Recognised everywhere</td>
			</tr>
			<tr>
					<td>Backup/recovery tools</td>
					<td>May expect a partition table</td>
					<td>Work as expected</td>
			</tr>
			<tr>
					<td>OS disk</td>
					<td>Not usable, data disks only</td>
					<td>Usable</td>
			</tr>
	</tbody>
</table>
<h3 id="when-to-use-which">When to use which <a class="anchor" data-pagefind-ignore href="#when-to-use-which" aria-label="Link to this section">#</a></h3>
<ul>
<li><strong>Whole disk</strong>: data disks used only by LVM on servers. Fewest steps.</li>
<li><strong>Partition</strong>: OS disks, or disks shared between purposes or environments.</li>
</ul>
<h2 id="resizing-an-lvm-disk-in-vsphere">Resizing an LVM disk in vSphere <a class="anchor" data-pagefind-ignore href="#resizing-an-lvm-disk-in-vsphere" aria-label="Link to this section">#</a></h2>
<p>The PV sits on the whole disk. After growing the VMDK, Linux and LVM each need to be told about the new size.</p>
<p>The flow: grow VMDK → rescan → <code>pvresize</code> → VG has free space → <code>lvresize -r</code> or <code>lvcreate</code>.</p>
<h3 id="step-1-resize-the-disk-in-vsphere">Step 1: Resize the disk in vSphere <a class="anchor" data-pagefind-ignore href="#step-1-resize-the-disk-in-vsphere" aria-label="Link to this section">#</a></h3>
<p>Increase the size of the disk in the VMware interface:</p>
<ol>
<li>Log in to the vSphere client or vCenter.</li>
<li>Locate the VM you want to resize.</li>
<li>Edit the VM settings and increase the size of the existing virtual disk (e.g., from 100GB to 200GB).</li>
<li>Save your changes.</li>
</ol>
<p>The VM now has a larger disk, but the operating system still needs to recognise and use the new space.</p>
<h3 id="step-2-rescan-the-disk-in-the-vm">Step 2: Rescan the disk in the VM <a class="anchor" data-pagefind-ignore href="#step-2-rescan-the-disk-in-the-vm" aria-label="Link to this section">#</a></h3>
<p>A SCSI rescan makes the kernel re-read the disk size, without a reboot:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="m">1</span> &gt; /sys/class/scsi_device/0:0:0:0/device/rescan
</span></span></code></pre></div><p>Replace <code>0:0:0:0</code> with the identifier (host:channel:target:LUN) of your disk. List them with:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ls /sys/class/scsi_device/
</span></span></code></pre></div><h3 id="step-3-verify-the-disk-size">Step 3: Verify the disk size <a class="anchor" data-pagefind-ignore href="#step-3-verify-the-disk-size" aria-label="Link to this section">#</a></h3>
<p>Check that the VM recognises the new size:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">lsblk
</span></span></code></pre></div><p>The output should show the increased capacity for your disk (e.g., <code>/dev/sdb</code>).</p>
<h3 id="step-4-extend-the-physical-volume-pv">Step 4: Extend the physical volume (PV) <a class="anchor" data-pagefind-ignore href="#step-4-extend-the-physical-volume-pv" aria-label="Link to this section">#</a></h3>
<p><code>pvresize</code> grows the PV to the new disk size, so the VG gets the extra space:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvresize /dev/sdb
</span></span></code></pre></div><h3 id="step-5-alternative-add-a-brand-new-disk-to-the-volume-group">Step 5: (Alternative) Add a brand-new disk to the volume group <a class="anchor" data-pagefind-ignore href="#step-5-alternative-add-a-brand-new-disk-to-the-volume-group" aria-label="Link to this section">#</a></h3>
<p>If you added a completely new disk instead of growing one, <code>pvresize</code> does not apply. Initialise the new disk as a PV, then add it to the existing VG:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvcreate /dev/sdb
</span></span><span class="line"><span class="cl">vgextend &lt;vg_name&gt; /dev/sdb
</span></span></code></pre></div><h3 id="step-6-verify-the-volume-group-vg-size">Step 6: Verify the volume group (VG) size <a class="anchor" data-pagefind-ignore href="#step-6-verify-the-volume-group-vg-size" aria-label="Link to this section">#</a></h3>
<p>Check that the extra space is available in the VG:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgdisplay
</span></span></code></pre></div><p>The &ldquo;Free PE / Size&rdquo; field shows the capacity available for allocation.</p>
<h3 id="step-7-expand-your-logical-volume-lv">Step 7: Expand your logical volume (LV) <a class="anchor" data-pagefind-ignore href="#step-7-expand-your-logical-volume-lv" aria-label="Link to this section">#</a></h3>
<p>Use the new space for a new LV, or grow an existing one.</p>
<table>
	<thead>
			<tr>
					<th>Option</th>
					<th>Use it for</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>lvcreate</code> + <code>mkfs</code></td>
					<td>A new filesystem, e.g. a separate mount for data.</td>
			</tr>
			<tr>
					<td><code>lvresize -r</code></td>
					<td>Growing an existing LV and its filesystem in one step.</td>
			</tr>
	</tbody>
</table>
<p><strong>Create a new LV</strong>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">lvcreate -L 100G -n new_lv my_volume_group
</span></span><span class="line"><span class="cl">mkfs.ext4 /dev/my_volume_group/new_lv  <span class="c1"># Formatting with a filesystem</span>
</span></span></code></pre></div><p><strong>Extend an existing LV</strong> (<code>-r</code> resizes the filesystem as well):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">lvresize -r -L +100G /dev/my_volume_group/my_logical_volume  <span class="c1"># The -r switch automatically resizes the filesystem</span>
</span></span></code></pre></div><h2 id="scenario-expanding-a-partition-backed-pv-with-parted">Scenario: Expanding a partition-backed PV with parted <a class="anchor" data-pagefind-ignore href="#scenario-expanding-a-partition-backed-pv-with-parted" aria-label="Link to this section">#</a></h2>
<p>When the PV sits on a partition such as <code>/dev/sdb1</code>, growing the disk is not enough. LVM can only use the space that the partition exposes, so the partition must grow first.</p>
<ul>
<li>Modern kernels support growing a partition while it is in use, so this also works online without a reboot.</li>
<li>The flow: rescan → <code>parted resizepart</code> → <code>partprobe</code> (if needed) → <code>pvresize /dev/sdb1</code>.</li>
</ul>
<h3 id="step-1-rescan-and-verify-the-new-disk-size">Step 1: Rescan and verify the new disk size <a class="anchor" data-pagefind-ignore href="#step-1-rescan-and-verify-the-new-disk-size" aria-label="Link to this section">#</a></h3>
<p>Rescan the disk exactly as in steps 2 and 3 above. <code>lsblk</code> then shows the mismatch to fix:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">lsblk
</span></span><span class="line"><span class="cl">NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
</span></span><span class="line"><span class="cl">sdb      8:16   <span class="m">0</span>  200G  <span class="m">0</span> disk
</span></span><span class="line"><span class="cl">└─sdb1   8:17   <span class="m">0</span>  100G  <span class="m">0</span> part
</span></span></code></pre></div><p>The disk (<code>sdb</code>) is 200GB, but the partition (<code>sdb1</code>) is still 100GB.</p>
<h3 id="step-2-grow-the-partition-with-parted">Step 2: Grow the partition with parted <a class="anchor" data-pagefind-ignore href="#step-2-grow-the-partition-with-parted" aria-label="Link to this section">#</a></h3>
<p>Start <code>parted</code> on the disk (not the partition):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">parted /dev/sdb
</span></span><span class="line"><span class="cl"><span class="o">(</span>parted<span class="o">)</span> print
</span></span></code></pre></div><p>If the disk uses GPT, <code>parted</code> may warn that not all of the disk space is in use and offer to fix it. Answer <code>Fix</code>: this moves the backup GPT header to the new end of the disk, which is required before you can extend the partition.</p>
<p>Now resize the partition. <code>resizepart</code> takes the partition number and the new end; <code>100%</code> means &ldquo;up to the end of the disk&rdquo;:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="o">(</span>parted<span class="o">)</span> resizepart <span class="m">1</span> 100%
</span></span><span class="line"><span class="cl"><span class="o">(</span>parted<span class="o">)</span> quit
</span></span></code></pre></div><ul>
<li>Older <code>parted</code> releases ask for confirmation when the partition is in use; answer <code>Yes</code>. Current versions (parted 3.6 on Ubuntu 24.04) grow an in-use partition without asking.</li>
<li>Growing is safe while online: the start of the partition does not move, so the data on it is untouched.</li>
</ul>
<blockquote>
<p><strong>Tip:</strong> If you have <code>cloud-utils</code> installed, <code>growpart /dev/sdb 1</code> does the same thing in a single non-interactive command, which is handy for automation with Ansible or cloud-init.</p>
</blockquote>
<h3 id="step-3-let-the-kernel-re-read-the-partition-table">Step 3: Let the kernel re-read the partition table <a class="anchor" data-pagefind-ignore href="#step-3-let-the-kernel-re-read-the-partition-table" aria-label="Link to this section">#</a></h3>
<p><code>parted</code> usually informs the kernel automatically. If <code>lsblk</code> still shows the old size, force a re-read:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">partprobe /dev/sdb
</span></span></code></pre></div><p><code>lsblk</code> should now show <code>sdb1</code> at the full 200GB.</p>
<h3 id="step-4-resize-the-physical-volume">Step 4: Resize the physical volume <a class="anchor" data-pagefind-ignore href="#step-4-resize-the-physical-volume" aria-label="Link to this section">#</a></h3>
<p>Tell LVM to claim the new space in the partition:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvresize /dev/sdb1
</span></span></code></pre></div><p>Verify with <code>pvs</code> or <code>vgdisplay</code>: the &ldquo;Free PE / Size&rdquo; of the VG should have grown. Extend your LV as in Step 7 above with <code>lvresize -r</code>.</p>
<h2 id="scenario-adding-a-larger-pv-and-migrating-data">Scenario: Adding a larger PV and migrating data <a class="anchor" data-pagefind-ignore href="#scenario-adding-a-larger-pv-and-migrating-data" aria-label="Link to this section">#</a></h2>
<p><code>pvmove</code> moves the data from old PVs to a new one while the LVs stay in use. Use it to replace several small disks with one large disk, or to retire old disks.</p>
<p>The setup:</p>
<ul>
<li>Two existing PVs (PV1 and PV2), e.g. 100GB each.</li>
<li>A new PV (PV3), larger than PV1 and PV2 together, e.g. 250GB.</li>
<li>Goal: move all data to PV3, then remove PV1 and PV2 from the VG.</li>
</ul>
<p>The flow: <code>pvcreate</code> → <code>vgextend</code> → <code>pvmove</code> (per old PV) → <code>vgreduce</code> → <code>pvremove</code>.</p>
<h3 id="step-1-add-the-new-physical-volume">Step 1: Add the new physical volume <a class="anchor" data-pagefind-ignore href="#step-1-add-the-new-physical-volume" aria-label="Link to this section">#</a></h3>
<p>Add the new disk in vSphere and make it available to your VM. Initialise it as a PV:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvcreate /dev/sdc  <span class="c1"># Assuming the new disk is /dev/sdc</span>
</span></span></code></pre></div><p>Add it to the volume group:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgextend my_volume_group /dev/sdc
</span></span></code></pre></div><h3 id="step-2-migrate-data-to-the-new-physical-volume">Step 2: Migrate data to the new physical volume <a class="anchor" data-pagefind-ignore href="#step-2-migrate-data-to-the-new-physical-volume" aria-label="Link to this section">#</a></h3>
<p><code>pvmove</code> moves all extents from the first PV to the second. It runs online; the LVs stay mounted:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvmove /dev/sdb /dev/sdc
</span></span><span class="line"><span class="cl">pvmove /dev/sda /dev/sdc
</span></span></code></pre></div><p>This moves all extents from <code>/dev/sdb</code> and <code>/dev/sda</code> (the smaller PVs) to <code>/dev/sdc</code> (the new, larger PV).</p>
<h3 id="step-3-verify-the-migration">Step 3: Verify the migration <a class="anchor" data-pagefind-ignore href="#step-3-verify-the-migration" aria-label="Link to this section">#</a></h3>
<p>Check where the extents are now:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvs
</span></span></code></pre></div><p><code>/dev/sdc</code> should now hold all the extents; <code>/dev/sda</code> and <code>/dev/sdb</code> should be empty (PFree equals PSize).</p>
<h3 id="step-4-remove-the-old-physical-volumes">Step 4: Remove the old physical volumes <a class="anchor" data-pagefind-ignore href="#step-4-remove-the-old-physical-volumes" aria-label="Link to this section">#</a></h3>
<p><code>vgreduce</code> removes the empty PVs from the volume group:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgreduce my_volume_group /dev/sda
</span></span><span class="line"><span class="cl">vgreduce my_volume_group /dev/sdb
</span></span></code></pre></div><p><code>pvremove</code> then wipes the LVM label, if you no longer need the disks:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvremove /dev/sda
</span></span><span class="line"><span class="cl">pvremove /dev/sdb
</span></span></code></pre></div><h2 id="scenario-backing-up-and-restoring-volume-group-configuration">Scenario: Backing up and restoring volume group configuration <a class="anchor" data-pagefind-ignore href="#scenario-backing-up-and-restoring-volume-group-configuration" aria-label="Link to this section">#</a></h2>
<p>VG metadata describes which extents belong to which LV. Back it up before significant changes, such as moving PVs between machines or migrations.</p>
<table>
	<thead>
			<tr>
					<th>Command</th>
					<th>What it does</th>
					<th>When</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>vgcfgrestore</code></td>
					<td>Writes saved metadata back to the PVs</td>
					<td>Metadata damaged, or an unintended change (e.g. <code>lvremove</code>)</td>
			</tr>
			<tr>
					<td><code>vgcfgbackup</code></td>
					<td>Saves the current metadata to a file</td>
					<td>Before major changes</td>
			</tr>
	</tbody>
</table>
<h3 id="restoring-with-vgcfgrestore">Restoring with vgcfgrestore <a class="anchor" data-pagefind-ignore href="#restoring-with-vgcfgrestore" aria-label="Link to this section">#</a></h3>
<p>Deactivate the LVs first, then restore the VG&rsquo;s metadata from its backup file. With active LVs, <code>vgcfgrestore</code> refuses to continue unless you confirm:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgchange -an my_volume_group
</span></span><span class="line"><span class="cl">vgcfgrestore my_volume_group
</span></span></code></pre></div><p>LVM rewrites <code>/etc/lvm/backup/my_volume_group</code> automatically after every metadata change. After an unintended change, that file already contains the new state. Earlier versions are kept in <code>/etc/lvm/archive/</code>: list them and restore the one taken <em>before</em> the change:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgcfgrestore --list my_volume_group
</span></span><span class="line"><span class="cl">vgcfgrestore -f /etc/lvm/archive/my_volume_group_00011-1234567890.vg my_volume_group
</span></span></code></pre></div><h3 id="backing-up-with-vgcfgbackup">Backing up with vgcfgbackup <a class="anchor" data-pagefind-ignore href="#backing-up-with-vgcfgbackup" aria-label="Link to this section">#</a></h3>
<p><code>vgcfgbackup</code> saves the VG&rsquo;s metadata: its structure and the LVs in it. Run it before resizing, migration or removing PVs:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgcfgbackup my_volume_group
</span></span></code></pre></div><p>By default, this creates a backup file in <code>/etc/lvm/backup/</code>. You can also specify a custom path.</p>
<h3 id="best-practices">Best practices <a class="anchor" data-pagefind-ignore href="#best-practices" aria-label="Link to this section">#</a></h3>
<ul>
<li><strong>Back up before major changes</strong>: run <code>vgcfgbackup</code> before <code>pvmove</code>, <code>vgreduce</code> or even adding new PVs.</li>
<li><strong>Store backups off the machine</strong>: a backup on the failed disk does not help.</li>
<li><strong>Test restores</strong>: practise <code>vgcfgrestore</code> in a test environment before you need it in production.</li>
</ul>
<h2 id="scenario-moving-lvm-pvs-from-one-machine-to-another">Scenario: Moving LVM PVs from one machine to another <a class="anchor" data-pagefind-ignore href="#scenario-moving-lvm-pvs-from-one-machine-to-another" aria-label="Link to this section">#</a></h2>
<p>A VG can move to another server with its disks, for example two PVs on iSCSI LUNs. You export the VG on the old server and import it on the new one.</p>
<p>The flow: <code>umount</code> → <code>vgchange -an</code> → <code>vgexport</code> → move LUNs → <code>vgimport</code> → <code>vgchange -ay</code> → <code>mount</code>.</p>
<h3 id="step-1-unmount-the-logical-volumes">Step 1: Unmount the logical volumes <a class="anchor" data-pagefind-ignore href="#step-1-unmount-the-logical-volumes" aria-label="Link to this section">#</a></h3>
<p>Unmount every filesystem on the VG&rsquo;s logical volumes:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">umount /mnt/my_logical_volume
</span></span></code></pre></div><p>Repeat this for each mounted LV.</p>
<h3 id="step-2-deactivate-the-volume-group">Step 2: Deactivate the volume group <a class="anchor" data-pagefind-ignore href="#step-2-deactivate-the-volume-group" aria-label="Link to this section">#</a></h3>
<p>Deactivating removes the LV devices, so nothing can write to them during the move:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgchange -an my_volume_group
</span></span></code></pre></div><h3 id="step-3-export-the-volume-group">Step 3: Export the volume group <a class="anchor" data-pagefind-ignore href="#step-3-export-the-volume-group" aria-label="Link to this section">#</a></h3>
<p><code>vgexport</code> marks the VG as exported, so the old server no longer uses it and the destination can import it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgexport my_volume_group
</span></span></code></pre></div><h3 id="step-4-move-the-iscsi-luns-to-the-destination-machine">Step 4: Move the iSCSI LUNs to the destination machine <a class="anchor" data-pagefind-ignore href="#step-4-move-the-iscsi-luns-to-the-destination-machine" aria-label="Link to this section">#</a></h3>
<p>Connect the destination machine to the iSCSI LUNs that hold the PVs. This depends on your iSCSI setup, but typically means logging in to the iSCSI target from the destination. See <a href="https://blog.bsdserver.nl/automating-iscsi-initiator-configuration-with-ansible/">Automating iSCSI Initiator Configuration with Ansible</a>.</p>
<h3 id="step-5-import-the-volume-group-on-the-destination-machine">Step 5: Import the volume group on the destination machine <a class="anchor" data-pagefind-ignore href="#step-5-import-the-volume-group-on-the-destination-machine" aria-label="Link to this section">#</a></h3>
<p>Once the LUNs are connected, import the VG:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgimport my_volume_group
</span></span></code></pre></div><h3 id="step-6-activate-the-volume-group">Step 6: Activate the volume group <a class="anchor" data-pagefind-ignore href="#step-6-activate-the-volume-group" aria-label="Link to this section">#</a></h3>
<p>Activation makes the LV devices available:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgchange -ay my_volume_group
</span></span></code></pre></div><h3 id="step-7-mount-the-logical-volumes">Step 7: Mount the logical volumes <a class="anchor" data-pagefind-ignore href="#step-7-mount-the-logical-volumes" aria-label="Link to this section">#</a></h3>
<p>Mount the LVs on their mount points:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">mount /dev/my_volume_group/my_logical_volume /mnt/my_logical_volume
</span></span></code></pre></div><p>Repeat this for each LV. Add them to <code>/etc/fstab</code> on the new server if they must mount at boot.</p>
<h2 id="scenario-using-vgimportclone-for-cloned-volume-groups">Scenario: Using vgimportclone for cloned volume groups <a class="anchor" data-pagefind-ignore href="#scenario-using-vgimportclone-for-cloned-volume-groups" aria-label="Link to this section">#</a></h2>
<p>A cloned disk (a storage snapshot or a copied VMDK) has the same VG name and UUIDs as the original. When both are visible on one system, LVM cannot tell them apart. <code>vgimportclone</code> gives the clone new UUIDs and a new name.</p>
<h3 id="step-1-attach-the-cloned-disk">Step 1: Attach the cloned disk <a class="anchor" data-pagefind-ignore href="#step-1-attach-the-cloned-disk" aria-label="Link to this section">#</a></h3>
<p>Attach the cloned disk to the destination machine and check that the operating system recognises it.</p>
<h3 id="step-2-use-vgimportclone">Step 2: Use vgimportclone <a class="anchor" data-pagefind-ignore href="#step-2-use-vgimportclone" aria-label="Link to this section">#</a></h3>
<p>Import the cloned VG under a new name:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgimportclone -n new_volume_group_name /dev/sdX
</span></span></code></pre></div><p>Replace <code>/dev/sdX</code> with the cloned disk and <code>new_volume_group_name</code> with the new VG name.</p>
<h2 id="scenario-using-vgimportdevices-for-importing-volume-groups-from-specific-devices">Scenario: Using vgimportdevices for importing volume groups from specific devices <a class="anchor" data-pagefind-ignore href="#scenario-using-vgimportdevices-for-importing-volume-groups-from-specific-devices" aria-label="Link to this section">#</a></h2>
<p>On systems that use the LVM devices file (<code>/etc/lvm/devices/system.devices</code>, enabled by default on RHEL 9), LVM ignores every device that is not listed in it. <code>vgimportdevices</code> adds the devices of a volume group to that file.</p>
<p>Use it when:</p>
<ul>
<li>A system has multiple disks with different VGs.</li>
<li>LVM should only use the devices of the VGs you choose, to avoid conflicts with other setups.</li>
</ul>
<h3 id="step-1-list-available-devices">Step 1: List available devices <a class="anchor" data-pagefind-ignore href="#step-1-list-available-devices" aria-label="Link to this section">#</a></h3>
<p>See which PVs exist and which VG each belongs to:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvs
</span></span></code></pre></div><h3 id="step-2-import-the-volume-groups-devices">Step 2: Import the volume group&rsquo;s devices <a class="anchor" data-pagefind-ignore href="#step-2-import-the-volume-groups-devices" aria-label="Link to this section">#</a></h3>
<p><code>vgimportdevices</code> takes VG names, not device names, and adds all PVs of that VG to the devices file:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgimportdevices my_volume_group
</span></span><span class="line"><span class="cl">lvmdevices
</span></span></code></pre></div><ul>
<li><code>lvmdevices</code> shows the resulting list.</li>
<li>Passing device paths (<code>vgimportdevices my_volume_group /dev/sdX</code>) fails with <code>Volume group &quot;sdX&quot; not found</code>.</li>
<li>On Debian and Ubuntu the command is only available as <code>lvm vgimportdevices</code>, and the devices file is disabled there by default (<code>use_devicesfile = 0</code>).</li>
</ul>
<h2 id="scenario-splitting-a-volume-group-with-vgsplit">Scenario: Splitting a volume group with vgsplit <a class="anchor" data-pagefind-ignore href="#scenario-splitting-a-volume-group-with-vgsplit" aria-label="Link to this section">#</a></h2>
<p><code>vgsplit</code> moves part of a VG into a new VG. Use it to prepare some LVs for a move to another machine, or when reorganising storage.</p>
<ul>
<li><code>vgsplit</code> moves whole PVs, so the LVs you split off must live on PVs of their own.</li>
<li>The LVs that move must be inactive.</li>
</ul>
<h3 id="step-1-verify-volume-group-and-logical-volumes">Step 1: Verify volume group and logical volumes <a class="anchor" data-pagefind-ignore href="#step-1-verify-volume-group-and-logical-volumes" aria-label="Link to this section">#</a></h3>
<p>Check the structure of the VG and list all LVs:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgdisplay my_volume_group
</span></span><span class="line"><span class="cl">lvdisplay
</span></span></code></pre></div><h3 id="step-2-split-the-volume-group">Step 2: Split the volume group <a class="anchor" data-pagefind-ignore href="#step-2-split-the-volume-group" aria-label="Link to this section">#</a></h3>
<p>Deactivate the LVs you want to move, then create a new VG from the PV(s) that hold them:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">lvchange -an my_volume_group/lv_name1 my_volume_group/lv_name2
</span></span><span class="line"><span class="cl">vgsplit my_volume_group new_volume_group /dev/sdX
</span></span></code></pre></div><p>Alternatively, name one LV and let <code>vgsplit</code> move the PVs it lives on. Any other LV on those PVs moves along with it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgsplit -n lv_name1 my_volume_group new_volume_group
</span></span></code></pre></div><ul>
<li>Replace <code>new_volume_group</code> with the new VG name, <code>/dev/sdX</code> with the PV that holds the LVs, and <code>lv_name1</code>, <code>lv_name2</code> with the LVs you want to move.</li>
<li>Listing LV names as plain arguments does not work: <code>vgsplit</code> treats them as PV names and fails with <code>Physical volume lv_name1 not in volume group my_volume_group</code>.</li>
</ul>
<h3 id="step-3-verify-the-split">Step 3: Verify the split <a class="anchor" data-pagefind-ignore href="#step-3-verify-the-split" aria-label="Link to this section">#</a></h3>
<p>Check that both VGs exist and contain the expected LVs:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgdisplay
</span></span></code></pre></div><h2 id="scenario-checking-volume-group-metadata-with-vgck">Scenario: Checking volume group metadata with vgck <a class="anchor" data-pagefind-ignore href="#scenario-checking-volume-group-metadata-with-vgck" aria-label="Link to this section">#</a></h2>
<p><code>vgck</code> checks the consistency of the VG metadata. Use it when you suspect corruption, for example after a crash.</p>
<h3 id="step-1-run-vgck-on-the-volume-group">Step 1: Run vgck on the volume group <a class="anchor" data-pagefind-ignore href="#step-1-run-vgck-on-the-volume-group" aria-label="Link to this section">#</a></h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vgck my_volume_group
</span></span></code></pre></div><p>Replace <code>my_volume_group</code> with the name of the VG to check.</p>
<h3 id="step-2-review-the-output">Step 2: Review the output <a class="anchor" data-pagefind-ignore href="#step-2-review-the-output" aria-label="Link to this section">#</a></h3>
<p><code>vgck</code> reports any inconsistencies it finds. If it finds problems, you may need <code>vgcfgrestore</code> (see above) or manual repair.</p>
<h3 id="when-to-use-vgck">When to use vgck <a class="anchor" data-pagefind-ignore href="#when-to-use-vgck" aria-label="Link to this section">#</a></h3>
<ul>
<li><strong>After a system crash</strong> or abrupt shutdown: check that the VG metadata is not corrupted.</li>
<li><strong>Before major operations</strong> like <code>pvmove</code> or <code>vgreduce</code>: make sure the VG is healthy first.</li>
</ul>
<h2 id="best-practices-for-disk-resizing-and-migration-in-vsphere">Best practices for disk resizing and migration in vSphere <a class="anchor" data-pagefind-ignore href="#best-practices-for-disk-resizing-and-migration-in-vsphere" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>Backup before operations</strong>: always have a recent backup before resizing or migrating data.</li>
<li><strong>Monitor performance</strong>: <code>pvmove</code> is I/O-intensive. Watch disk I/O and system performance, especially in production.</li>
<li><strong>Plan for slowdown</strong>: <code>pvmove</code> runs online, but expect reduced performance during the migration.</li>
</ul>
<h2 id="automate-it">Automate it <a class="anchor" data-pagefind-ignore href="#automate-it" aria-label="Link to this section">#</a></h2>
<p>The Ansible roles and Terraform code that build this setup are on GitHub: <a href="https://github.com/pderuiter/blog-lvm-pv-vg" rel="noopener">pderuiter/blog-lvm-pv-vg</a>. It creates a VM with three spare disks on Proxmox and automates the resize (rescan, growpart, pvresize), add-a-disk and pvmove migration scenarios, followed by <code>lvresize -r</code>; run <code>terraform apply</code> and then <code>ansible-playbook site.yml</code>.</p>
<h2 id="conclusion">Conclusion <a class="anchor" data-pagefind-ignore href="#conclusion" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>Whole-disk PVs</strong> are the simplest to grow: rescan and <code>pvresize</code>. Partitions add a <code>parted</code> or <code>growpart</code> step but are more portable.</li>
<li><strong><code>pvmove</code></strong> replaces disks online.</li>
<li><strong><code>vgexport</code> / <code>vgimport</code></strong> move a VG with its LUNs to another server; <code>vgimportclone</code> handles clones.</li>
<li><strong><code>vgcfgbackup</code>, <code>vgcfgrestore</code> and <code>vgck</code></strong> protect and check the metadata.</li>
</ul>
<p>For the basic add-a-disk procedure, see <a href="https://blog.bsdserver.nl/expanding-disk-space-on-lvm-a-step-by-step-guide/">Expanding Disk Space on LVM: A Step-by-Step Guide</a>.</p>
]]></content:encoded></item><item><title>Expand Disk Space on a VMware Linux VM Without Rebooting</title><link>https://blog.bsdserver.nl/expand-disk-space-on-a-vmware-linux-vm-without-rebooting/</link><guid isPermaLink="false">6981fa80bacee50001395b21</guid><dc:creator>Patrick de Ruiter</dc:creator><pubDate>Tue, 03 Feb 2026 13:50:38 +0000</pubDate><description>Say goodbye to downtime when you need more storage Running out of disk space on a production VM is stressful enough without the added headache of…</description><category>Linux</category><category>VMware</category><category>LVM</category><category>Sysadmin</category><media:content url="https://blog.bsdserver.nl/content/images/2026/02/resize-lvm-vmware.png" medium="image"/><content:encoded><![CDATA[<p>Running out of disk space on a production VM is stressful enough without scheduling a reboot as well. On VMware you can grow the virtual disk while the VM runs, but Linux keeps showing the old size.</p>
<p>This post walks through the whole process without a reboot: expand the VMDK in vSphere, make Linux recognise the new size, then grow the partition, LVM and filesystem.</p>
<h2 id="why-rescan-instead-of-reboot">Why rescan instead of reboot? <a class="anchor" data-pagefind-ignore href="#why-rescan-instead-of-reboot" aria-label="Link to this section">#</a></h2>
<p>When you grow a virtual disk, the hypervisor knows the new size immediately. The Linux guest does not: it still uses the size it read when the SCSI device was detected. A reboot re-reads it, but means downtime.</p>
<p>A SCSI rescan through <code>/sys</code> makes the kernel re-read the size of a running disk:</p>
<ul>
<li><strong>No downtime</strong>: the filesystem stays mounted and in use</li>
<li><strong>Seconds, not a maintenance window</strong></li>
<li><strong>Works for new disks too</strong>: a host rescan finds hot-added disks</li>
</ul>
<h3 id="when-to-use-it">When to use it <a class="anchor" data-pagefind-ignore href="#when-to-use-it" aria-label="Link to this section">#</a></h3>
<ul>
<li><strong>Use it</strong> to grow an existing disk or hot-add a new one on a running Linux VM.</li>
<li><strong>Skip it</strong> for shrinking. That needs different steps and carries more risk.</li>
</ul>
<h3 id="which-rescan">Which rescan? <a class="anchor" data-pagefind-ignore href="#which-rescan" aria-label="Link to this section">#</a></h3>
<table>
	<thead>
			<tr>
					<th>Situation</th>
					<th>What to rescan</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>You made an existing VMDK bigger</td>
					<td>The block device: <code>/sys/block/sdX/device/rescan</code></td>
			</tr>
			<tr>
					<td>You hot-added a new disk</td>
					<td>The SCSI host adapter: <code>/sys/class/scsi_host/hostN/scan</code></td>
			</tr>
	</tbody>
</table>
<h2 id="how-it-works">How it works <a class="anchor" data-pagefind-ignore href="#how-it-works" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Layer</th>
					<th>Tool</th>
					<th>Job</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Virtual disk (VMDK)</td>
					<td>vSphere Client</td>
					<td>Makes the disk bigger.</td>
			</tr>
			<tr>
					<td>Block device (<code>sda</code>)</td>
					<td><code>/sys</code> rescan</td>
					<td>Makes the kernel see the new size.</td>
			</tr>
			<tr>
					<td>Partition (<code>sda2</code>)</td>
					<td><code>growpart</code></td>
					<td>Grows the partition into the new space.</td>
			</tr>
			<tr>
					<td>LVM (if used)</td>
					<td><code>pvresize</code>, <code>lvextend</code></td>
					<td>Grows the PV, then the LV.</td>
			</tr>
			<tr>
					<td>Filesystem</td>
					<td><code>resize2fs</code> / <code>xfs_growfs</code></td>
					<td>Grows the filesystem into the bigger LV or partition.</td>
			</tr>
	</tbody>
</table>
<p>The flow: grow VMDK → rescan <code>sda</code> → <code>growpart</code> → <code>pvresize</code> → <code>lvextend</code> → <code>resize2fs</code> or <code>xfs_growfs</code> → <code>df -h</code> shows the space.</p>
<h2 id="the-scsi-rescan">The SCSI rescan <a class="anchor" data-pagefind-ignore href="#the-scsi-rescan" aria-label="Link to this section">#</a></h2>
<p>Linux lets you force the kernel to re-read disk information through the <code>/sys</code> filesystem. There are two scenarios.</p>
<h3 id="scenario-1-resizing-an-existing-disk">Scenario 1: Resizing an existing disk <a class="anchor" data-pagefind-ignore href="#scenario-1-resizing-an-existing-disk" aria-label="Link to this section">#</a></h3>
<p>After expanding an existing VMDK, tell that block device to refresh its size:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="m">1</span> &gt; /sys/block/sda/device/rescan
</span></span></code></pre></div><ul>
<li>Replace <code>sda</code> with your actual device name (e.g., <code>sdb</code>, <code>sdc</code>).</li>
<li>The kernel re-reads where the disk ends and updates its size.</li>
</ul>
<p>Run these commands from a root shell (<code>sudo -i</code>):</p>
<ul>
<li><code>sudo echo 1 &gt; /sys/block/sda/device/rescan</code> fails with &ldquo;Permission denied&rdquo;: the redirect is done by your own, unprivileged shell.</li>
<li>Use <code>echo 1 | sudo tee /sys/block/sda/device/rescan</code> instead.</li>
</ul>
<h3 id="scenario-2-adding-a-new-disk">Scenario 2: Adding a new disk <a class="anchor" data-pagefind-ignore href="#scenario-2-adding-a-new-disk" aria-label="Link to this section">#</a></h3>
<p>After hot-adding a completely new disk, scan the SCSI host adapter for new devices:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s2">&#34;- - -&#34;</span> &gt; /sys/class/scsi_host/host0/scan
</span></span></code></pre></div><p>The three dashes are wildcards for channel, target and LUN. Not sure which <code>hostN</code> the disk is on? Scan all adapters at once:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s2">&#34;- - -&#34;</span> <span class="p">|</span> tee /sys/class/scsi_host/*/scan
</span></span></code></pre></div><h2 id="step-by-step-expanding-an-existing-disk">Step-by-step: expanding an existing disk <a class="anchor" data-pagefind-ignore href="#step-by-step-expanding-an-existing-disk" aria-label="Link to this section">#</a></h2>
<p>The complete workflow for growing an existing disk on a running Linux VM.</p>
<h3 id="step-1-expand-the-vmdk-in-vsphere">Step 1: Expand the VMDK in vSphere <a class="anchor" data-pagefind-ignore href="#step-1-expand-the-vmdk-in-vsphere" aria-label="Link to this section">#</a></h3>
<ol>
<li>Open the vSphere Client</li>
<li>Right-click your VM and select <strong>Edit Settings</strong></li>
<li>Find the hard disk you want to expand</li>
<li>Increase the size to your desired capacity</li>
<li>Click <strong>OK</strong></li>
</ol>
<h3 id="step-2-rescan-the-disk-in-linux">Step 2: Rescan the disk in Linux <a class="anchor" data-pagefind-ignore href="#step-2-rescan-the-disk-in-linux" aria-label="Link to this section">#</a></h3>
<p>Identify which device belongs to the disk you grew:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">lsblk
</span></span></code></pre></div><p>Trigger a rescan on that device:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="m">1</span> &gt; /sys/block/sda/device/rescan
</span></span></code></pre></div><p>Verify the new size is detected. The disk size in the header should show the new value:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">fdisk -l /dev/sda
</span></span></code></pre></div><h3 id="step-3-expand-the-partition">Step 3: Expand the partition <a class="anchor" data-pagefind-ignore href="#step-3-expand-the-partition" aria-label="Link to this section">#</a></h3>
<p>The disk is bigger, but the partition still ends where it did. <code>growpart</code> (recommended) moves the end of a partition to the end of the disk, also while it is in use:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Install growpart if needed (part of cloud-utils-growpart package)</span>
</span></span><span class="line"><span class="cl">yum install cloud-utils-growpart   <span class="c1"># RHEL/CentOS</span>
</span></span><span class="line"><span class="cl">apt install cloud-guest-utils      <span class="c1"># Debian/Ubuntu</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Grow the partition (partition 2 in this example)</span>
</span></span><span class="line"><span class="cl">growpart /dev/sda <span class="m">2</span>
</span></span></code></pre></div><ul>
<li><code>growpart /dev/sda 2</code>: disk and partition number, separated by a space.</li>
<li>Skip this step if the filesystem or PV sits directly on the disk without a partition.</li>
</ul>
<h3 id="step-4-resize-the-filesystem-or-lvm">Step 4: Resize the filesystem or LVM <a class="anchor" data-pagefind-ignore href="#step-4-resize-the-filesystem-or-lvm" aria-label="Link to this section">#</a></h3>
<p>What comes next depends on what sits on the partition:</p>
<table>
	<thead>
			<tr>
					<th>On the partition</th>
					<th>Steps</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>LVM</td>
					<td><code>pvresize</code>, <code>lvextend</code>, then grow the filesystem</td>
			</tr>
			<tr>
					<td>ext4 directly</td>
					<td><code>resize2fs /dev/sda2</code></td>
			</tr>
			<tr>
					<td>XFS directly</td>
					<td><code>xfs_growfs /mountpoint</code></td>
			</tr>
	</tbody>
</table>
<p><strong>For LVM setups</strong>, resize the physical volume first, so the volume group sees the extra space:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pvresize /dev/sda2
</span></span></code></pre></div><p>Then give all free space to your logical volume:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">lvextend -l +100%FREE /dev/mapper/vg_name-lv_name
</span></span></code></pre></div><p><strong>For ext4 filesystems</strong>, grow the filesystem into the bigger LV or partition. Works while mounted:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">resize2fs /dev/mapper/vg_name-lv_name
</span></span><span class="line"><span class="cl"><span class="c1"># Or for a direct partition:</span>
</span></span><span class="line"><span class="cl">resize2fs /dev/sda2
</span></span></code></pre></div><p><strong>For XFS filesystems</strong> (common on RHEL/CentOS 7+). <code>xfs_growfs</code> takes the mount point, not the device:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">xfs_growfs /mountpoint
</span></span></code></pre></div><h3 id="step-5-verify-the-changes">Step 5: Verify the changes <a class="anchor" data-pagefind-ignore href="#step-5-verify-the-changes" aria-label="Link to this section">#</a></h3>
<p>Confirm everything worked:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">df -h
</span></span></code></pre></div><p>The filesystem should now report the expanded size.</p>
<h2 id="quick-reference-commands">Quick reference commands <a class="anchor" data-pagefind-ignore href="#quick-reference-commands" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Task</th>
					<th>Command</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Rescan existing disk</td>
					<td><code>echo 1 &gt; /sys/block/sdX/device/rescan</code></td>
			</tr>
			<tr>
					<td>Scan for new disks</td>
					<td><code>echo &quot;- - -&quot; | tee /sys/class/scsi_host/*/scan</code></td>
			</tr>
			<tr>
					<td>Grow partition</td>
					<td><code>growpart /dev/sdX N</code></td>
			</tr>
			<tr>
					<td>Resize LVM PV</td>
					<td><code>pvresize /dev/sdXN</code></td>
			</tr>
			<tr>
					<td>Extend LV</td>
					<td><code>lvextend -l +100%FREE /dev/vg/lv</code></td>
			</tr>
			<tr>
					<td>Resize ext4</td>
					<td><code>resize2fs /dev/path</code></td>
			</tr>
			<tr>
					<td>Resize XFS</td>
					<td><code>xfs_growfs /mountpoint</code></td>
			</tr>
	</tbody>
</table>
<h2 id="troubleshooting">Troubleshooting <a class="anchor" data-pagefind-ignore href="#troubleshooting" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Symptom</th>
					<th>Cause / fix</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>Permission denied</code> on the rescan</td>
					<td><code>sudo echo ... &gt;</code> runs the redirect without root. Use a root shell or <code>tee</code>.</td>
			</tr>
			<tr>
					<td><code>lsblk</code> still shows the old size</td>
					<td>Rescanned the wrong device. Check which <code>sdX</code> you grew.</td>
			</tr>
			<tr>
					<td>New disk does not appear</td>
					<td>Scanned the wrong host adapter. Scan all with <code>/sys/class/scsi_host/*/scan</code>.</td>
			</tr>
			<tr>
					<td><code>df</code> shows the old size</td>
					<td>Filesystem not grown yet. Run <code>resize2fs</code> or <code>xfs_growfs</code>.</td>
			</tr>
	</tbody>
</table>
<h2 id="important-caveats">Important caveats <a class="anchor" data-pagefind-ignore href="#important-caveats" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>Shrinking is different</strong>: this process is for <em>expanding</em> disks only.</li>
<li><strong>Backups first</strong>: always have a backup before modifying disk structures, even if the procedure is well-tested.</li>
<li><strong>VMware Tools</strong>: ensure VMware Tools is installed and running for best results.</li>
</ul>
<h2 id="automate-it">Automate it <a class="anchor" data-pagefind-ignore href="#automate-it" aria-label="Link to this section">#</a></h2>
<p>The Ansible roles and Terraform code that build this setup are on GitHub: <a href="https://github.com/pderuiter/blog-disk-expand-online" rel="noopener">pderuiter/blog-disk-expand-online</a>. It uses a Proxmox VM instead of vSphere (the rescan works the same), puts LVM on one data disk and XFS on another, and after you grow the disks with <code>terraform apply</code> the playbook does steps 2 to 4 (rescan, growpart, pvresize/lvextend, resize2fs or xfs_growfs) without a reboot; run <code>ansible-playbook site.yml</code>.</p>
<h2 id="conclusion">Conclusion <a class="anchor" data-pagefind-ignore href="#conclusion" aria-label="Link to this section">#</a></h2>
<p>Linux caches the disk size; the <code>/sys</code> rescan forces a refresh. Combine that with VMware&rsquo;s hot-expand and you grow storage on a running VM:</p>
<ol>
<li>Grow the VMDK</li>
<li>Rescan the device</li>
<li><code>growpart</code></li>
<li><code>pvresize</code> and <code>lvextend</code> (LVM only)</li>
<li>Grow the filesystem</li>
</ol>
<p>Adding a disk instead of growing one? See <a href="https://blog.bsdserver.nl/expanding-disk-space-on-lvm-a-step-by-step-guide/">Expanding Disk Space on LVM: A Step-by-Step Guide</a>.</p>
]]></content:encoded></item><item><title>Expanding Disk Space on LVM: A Step-by-Step Guide</title><link>https://blog.bsdserver.nl/expanding-disk-space-on-lvm-a-step-by-step-guide/</link><guid isPermaLink="false">693b514779eb54000160a487</guid><dc:creator>Patrick de Ruiter</dc:creator><pubDate>Thu, 11 Dec 2025 23:18:31 +0000</pubDate><description>Sometimes the required disk space for an application or service is greater than initially anticipated.</description><category>Linux</category><category>LVM</category><category>How-to</category><media:content url="https://blog.bsdserver.nl/content/images/2026/01/lvm-step-by-step.png" medium="image"/><content:encoded><![CDATA[<p>A filesystem runs full, and the server has no free space left. With LVM you add a disk and grow the filesystem while it stays mounted: no downtime, no reboot.</p>
<p>This post adds a new disk to an existing volume group and gives the space to <code>/var</code>, in six steps. It assumes your disks already use LVM. Without LVM it is still possible, but a lot harder.</p>
<h2 id="why-lvm-for-this">Why LVM for this? <a class="anchor" data-pagefind-ignore href="#why-lvm-for-this" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>Online</strong>: the filesystem stays mounted and in use the whole time</li>
<li><strong>Any disk</strong>: the new space does not have to sit next to the old space on the same disk</li>
<li><strong>Flexible</strong>: give the space to one logical volume now, keep the rest for later</li>
</ul>
<h3 id="when-to-use-it">When to use it <a class="anchor" data-pagefind-ignore href="#when-to-use-it" aria-label="Link to this section">#</a></h3>
<ul>
<li><strong>Use it</strong> when a VM or server gets an extra disk and an LVM filesystem needs the space.</li>
<li><strong>Skip it</strong> when the existing virtual disk can simply grow. Then grow that disk instead, see <a href="https://blog.bsdserver.nl/expand-disk-space-on-a-vmware-linux-vm-without-rebooting/">Expand Disk Space on a VMware Linux VM Without Rebooting</a>.</li>
</ul>
<h2 id="how-it-works">How it works <a class="anchor" data-pagefind-ignore href="#how-it-works" aria-label="Link to this section">#</a></h2>
<p>LVM stacks three layers between the disk and the filesystem:</p>
<table>
	<thead>
			<tr>
					<th>Layer</th>
					<th>Example here</th>
					<th>Job</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Physical volume (PV)</td>
					<td><code>/dev/sdc</code></td>
					<td>A disk (or partition) prepared for LVM.</td>
			</tr>
			<tr>
					<td>Volume group (VG)</td>
					<td><code>ubuntu-vg</code></td>
					<td>Pool of space from all its PVs.</td>
			</tr>
			<tr>
					<td>Logical volume (LV)</td>
					<td><code>lv_var</code></td>
					<td>A slice of the pool that holds a filesystem.</td>
			</tr>
			<tr>
					<td>Filesystem</td>
					<td>ext4 on <code>/var</code></td>
					<td>Must be grown separately after the LV.</td>
			</tr>
	</tbody>
</table>
<p>The flow: new disk → <code>pvcreate</code> → <code>vgextend</code> (pool grows) → <code>lvextend</code> (LV grows) → <code>resize2fs</code> (filesystem grows) → <code>df</code> shows the space.</p>
<p>For more on PVs and VGs, see <a href="https://blog.bsdserver.nl/mastering-physical-volumes-and-volume-groups/">Mastering Physical Volumes and Volume Groups</a>.</p>
<h2 id="step-1-check-available-disks">Step 1: Check available disks <a class="anchor" data-pagefind-ignore href="#step-1-check-available-disks" aria-label="Link to this section">#</a></h2>
<p>Find the new, empty disk. <code>lsblk -fa</code> shows all block devices with their filesystem type, so you can see which disks are already in use:</p>
<pre tabindex="0"><code># lsblk -fa
NAME                   FSTYPE      LABEL UUID                                   FSAVAIL FSUSE% MOUNTPOINT
fd0
loop0                  squashfs                                                       0   100% /snap/core18/2344
sda
├─sda1
├─sda2                 LVM2_member       ycKirk-5Njf-jl0R-lGOE-jKbV-xmM5-dNEo0u
│ ├─ubuntu--vg-lv_boot ext4              09833142-b287-4b63-a06b-9ad220d3feb1      997M    16% /boot
│ ├─ubuntu--vg-lv_root ext4              8787c3f7-6651-4787-8fbb-907161694f75      8.1G    40% /
│ ├─ubuntu--vg-lv_var  ext4              7d71eec1-eec5-4083-b882-aa5256bfa98e      2.2G    72% /var
│ ├─ubuntu--vg-lv_swap swap              eb6d1ce5-46c3-4057-860b-ac9658b122df
│ └─ubuntu--vg-lv_home ext4              d8248abf-b466-480b-b962-3dfc00cc810e      5.9G     2% /home
└─sda3                 LVM2_member       Gzk1sQ-MTMY-tlr3-AH1g-2bAI-0O4V-SdkfXM
  ├─ubuntu--vg-lv_boot ext4              09833142-b287-4b63-a06b-9ad220d3feb1      997M    16% /boot
  └─ubuntu--vg-lv_root ext4              8787c3f7-6651-4787-8fbb-907161694f75      8.1G    40% /
sdb
sdc
sr0
</code></pre><ul>
<li><code>sda2</code> and <code>sda3</code> are <code>LVM2_member</code>: already part of the volume group.</li>
<li><code>sdb</code> and <code>sdc</code> have no partitions or filesystem: free to use.</li>
</ul>
<p>If a disk still has a partition table, <code>pvcreate</code> refuses it with this error:</p>
<pre tabindex="0"><code># pvcreate /dev/sdc
  Cannot use /dev/sdc: device is partitioned
</code></pre><p>Older LVM releases (2.02.x) report the same situation as <code>Device /dev/sdc excluded by a filter.</code></p>
<p>Remove the partition table with <code>wipefs</code>. <code>--all</code> removes every signature, <code>--backup</code> saves them to a file in your home directory first, so you can undo it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">wipefs --all --backup /dev/sdc
</span></span></code></pre></div><p>Re-run <code>lsblk -fa</code> to check that the disk is now empty.</p>
<h2 id="step-2-initialize-the-empty-disk-as-a-physical-volume">Step 2: Initialize the empty disk as a physical volume <a class="anchor" data-pagefind-ignore href="#step-2-initialize-the-empty-disk-as-a-physical-volume" aria-label="Link to this section">#</a></h2>
<p><code>pvcreate</code> writes an LVM label on the disk, so a volume group can use it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">pvcreate /dev/sdc
</span></span></code></pre></div><h2 id="step-3-check-which-volume-group-to-assign-the-disk-to">Step 3: Check which volume group to assign the disk to <a class="anchor" data-pagefind-ignore href="#step-3-check-which-volume-group-to-assign-the-disk-to" aria-label="Link to this section">#</a></h2>
<p><code>vgdisplay</code> lists the volume groups and their size and free space:</p>
<pre tabindex="0"><code>vgdisplay
</code></pre><pre tabindex="0"><code>  --- Volume group ---
  VG Name               ubuntu-vg
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  11
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                5
  Open LV               4
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               84.87 GiB
  PE Size               4.00 MiB
  Total PE              21727
  Alloc PE / Size       16583 / &lt;64.78 GiB
  Free  PE / Size       5144 / 20.09 GiB
  VG UUID               DD2SCh-4T1o-PhO9-sTNm-p72z-3zJg-2NNC0j
</code></pre><ul>
<li><code>VG Name</code>: the name you need in the next step.</li>
<li><code>Free PE / Size</code>: space in the pool that no LV uses yet.</li>
</ul>
<p>In this case there is only one volume group: &ldquo;ubuntu-vg&rdquo;.</p>
<h2 id="step-4-extend-the-volume-group-with-the-new-disk">Step 4: Extend the volume group with the new disk <a class="anchor" data-pagefind-ignore href="#step-4-extend-the-volume-group-with-the-new-disk" aria-label="Link to this section">#</a></h2>
<p><code>vgextend</code> adds the PV to the volume group. The pool grows by the size of the disk:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">vgextend ubuntu-vg /dev/sdc
</span></span></code></pre></div><p>The output looks something like this:</p>
<pre tabindex="0"><code>Volume group &#34;ubuntu-vg&#34; successfully extended
</code></pre><p>Check with <code>pvscan</code> that the PV now belongs to <code>ubuntu-vg</code>:</p>
<pre tabindex="0"><code>pvscan
</code></pre><pre tabindex="0"><code>PV /dev/sda2   VG ubuntu-vg       lvm2 [&lt;29.00 GiB / 0    free]
PV /dev/sda3   VG ubuntu-vg       lvm2 [&lt;5.88 GiB / 100.00 MiB free]
PV /dev/sdc    VG ubuntu-vg       lvm2 [&lt;50.00 GiB / &lt;50.00 GiB free]
Total: 3 [84.87 GiB] / in use: 3 [84.87 GiB] / in no VG: 0 [0   ]
</code></pre><p><code>/dev/sdc</code> is in <code>ubuntu-vg</code> with all of its space free.</p>
<h2 id="step-5-assign-the-extra-space-to-a-logical-volume">Step 5: Assign the extra space to a logical volume <a class="anchor" data-pagefind-ignore href="#step-5-assign-the-extra-space-to-a-logical-volume" aria-label="Link to this section">#</a></h2>
<p><code>lvextend</code> gives part of the free pool space to one LV. Here <code>/var</code> gets 30 GiB more:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">lvextend -L+30G /dev/ubuntu-vg/lv_var
</span></span></code></pre></div><table>
	<thead>
			<tr>
					<th>Option</th>
					<th>Use it for</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>-L+30G</code></td>
					<td>Add a fixed amount; keeps the rest free for later.</td>
			</tr>
			<tr>
					<td><code>-L40G</code></td>
					<td>Set the total size of the LV.</td>
			</tr>
			<tr>
					<td><code>-l+100%FREE</code></td>
					<td>Give all free space in the VG to this LV.</td>
			</tr>
	</tbody>
</table>
<p>The output should be similar to this:</p>
<pre tabindex="0"><code>  Size of logical volume ubuntu-vg/lv_var changed from 10.00 GiB (2560 extents) to 40.00 GiB (10240 extents).
  Logical volume ubuntu-vg/lv_var successfully resized.
</code></pre><h2 id="step-6-resize-the-filesystem">Step 6: Resize the filesystem <a class="anchor" data-pagefind-ignore href="#step-6-resize-the-filesystem" aria-label="Link to this section">#</a></h2>
<p>The LV is bigger, but the filesystem on it is not yet. <code>resize2fs</code> grows an ext4 filesystem to fill the LV; it only needs the path of the LV and works while the filesystem is mounted:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">resize2fs /dev/ubuntu-vg/lv_var
</span></span></code></pre></div><p>Output should be something similar to this:</p>
<pre tabindex="0"><code>resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/ubuntu-vg/lv_var is mounted on /var; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 5
The filesystem on /dev/ubuntu-vg/lv_var is now 10485760 (4k) blocks long.
</code></pre><p><code>on-line resizing required</code> means it grew while mounted, which is what you want.</p>
<p><code>resize2fs</code> is for ext2/3/4 only:</p>
<table>
	<thead>
			<tr>
					<th>Filesystem</th>
					<th>Grow command</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>ext4</td>
					<td><code>resize2fs /dev/&lt;vg&gt;/&lt;lv&gt;</code></td>
			</tr>
			<tr>
					<td>XFS</td>
					<td><code>xfs_growfs &lt;mountpoint&gt;</code></td>
			</tr>
	</tbody>
</table>
<p>Check with <code>df</code> that the additional space is available to the filesystem:</p>
<pre tabindex="0"><code>df -h /var
</code></pre><pre tabindex="0"><code>Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-lv_var   40G  7.1G   31G  19% /var
</code></pre><h2 id="troubleshooting">Troubleshooting <a class="anchor" data-pagefind-ignore href="#troubleshooting" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Symptom</th>
					<th>Cause / fix</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>Cannot use /dev/sdc: device is partitioned</code></td>
					<td>Old partition table on the disk. Remove it with <code>wipefs</code> (step 1).</td>
			</tr>
			<tr>
					<td><code>Device /dev/sdc excluded by a filter.</code></td>
					<td>Same cause on older LVM, or an LVM filter in <code>lvm.conf</code> excludes the disk.</td>
			</tr>
			<tr>
					<td><code>Insufficient free space</code> on <code>lvextend</code></td>
					<td>Asked for more than <code>Free PE / Size</code>. Use a smaller size or <code>-l+100%FREE</code>.</td>
			</tr>
			<tr>
					<td><code>df</code> shows the old size</td>
					<td>The filesystem was not resized. Run step 6.</td>
			</tr>
	</tbody>
</table>
<h2 id="automate-it">Automate it <a class="anchor" data-pagefind-ignore href="#automate-it" aria-label="Link to this section">#</a></h2>
<p>The Ansible roles and Terraform code that build this setup are on GitHub: <a href="https://github.com/pderuiter/blog-lvm-expand" rel="noopener">pderuiter/blog-lvm-expand</a>. It creates a VM with two spare disks on Proxmox, builds a practice volume group on the first one and then adds the second disk and grows the logical volume and its filesystem as in the steps above; run <code>terraform apply</code> and then <code>ansible-playbook site.yml</code>.</p>
<h2 id="conclusion">Conclusion <a class="anchor" data-pagefind-ignore href="#conclusion" aria-label="Link to this section">#</a></h2>
<p>Expanding disk space on LVM works on a live system without downtime. The steps:</p>
<ol>
<li>Identify and prepare the new disk</li>
<li>Initialize it as a physical volume</li>
<li>Add it to the volume group</li>
<li>Extend the logical volume</li>
<li>Resize the filesystem</li>
</ol>
<p>Keep some free space in the volume group: next time you only need steps 5 and 6.</p>
]]></content:encoded></item></channel></rss>