Linux Labs

Storage / Stage 6 of 11

Logical volumes and growing a filesystem

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 7 · on a machine · 7 min

When only the volume grew

Growing in two steps can stop halfway. Here is how to tell where it stopped and what to do next.

A volume grows only from the group's free extents, shown in the VFree column of vgs. When there are none, you add a physical volume to the group with vgextend. Check the disk first: it must be empty and meant for LVM, because preparing it for LVM wipes its partition table.

Check yourself 1 question

The group's VFree is 0, and the data volume needs another 100 MiB. What do you do?

  • mkfs creates an empty filesystem on the same volume: the data is lost, and there is no more room.

  • A volume with a filesystem is shrunk only after the filesystem is, or the neighbour's data suffers. That is separate work with its own checks; vgs and lvs do not replace them.

  • +100%FREE takes the group's free extents, and there are none: lvextend prints Insufficient free space.

A volume gets space only from the group's free extents. When there are none, you add a physical volume to the group, a checked empty disk (vgextend), and only then grow the volume.

Without -r, or after an error in the second step, the volume has grown and ext4 has not. Two commands side by side show it: sudo lvs shows the new volume size, and df -h the old filesystem size. What is left is to grow the filesystem: resize2fs with no size stretches it over the whole volume.

lvextend with a plus would grow the volume once more at this point, leaving the filesystem as it was. Shrinking the volume back as an undo is dangerous: cutting off blocks where ext4 keeps data damages the filesystem. mkfs does not help here either: it creates a new, empty filesystem in place of the old one.

Exercise · do it

Finish the growth

A colleague grew the /dev/lab_vg/data volume to 256 MiB, yet the service still cannot write to /mnt/lvm-data. Finish the growth without changing the volume's size, and as your own user write the line report to /mnt/lvm-data/report.txt.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Grow the filesystem to the volume's size not done yet
  • Write report.txt as your own user not done yet

Step goals

0 of 2
  • Grow the filesystem to the volume's size — not done yet
  • Write report.txt as your own user — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Grow the filesystem to the volume's size — not done yet
  • Write report.txt as your own user — not done yet
Loading…