Linux and servers · Advanced · 18 min
Add disks and grow filesystems with LVM
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · LVM2 2.03.31
You will pool two disks into an LVM volume group, grow a mounted ext4 filesystem, add a third disk, take a snapshot for a consistent backup, retire a disk with pvmove and claim the space the Ubuntu installer left free.
On this page
A filesystem made straight on a disk is as big as that disk, for life. When it fills, you either move the data to a bigger disk or start splitting it across mount points. LVM (the Logical Volume Manager) puts a layer in between. You hand it whole disks, it pools them, and you carve volumes out of the pool that can grow, move between disks and be snapshotted while they stay mounted.
In this tutorial you build a small data store for a server: two disks pooled into a volume group called data-vg, one logical volume mounted at /srv/files, then you grow it, add a third disk, take a snapshot for a backup and retire the first disk. The last step applies the same tools to the root volume the Ubuntu Server installer creates.
Every command here changes disks. Read each warning before you run the command under it, and run them on volumes that hold nothing you need, or on a server you have a fresh provider snapshot of.
Pooling small volumes also suits a tight budget. If your provider bills block storage by the gigabyte each month, as many hosts in Lagos, Nairobi and elsewhere do, you can start with a small volume and add another when the data grows, instead of paying for a large disk up front.
Step 1 · Learn the three layers
LVM has three kinds of object, and every command name starts with the layer it works on:
- A physical volume (PV,
pv...commands) is a disk or partition that LVM has labelled for its own use. - A volume group (VG,
vg...) pools one or more PVs into a single store of space, cut into fixed-size extents (4 MiB each by default). - A logical volume (LV,
lv...) is a block device made from extents in a VG. You put a filesystem on it and mount it as you would a partition. It shows up as/dev/<vg>/<lv>and as/dev/mapper/<vg>-<lv>.
An LV does not have to sit on one disk. Its extents can come from any PV in the group, which is why you can grow it past the size of a single disk and move it off a disk without stopping it.
Make sure the tools are installed. Ubuntu Server normally has them already:
sudo apt update
sudo apt install -y lvm2
sudo lvm versionCheck it worked
lvm version prints an LVM version: line starting with 2.03. Without arguments, sudo pvs prints nothing or only the PVs your server already has (for example the installer's root disk, covered in the last step).
Step 2 · Find the new disks and label them as physical volumes
Find the empty disks by size and serial number, not by guessing a name. /dev/sdb on one server is /dev/vdb or /dev/nvme1n1 on another, and the order can change at boot:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,SERIALA new volume has no FSTYPE, no children (partitions) and no mount point. Match its size and serial with the volume you attached in your provider's console. The parted tutorial shows how to check this with /dev/disk/by-id as well.
Set the names once so the rest of the commands use your disks. Replace these three values with the ones you found:
DISK1=/dev/sdb # replace this
DISK2=/dev/sdc # replace this
DISK3=/dev/sdd # replace this; used in a later stepList any signatures on the first two disks. Without -a, wipefs only reads, it does not wipe:
sudo wipefs "$DISK1"
sudo wipefs "$DISK2"If either command prints a table of signatures, the disk is not empty. Stop and find out what is on it.
Warning: pvcreate writes an LVM label onto the disk. Anything stored there before is lost. When wipefs printed nothing for both disks, label them:
sudo pvcreate "$DISK1" "$DISK2"This uses whole disks, with no partition table. That keeps growing and replacing them simple. Some teams prefer one partition per disk so other tools see that the disk is in use; both work.
Check it worked
sudo pvs lists both disks with lvm2 in the Fmt column, an empty VG column and PFree equal to PSize, something like:
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 20.00g 20.00g
/dev/sdc lvm2 --- 20.00g 20.00gStep 3 · Pool the disks and create a logical volume
Create the volume group from both PVs:
sudo vgcreate data-vg "$DISK1" "$DISK2"Then make a 30 GB logical volume called files. That is more than one 20 GB disk holds, so LVM takes extents from both:
sudo lvcreate -n files -L 30G data-vgLeave the rest of the group free on purpose. Free extents are what you grow into later, and what snapshots use. -l 100%FREE would take everything, which leaves no room for a snapshot.
Check it worked
sudo vgs data-vg shows #PV as 2 and VFree of roughly 10 GB. sudo lvs data-vg shows files with LSize of 30.00g. To see which disks hold its extents, run:
sudo lvs -o lv_name,lv_size,devices data-vgThe Devices column names both disks.
Step 4 · Make a filesystem and mount it
Put ext4 on the volume, mount it and give it to your user so you can write sample data:
sudo mkfs.ext4 -L files /dev/data-vg/files
sudo mkdir -p /srv/files
sudo mount /dev/data-vg/files /srv/files
sudo chown "$USER": /srv/filesext4 can grow while mounted, and can shrink only while unmounted. XFS (mkfs.xfs) also grows while mounted but cannot shrink at all. Choose ext4 here unless you have a reason to prefer XFS.
Write a file so you can see that data survives the later steps:
dd if=/dev/urandom of=/srv/files/sample.bin bs=1M count=200
sha256sum /srv/files/sample.bin | tee ~/lvm-demo-sample.sha256The mount lasts until the next reboot. To mount it at boot, add it to /etc/fstab as the fstab tutorial shows. LV paths such as /dev/data-vg/files do not change with disk order, so you can use either the path or the filesystem UUID there.
Check it worked
df -h /srv/files shows /dev/mapper/data--vg-files (LVM doubles the hyphens inside names) with a size of about 29G, since ext4 keeps some space for itself. ls -l /srv/files lists sample.bin at 200M.
Step 5 · Grow the mounted filesystem
When /srv/files fills, grow it into the free extents. The -r flag resizes the filesystem in the same command, so you do not need a separate resize2fs:
sudo lvextend -r -L +5G data-vg/files-L +5G adds 5 GB. -L 35G would set an absolute size, and -l +100%FREE would use all the free space in the group. Nothing is unmounted and no service needs to stop.
Check it worked
df -h /srv/files now shows about 5 GB more than before, and sudo vgs data-vg shows VFree down by 5 GB. sha256sum -c ~/lvm-demo-sample.sha256 prints sample.bin: OK.
Step 6 · Add a third disk to the group
When the group itself runs low, attach another volume in your provider's console and add it to the group. Check it is empty first, as before:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,SERIAL
sudo wipefs "$DISK3"Warning: vgextend labels the disk as a PV if it is not one yet, which overwrites what is on it. When wipefs printed nothing, add it:
sudo vgextend data-vg "$DISK3"The new extents are free space in data-vg. Grow files into them with lvextend -r from the previous step whenever you need to.
Check it worked
sudo vgs data-vg shows #PV as 3 and VFree about 20 GB larger than before. sudo pvs lists the third disk with data-vg in the VG column.
Step 7 · Take a snapshot for a consistent backup
Backing up a filesystem that is being written to can capture files halfway through a change. A snapshot freezes the volume's contents at one moment, so you back up a still copy while the original stays in use.
This kind of snapshot is copy-on-write. It starts almost empty. Each time a block on files changes, LVM first copies the old block into the snapshot. So the snapshot needs room for everything that changes while it exists, not a full copy. If it fills, LVM marks it invalid and the backup taken from it is useless. Size it for the writes you expect during the backup, plus a margin; 10–20 per cent of the origin is a reasonable first guess for a short-lived snapshot; the Data% check below tells you if it was enough.
Each snapshot also slows writes to the origin a little, because of that extra copy. Remove it as soon as the backup is done.
If a database writes to the volume, stop it or use its own backup tool first, so the snapshot does not catch it mid-transaction.
Create a 4 GB snapshot and mount it read-only:
sudo lvcreate -s -n files-snap -L 4G data-vg/files
sudo mkdir -p /mnt/files-snap
sudo mount -o ro /dev/data-vg/files-snap /mnt/files-snapFor XFS, add nouuid to the options (-o ro,nouuid), because the snapshot carries the same filesystem UUID as the mounted original.
Back up from /mnt/files-snap with your usual tool. The restic tutorial covers one. For this walkthrough, a tar archive in your home folder will do:
sudo tar -C /mnt/files-snap -czf ~/lvm-demo-files.tar.gz .While the backup runs, watch how full the snapshot is:
sudo lvs -o lv_name,origin,lv_size,data_percent data-vgWhen the backup is done, unmount and remove the snapshot:
sudo umount /mnt/files-snap
sudo lvremove -y data-vg/files-snapCheck it worked
While it existed, lvs showed files-snap with files in the Origin column and a Data% well below 100. tar -tzf ~/lvm-demo-files.tar.gz lists ./sample.bin. After lvremove, sudo lvs data-vg lists only files.
Step 8 · Retire a disk with pvmove
To replace a small or failing volume, move its data onto the other disks while everything stays mounted, then take it out of the group.
First make sure the other disks can take the data. Compare the space in use on the disk you are retiring (PSize minus PFree) with the PFree of the others:
sudo pvs -o pv_name,vg_name,pv_size,pv_freeIf the others do not have enough free space, add a disk first, as in the previous step.
Move every extent off the first disk. It reports progress as a percentage and can take a long time on large disks; the filesystem stays usable throughout:
sudo pvmove "$DISK1"Then take the empty disk out of the group and remove its LVM label:
sudo vgreduce data-vg "$DISK1"
sudo pvremove "$DISK1"Only now detach the volume in your provider's console.
Check it worked
sudo pvs no longer lists the first disk. sudo lvs -o lv_name,devices data-vg shows files on the remaining disks only. sha256sum -c ~/lvm-demo-sample.sha256 still prints sample.bin: OK, and df -h /srv/files shows the same size as before.
Step 9 · Claim the space the Ubuntu installer left free
If you installed Ubuntu Server with its default storage layout, your root filesystem is already on LVM: a group called ubuntu-vg with a logical volume called ubuntu-lv. The installer leaves room in the group on purpose: on a disk of 20 GB or more it gives ubuntu-lv about half of the space, up to 100 GB, and leaves the rest free. So a server can report a nearly full / while space sits unused. Check:
df -h /
sudo vgs ubuntu-vg
sudo lvs ubuntu-vgdf shows /dev/mapper/ubuntu--vg-ubuntu--lv mounted on /. If vgs shows a VFree larger than zero, that space is yours to claim. Give all of it to the root volume, growing the filesystem in the same command:
sudo lvextend -r -l +100%FREE ubuntu-vg/ubuntu-lvIf you plan to take snapshots of the root volume, add only part of it (for example -L +20G) and keep the rest free.
If VFree is zero but the provider says the disk is bigger, the disk grew under the partition and the PV has not caught up. The cloud disk tutorial covers growpart; after it, run sudo pvresize on that partition and then the lvextend above.
Check it worked
sudo vgs ubuntu-vg shows VFree as 0 (or what you chose to keep), and df -h / shows the larger size.
To clean up the walkthrough, unmount and remove the demo volume group, then detach the remaining volumes in your provider's console. Warning: this deletes everything in data-vg.
sudo umount /srv/files
sudo lvremove -y data-vg/files
sudo vgremove data-vg
sudo pvremove "$DISK2" "$DISK3"
sudo rmdir /srv/files /mnt/files-snap
sudo rm ~/lvm-demo-sample.sha256 ~/lvm-demo-files.tar.gzRemove any /etc/fstab line you added for /srv/files before you reboot.
Next steps
- Mount
/srv/filesat every boot with Mount a disk at boot with fstab and UUIDs. - Back up from your snapshots on a schedule with Back up a server with restic.
- Grow a provider volume in place with Grow a cloud server disk without downtime.
- Prepare a single disk without LVM in Partition and format a new disk with parted.
Related tutorials
- Write safer Bash scripts with strict mode and trapsYou will build a small Bash release script that stops on the first error, says which line failed, survives file names with spaces and always removes its temporary files.
- Write least-privilege sudo rules with visudoYou will replace blanket sudo access with checked rule files in /etc/sudoers.d that let two operators restart one service and edit one file, give an automation account a password-free command list, and audit what every account can run.
- Upgrade a server from Ubuntu 24.04 LTS to 26.04 LTSYou will take a backed-up Ubuntu 24.04 server through do-release-upgrade to 26.04 LTS over SSH with a fallback login, then confirm services, repositories and language runtimes work on the new release.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials