Here are some instructions for how to grow ext4+lvm+LUKS+RAID storage.
NOTE: If you can stop the array and are only growing (and not moving) the partition, you can modify all drives at once. Otherwise you will need to do one disk at a time with a resync after each disk is done. Detailed instructions here. These instructions are only for growing partitions on existing disks, you will need to adjust if you are doing something different.
unmount the partition¶
stop the vg (assuming other lvols in that vg are unmounted)¶
vgchange -a n vg_hostnameX
stop the crypt¶
(use pvs to determine which device for the vg)
cryptsetup luksClose /dev/mapper/mdX_crypt
initialized the new space¶
we want to random fill the space we will add, we do this by adding a temporary partition, filling it with random data, and then deleting it (this page claims that deleting a partition on an SSD does not result in a TRIM operation, so the random data should be left)
For each disk
fdisk /dev/sdX # add additional partition
dd if=/dev/urandom of=/dev/sdXN+1
fdisk /dev/sdX # delete the added partition
debian-installer has a faster way of doing this, it creates a throw-away LUKS on the device , writes data to it, and then deletes it. It would be nice to have that as a stand-alone tool.
extend the partitions and raid¶
(use /proc/mdstat to determine the devices in the raid array)
NOTE: read note at top, these instructions are only for growing
If you are using write intent bitmaps you will need to remove them before growing and then re-add them (make sure you have the bitmap settings recorded)
mdadm --grow /dev/mdX --bitmap none
extend the partitions
fdisk /dev/sdX # extend partition
fdisk /dev/sdY # extend partition, repeat for additional disks
grow the RAID and after it’s finished re-add the bitmap
mdadm --grow /dev/mdX --size=max
mdadm --wait /dev/mdX
mdadm --grow /dev/mdX --bitmap internal
If you are creating a new array
- create the partitions you need with fdisk
- create the array with something like:
mdadm --create /dev/md4 --raid-devices=2 --level=raid1 --bitmap=/boot/md4_bitmap --bitmap-chunk=128M /dev/sde1 /dev/sdf1
start and resize the crypt¶
cryptsetup luksOpen /dev/mdX mdX_crypt
cryptsetup resize mdX_crypt
extend the pv/vg/lvol and activate¶
lvresize -L +sizeG /dev/mapper/vg_hostnameX-lvol # where size is how much you are adding, or
lvresize -l +100%FREE /dev/mapper/vg_hostnameX-lvol # to extend the lvol to use the rest of the space in the vg
vgchange -a y vg_hostnameX
force a filesystem check, to be sure it’s clean before extending¶
fsck.ext4 -C0 -f /dev/mapper/vg_hostnameX-lvol
extend the filesystem and remount¶
You’re done! Use df to ensure the filesystem is the correct new size.
Growing (only) an active stack¶
If all you are doing is growing a stack and not moving partitons around, etc you can do that with everything live.
For example when you swap larger drives into the array and want to grow the last partition.
fdisk /dev/sdX # resize last partition
fdisk /dev/sdY # resize last partition
partprobe /dev/sdX # get the kernel to notice
partprobe /dev/sdY # get the kernel to notice
mdadm --grow --bitmap none /dev/mdX # recommended to remove bitmap
mdadm --grow --size=max /dev/mdX # grow the raid array
mdadm --grow --bitmap internal /dev/mdX # re-add bitmap (internal for SSD in this case)
cryptsetup resize mdX_crypt # grow the luks
pvs # note the PFree amount
pvresize /dev/mapper/mdX_crypt # grow the LVM pv
pvs # check that PFree on that pv is larger
vgs # check that VFree in that vg is larger
lvresize -l +100%FREE /dev/mapper/vg_hostnameX-lvol # grow an lvol in that VG
resize2fs /dev/mapper/vg_hostnameX-lvol # resize the fs in that lvol
df -h # see the larger fs
This is super helpful!
Just want to say that I used the “Growing (only)” section on a machine and it worked flawlessly, even resizing the active / partition. Thanks for the great writeup.