--- title: Resize partitions on an encrypted disc date: 2015-03-20 tags: [code, linux] description: The Debian installer chose to use only 10GB for the root partition. So now I was tasked with resizing the partitions. --- Recently I installed a fresh debian jessie on my laptop. I used this opportunity not just to switch to the next debian version, I also switched to 64 bit and encrypted my disc. I had no experience with encrypted disc setups so I trusted the debian installer. It offered several default partition options of which I chose to have a root partition with a separate home partition. The trouble is now that the installer chose to use only 10GB for the root partition which I used up in the first week. So now I was tasked with resizing the partitions. ## What I already knew In the past I had used [gparted](http://gparted.org/) for task like this one. Unfortunately, gparted does not support encryptet discs. I was very unconfident about doing this without a tool I knew but in the end it turned out to be rather simple. If it had not been for the encryption, these are the steps I would have done in gparted (assuming that `root` takes up the first 10GB of the disc and `home` uses all the rest): 1. shrink `home` by 10GB 2. move `home` to the end of the disc 3. grow `root` ## the actual situation The disc layout was roughly like this: - there is one physical volume - the pysical volume containes a crypt - the crypt contains two logical volumns, `root` and `home` - the logical volumes both contain an ext\* file system There were two aspects about this that I did not expect and that significantly simplify my task: - I could completely ignore the encryption part. I only have to think about the logical volumes and the filesystems. - logical volumes can use available space anywhere on the physical volume. So there is no need to "move" `root`. ## what I had to do - The necessary operations can not be applied to mounted volumes. So I had to boot into a live system. - Get access to logical volmes inside of the crypt without mounting them (or unmount again) - shrink `home` - e2fsck /dev/mapper/localhost--vg-home - resize2fs /dev/mapper/localhost--vg-home 200G - will warn if specified size is smaller than actual data - lvreduce -L -10GB /dev/mapper/localhost--vg-home - resize2fs /dev/mapper/localhost--vg-home - grow root - lvextend -L +10GB /dev/mapper/localhost--vg-root - e2fsck /dev/mapper/localhost--vg-root - resize2fs /dev/mapper/localhost--vg-root