14.2. Growing Storage

Growth is the safe direction: every layer involved gains space, and no step destroys data when the order is respected. The order still exists, because a layer can only use capacity the layer below has already published - the disk must become larger before the partition, the array before the encryption mapping, and the mapping before the volume group. This section follows added capacity up that chain twice, once through a GPT partition on a SCSI disk and once through RAID, LUKS, and LVM to a mounted ext4 filesystem, then grows the XFS and Btrfs practice filesystems in place.

14.2.1. Making Additional Device Capacity Visible

The first step is always outside the filesystem: the device the guest can see must become larger. A hypervisor or storage array can expand a virtual disk or LUN while the guest is running, but the guest kernel may continue to report the old capacity until it rescans the transport. The correct rescan depends on the transport, not on Debian:

Transport Rescan method
virtio-blk The hypervisor's block resize usually updates the visible size; a rescan is not required
virtio-scsi or SCSI echo 1 > /sys/class/scsi_device/H:C:T:L/device/rescan, or rescan-scsi-bus.sh from sg3-utils
NVMe nvme ns-rescan /dev/nvmeN, or rescan the namespace through sysfs
Fibre Channel or iSCSI Rescan the SCSI host or use the array's documented host-rescan procedure
GPT partition table sgdisk -e to move the backup header, then partprobe or blockdev --rereadpt

The example uses two roles:

Role Name Access Use in this chapter
Hypervisor host host root or libvirt group membership Resizes the backing virtual disks with virsh
Debian guest migrate management SSH as john Runs the storage, filesystem, and boot commands

On the host, the libvirt domain has a SCSI target. The host expands that target from 2 GiB to 4 GiB while the guest is running:

$ virsh -c qemu:///system blockresize vagrant-debian_migrate --path sda --size 4G
Block device 'sda' is resized

This command runs on the host as an ordinary user with access to the system libvirt daemon - root, or a member of the libvirt group - not on migrate; the guest does not need libvirt installed. The options are:

Option Description
-c URI Connect to the libvirt daemon at URI; qemu:///system is the system-wide instance
blockresize DOMAIN Resize one of DOMAIN's attached disks while it runs
--path DEVICE Name the disk as the domain sees it, such as sda or vdb
--size SIZE New capacity, for example 4G

A physical administrator would instead expand the LUN on the array and rescan the host bus adapter. Back on migrate, as root, the SCSI layer still reports the old size:

# lsblk -o NAME,SIZE /dev/sda
NAME   SIZE
sda      2G
└─sda1   1G

Rescan the SCSI device. The command writes to a sysfs attribute and normally produces no output:

# echo 1 > /sys/class/scsi_device/0:0:0:0/device/rescan

The H:C:T:L address matters: 0:0:0:0 is this guest's SCSI disk. Find the address with ls /sys/class/scsi_device or lsblk -S -o NAME,HCTL when it differs. After the rescan, the disk reports the new size while the partition still has its old one:

# lsblk -o NAME,SIZE /dev/sda
NAME   SIZE
sda      4G
└─sda1   1G

The 3 GiB of new space is unallocated. Note that the disk grew but the partition did not. The partition table and the filesystem are separate objects, and each needs its own growth step.

14.2.2. Extending Partitions, RAID, Encryption Mappings, and LVM

An ext4 filesystem can grow while mounted, but a partition table is easier and safer to change with the filesystem unmounted. For the practice partition, unmount it, move the secondary GPT header to the end of the enlarged disk, and resize the partition:

# umount /srv/part

The command is silent.

# sgdisk -e /dev/sda
The operation has completed successfully.
# parted -s /dev/sda unit MiB resizepart 1 3073MiB

The command is silent.

# partprobe /dev/sda

The command is silent. sgdisk -e is the step that is easy to miss after a disk grows. GPT stores a backup header at the end of the device; on the old 2 GiB disk it sits at the old end, so parted sees the disk as not fully used until the header is moved. The partition now ends at 3073 MiB:

# lsblk -o NAME,SIZE,TYPE,FSTYPE /dev/sda
NAME   SIZE TYPE FSTYPE
sda      4G disk 
└─sda1   3G part ext4

Mount the partition again and let resize2fs grow the filesystem into the new partition space:

# mount /dev/sda1 /srv/part

The command is silent.

# resize2fs /dev/sda1
resize2fs 1.47.2 (1-Jan-2025)
Filesystem at /dev/sda1 is mounted on /srv/part; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/sda1 is now 786432 (4k) blocks long.

resize2fs reads the partition size when no explicit size is given. The new block count, 786432, is exactly 3 GiB divided by 4 KiB. The data is still there:

# sha256sum -c /home/john/debian-handbook/storage-migration/part-keep.sha256
/srv/part/keep.bin: OK

An XFS filesystem on a whole disk needs no partition step: the disk itself is the container. After the host expands /dev/vdb to 3 GiB, the guest sees the larger block device immediately because it is virtio-blk:

$ virsh -c qemu:///system blockresize vagrant-debian_migrate --path vdb --size 3G
Block device 'vdb' is resized

The host command is followed by a check on migrate, again in the root shell:

# lsblk -o NAME,SIZE /dev/vdb
NAME SIZE
vdb    3G

xfs_growfs takes the mount point and expands the data section to the device size:

# xfs_growfs /srv/xfs
meta-data=/dev/vdb               isize=512    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=1
         =                       reflink=1    bigtime=1 inobtcount=1 nrext64=1
         =                       exchange=0   metadir=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1, parent=0
log      =internal log           bsize=4096   blocks=16384, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
         =                       rgcount=0    rgsize=0 extents
data blocks changed from 524288 to 786432

The final line is the only line that reports the change; the geometry above it is the pre-growth state. XFS has no separate partition to grow in this layout, so the filesystem can consume the whole new disk size.

The RAID1 layer needs both members to grow before the array can use the new space. The host expands /dev/vdc and /dev/vdd to 3 GiB each:

$ virsh -c qemu:///system blockresize vagrant-debian_migrate --path vdc --size 3G
Block device 'vdc' is resized
$ virsh -c qemu:///system blockresize vagrant-debian_migrate --path vdd --size 3G
Block device 'vdd' is resized

Both commands run on the host. Inside the guest the member disks are 3 GiB, while md0 remains 2 GiB:

# lsblk -o NAME,SIZE,TYPE,FSTYPE /dev/vdc /dev/vdd /dev/md0
NAME                  SIZE TYPE  FSTYPE
md0                     2G raid1 crypto_LUKS
└─cryptstack            2G crypt LVM2_member
  └─stackvg-stacklv     1G lvm   ext4
vdc                     3G disk  linux_raid_member
└─md0                   2G raid1 crypto_LUKS
  └─cryptstack          2G crypt LVM2_member
    └─stackvg-stacklv   1G lvm   ext4
vdd                     3G disk  linux_raid_member
└─md0                   2G raid1 crypto_LUKS
  └─cryptstack          2G crypt LVM2_member
    └─stackvg-stacklv   1G lvm   ext4

Grow the array's component size to the largest value that fits both members:

# mdadm --grow /dev/md0 --size=max
mdadm: component size of /dev/md0 has been set to 3142656K

The command changes the array metadata; the kernel then resynchronizes the new area. Wait until /sys/block/md0/md/sync_action returns to idle, then verify the array size:

# mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Fri Nov 20 17:54:31 2026
        Raid Level : raid1
        Array Size : 3142656 (3.00 GiB 3.22 GB)
     Used Dev Size : 3142656 (3.00 GiB 3.22 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

             State : clean 
    Active Devices : 2
    Working Devices : 2
    Failed Devices : 0
       Spare Devices : 0

Selected output; the update time, consistency policy, name, UUID, event count, and member lines are omitted. The array now reports 3.00 GiB, but the LUKS mapping still exposes only its old 2 GiB payload. cryptsetup resize recomputes the mapping size from the underlying device. Because the volume key is already loaded in the kernel keyring, this command needs no passphrase; if the key has been evicted, supply --key-file as in the original open:

# cryptsetup resize --key-file /etc/luks-keys/stack.key cryptstack

The command is silent. Check the size before asking LVM to use it:

# cryptsetup status cryptstack
/dev/mapper/cryptstack is active and is in use.
  type:    LUKS2
  cipher:  aes-xts-plain64
  keysize: 512 bits
  key location: keyring
  device:  /dev/md0
  sector size:  512
  offset:  32768 sectors
  size:    6252544 sectors
  mode:    read/write

The mapping grew from 4155392 to 6252544 sectors. The header offset is unchanged; only the data payload became larger. Now the PV, VG, LV, and filesystem follow in order:

# pvresize /dev/mapper/cryptstack
  Physical volume "/dev/mapper/cryptstack" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized

Read the PV and VG sizes back:

# pvs
  PV                     VG      Fmt  Attr PSize  PFree   
  /dev/mapper/cryptstack stackvg lvm2 a--   2.98g    1.98g
  /dev/vde               demovg  lvm2 a--  <2.00g 1020.00m
  /dev/vdf               demovg  lvm2 a--  <4.00g   <4.00g

pvresize makes the new extents available to the volume group. The free space is visible in the PFree column. Extend the logical volume into all of it:

# lvextend -l +100%FREE /dev/stackvg/stacklv
  Size of logical volume stackvg/stacklv changed from 1.00 GiB (256 extents) to 2.98 GiB (763 extents).
  Logical volume stackvg/stacklv successfully resized.

LVM does not change the filesystem. resize2fs does that, online because the filesystem is mounted:

# resize2fs /dev/stackvg/stacklv
resize2fs 1.47.2 (1-Jan-2025)
Filesystem at /dev/stackvg/stacklv is mounted on /srv/stack; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/stackvg/stacklv is now 781312 (4k) blocks long.

The sequence for the full stack is therefore: disk, array, mapping, PV, LV, filesystem. Each command below the filesystem made the next device larger; the filesystem command was last. The options used in this section are:

Command Option Description
sgdisk -e Move the backup GPT header to the end of the enlarged disk
parted resizepart N SIZE Set partition N's end to SIZE without recreating it
partprobe none Ask the kernel to reread a partition table
mdadm --grow --size=max Use the largest component size that fits all members
cryptsetup resize --key-file FILE Recompute the mapping from the device, using FILE if a key is needed
pvresize none Make the PV's new size available to its volume group
lvextend -l +100%FREE Allocate all remaining extents to the LV
resize2fs none Grow ext4 to the size of its block device

14.2.3. Growing Ext4, XFS, and Btrfs Filesystems

The filesystem command is the same regardless of what made the block device larger, but the three filesystems behave differently:

Filesystem Grow command Online grow Shrink support
ext4 resize2fs DEVICE [SIZE] Yes, after the device is larger Offline only, after e2fsck
XFS xfs_growfs MOUNTPOINT Yes, on a mounted filesystem No ordinary shrink; migration for a reliable reduction
Btrfs btrfs filesystem resize DEVID:SIZE MOUNTPOINT Yes, per device Online, subject to chunk allocation

Ext4 is already covered by the partition and LV growth examples. The important distinction is that resize2fs /dev/sda1 reads the partition size when no size argument is supplied, while resize2fs DEVICE 1024M sets an explicit size. XFS takes a mount point rather than a device and will not grow a filesystem that is not mounted. Btrfs takes a device identifier and a size; max means the whole device.

Btrfs is the only one of the three that can grow and shrink a device online without a separate container step. The host expands /dev/vdg from 2 GiB to 4 GiB. The guest sees the larger device, but the Btrfs filesystem still uses only the old 2 GiB on that device:

# lsblk -o NAME,SIZE /dev/vdg
NAME SIZE
vdg    4G

The device reports 4 GiB; the filesystem's own view of it has not changed. Tell Btrfs to use the whole device:

# btrfs filesystem resize 1:max /srv/btr
Resize device id 1 (/dev/vdg) from 2.00GiB to max

btrfs filesystem show reports the per-device sizes and the space the filesystem is actually using:

# btrfs filesystem show /srv/btr
Label: 'btrdata'  uuid: 30561864-0a3e-4fa1-86c6-f8a471d8a6d3
    Total devices 2 FS bytes used 160.31MiB
    devid    1 size 4.00GiB used 272.00MiB path /dev/vdg
    devid    2 size 2.00GiB used 680.00MiB path /dev/vdh

The filesystem now has a 4 GiB device and a 2 GiB device. The used values are allocated chunks, not the sum of file sizes; Btrfs allocates data and metadata in chunks, and this filesystem has metadata RAID1 across both devices. That distinction becomes the central problem in Section 14.3.3.

14.2.4. Verifying Capacity at Every Layer

A successful command at one layer does not prove that the layer above it saw the change. Verify each boundary with a command that reads the layer itself, then verify that the files are still readable.

# lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
NAME                   SIZE TYPE  FSTYPE            MOUNTPOINTS
sda                      4G disk                    
└─sda1                   3G part  ext4              /srv/part
vda                    100G disk                    
└─vda1                 100G part  ext4              /
vdb                      3G disk  xfs               /srv/xfs
vdc                      3G disk  linux_raid_member 
└─md0                    3G raid1 crypto_LUKS       
  └─cryptstack           3G crypt LVM2_member       
    └─stackvg-stacklv    3G lvm   ext4              /srv/stack
vdd                      3G disk  linux_raid_member 
└─md0                    3G raid1 crypto_LUKS       
  └─cryptstack           3G crypt LVM2_member       
    └─stackvg-stacklv    3G lvm   ext4              /srv/stack
vde                      2G disk  LVM2_member       
└─demovg-appdata         1G lvm   ext4              /srv/appdata
vdf                      4G disk  LVM2_member       
vdg                      2G disk  btrfs             /srv/btr
vdh                      2G disk  btrfs             
vdi                      2G disk                    
vdj                      4G disk                    
vdk                      2G disk  ext4              /srv/migsrc
vdl                      2G disk  ext4              /srv/migdst
vdm                      2G disk                    

The SIZE column in this view is rounded. It shows 3G for both the raw RAID members and the LVM volume, but the filesystem's own view is more precise:

# df -h /srv/stack
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/stackvg-stacklv  2.9G   65M  2.7G   3% /srv/stack

The progression from a 3 GiB member disk to a 2.9 GiB mounted filesystem is normal: md reserves metadata, LUKS2 reserves its header, LVM rounds to its extent size, and ext4 reserves space for its own metadata and root reserve. The exact numbers are not a defect. What matters is that every layer reports a consistent size and that the data still verifies:

# sha256sum -c /home/john/debian-handbook/storage-migration/stack-keep.sha256
/srv/stack/keep.bin: OK
# lvs -o lv_name,vg_name,lv_size,devices
  LV      VG      LSize Devices                  
  appdata demovg  1.00g /dev/vde(0)              
  stacklv stackvg 2.98g /dev/mapper/cryptstack(0)
# df -h /srv/xfs
Filesystem      Size  Used Avail Use% Mounted on
/dev/vdb        3.0G  107M  2.9G   4% /srv/xfs

The XFS filesystem reports the same 3 GiB as its grown device, and the LVM listing maps each volume to the device that currently holds it.

Layer Verification command What to compare
Physical or virtual disk lsblk -o NAME,SIZE The provider's new size
Partition lsblk, parted print The partition end and the unallocated tail
md array mdadm --detail Array size and member state
LUKS mapping cryptsetup status Payload size and offset
LVM pvs, vgs, lvs PV size, VG free extents, LV size and devices
Filesystem df -h, xfs_info, btrfs filesystem show Filesystem size and allocation
Data sha256sum -c The bytes did not change