tier1.jp

LVM LV and filesystem extend on LVM over LUKS system.

This method is tested on Debian GNU/Linux Stretch, ext4 multi-partition system on LVM-over-LUKS setting.

Rev 2

Add comments for "ro" root filesystem case.

Prepare

DO BACKUP.

Extending ext4 filesystem is matured.

However, these kinds of storage operations under root privilege may corrupt your system, by making some mistakes.

Anyway, backup before doing something administrative is crucial.

Actual Steps

Assume we have the root file system on

  • LVM over LUKS
  • LVM VG "vgname"
  • LVM LV "rootfs"; the LV path is /dev/vgname/rootfs
  • / is formatted as ext4
root# vgdisplay vgname # confirm we have enough free physical extent.
...
  Free  PE / Size       X / Y GiB

root# lvdisplay /dev/vgname/rootfs # confirm the size
...
  LV Size               Z GiB

Entering rescue mode

Cold boot and enter into rescue mode.

Push 'e' and edit the linux boot parameter "rescue"
grub> linux ... rescue
then hit F10 to boot

Enter the LUKS passphrase, and enter the root password to login.

Note

It is possible to extend the volumes without entering rescue mode, but it could be a potential risk.

Extending actually

Let us extend /dev/vgname/rootfs 1 GiB.

If you setup "ro" root file system without remounting / as "rw", lvextend fails with status code 5.

root# mount -o remount,rw /
(then extend, remount,ro again).

In this example, we let lvextend to do automatically by fsadm.

root# lvextend --size +1G --resizefs /dev/vgname/rootfs # don't forget "+"
  Size of logical volume vgname/rootfs changed from A GiB (a extents) to A+1 GiB (a+e extents).
  Logical volume vgname/rootfs successfully resized.
resize2fs VERSION (DATE)
Filesystem at /dev/mapper/vgname-rootfs is mounted on /; on-line resizing required
[ time.msec] EXT4-fs (dm-i): resizing filesystem from N to N+n blocks
[ time.msec] EXT4-fs (dm-i): resized filesystem to N+n
The filesystem on /dev/mapper/vgname-rootfs is now N+n (4k) blocks long.

It displays the actual numbers; A, a, e, N, n are pseudo replacements.

Now, see what happened.

root# df -h # confirm the size has extended.

If it seems okay, then reboot normally.

root# reboot -n # and confirm the journalctl, lvdisplay, and df.

Comments

It is this easy to EXTEND the LVM LV and ext4 filesystem.

And that is why tier1.jp wrote some Debian install guides with relatively small partition amounts.

On the other hand, shrinking the filesystem is tricky.

It is not always possible, too; depends on the mountpoint usage/occupation.

Note

Preserve LVM Free PE, extend on demand.

published: MODIFIED: