Adding a disk to a logical volume manager (LVM)

The problem

Your hardrive became full, so you bought a new one, but how do you add the empty space of the new harddrive to your existing tree of files?

The solution

Find the name of the new disk

fdisk -l
[...]
Disk /dev/sdb: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: Samsung SSD 870
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[...]

The name was /dev/sdb

Create a physical volume of the new disk ("register" the disk into LVM)

sudo pvcreate /dev/sdb

Find the name of the volume group you want to add the new disk to

lvdisplay
  --- Logical volume ---
  LV Path                /dev/gpu-monster-vg/root
  LV Name                root
  VG Name                gpu-monster-vg

gpu-monster-vg is the name of the volume group (VG).

Add the new physical volume to the existing volume group

sudo vgextend gpu-monster-vg /dev/sdb

Choose which logical volume ("partition") you want to dedicate the new storage capacity to

Give all new space to root (the only other logical volume was swap).

Extend the choosen logical volume, (using the `Path`, not the `Name`)

By including the option -r the filesystem on the device is also resized, this works even when the "partition" is mounted.

sudo lvm lvextend -r -l +100%FREE /dev/gpu-monster-vg/root
  Size of logical volume gpu-monster-vg/root changed from 107,14 GiB (27428 extents) to 3,74 TiB (981299 extents).
  Logical volume gpu-monster-vg/root successfully resized.
resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/mapper/gpu--monster--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 14, new_desc_blocks = 480
The filesystem on /dev/mapper/gpu--monster--vg-root is now 1004850176 (4k) blocks long.

That's it, enjoy your new larger filesystem.

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: augusti 4, 2023