As I came to work this morning, I was painfully reminded of my task to grow our fileserver’s file system. It has reached over 90% utilization two month ago, but I always delayed that task, as I was not willing to take the system down or even reboot during working time. So this morning there was no other way left than to finally resize the filesystem as it now reached 100% utilization (shame on me).
Usually there is nothing special about online resizing an EXT3 filesystem, but I never tried that with a LUKS encrypted one. I was glad to find a good how-to at ubuntuforums.org which basically points out how it works with Ubuntu 8.04. As our fileserver runs Debian Lenny I knew that some things of the how-to are outdated. So here is a short summary of the steps, neccesarry to (nearly online) resize a LUKS encrypted root filesystem on a LVM logical volume:
- 1. Enlarge the partition conaining the crypted data with fdisk.
- 2. Reboot – always needed after making changes to the partition table
- 3. Enlarge the encrypted data with cryptsetup.
- 4. Enlarge the (LVM) physical volume with pvresize.
- 5. Enlarge the (LVM) logical volume with lvresize.
- 6. Enlarge the file system with resize2fs.
- 7. Reboot – let’s see if everything works as expected
Now here are the steps in detail:
1. Changing your partition table
cfdisk and delete the partition you want to resize. Afterwards create a new partition starting at the same block as the previously deleted partition, but with a new size including the newly added free space.
This is definitely required to make sure the following used utils get to know the new size of the partitions.
3. Enlarge encrypted data
The following command resizes the encrypted storage to the filesystem’s boundaries:
cryptsetup resize /dev/mapper/sda2_crypt
4. Enlarge LVM physical volume
Now the LVM physical volume can be resized with the
5. Enlarge the LVM logical volume
If you now run vgdisplay you will see that there are free physical extents (PE) available in the volume group where the physical volumes belongs to. To extent your logical volume to all free PEs you can use “-l +100%FREE” as parameter for the
lvresize -l +100%FREE /dev/mapper/hostname-root
6. Enlarge the file system
Finally it is time to resize the actual filesystem. To make sure it has no errors it is a good advise to run a filesystem check before really resizing it.
e2fsck -f /dev/mapper/hostname-root
resize2fs -p /dev/mapper/hostname-root
7. Final Reboot
Just to make sure everything works fine after all this exciting stuff.