You are not logged in.
After realizing that my root partition was way to big and my /home partition way to small, I decided to go about resizing them. "Easy!", I thought. "With LVM it should be a breeze!". Well it turns out it was not so. I can't figure out how to resize an LVM partition with a LUKS partition in it. I had originally followed the instructions from the arch wiki here to create a LUKS on LVM setup. Currently it looks like this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 119,2G 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 118,8G 0 part
├─lvm-lvroot 254:0 0 40G 0 lvm
│ └─cryptoroot 254:5 0 40G 0 crypt /
├─lvm-var 254:1 0 20G 0 lvm
│ └─var 254:6 0 20G 0 crypt /var
├─lvm-tmp 254:2 0 20G 0 lvm
│ └─tmp 254:7 0 20G 0 crypt /tmp
├─lvm-swap 254:3 0 8G 0 lvm
│ └─swap 254:8 0 8G 0 crypt [SWAP]
└─lvm-home 254:4 0 30,8G 0 lvm
└─home 254:9 0 30,8G 0 crypt /home
sr0 11:0 1 496,7M 0 rom where lvm-lvroot is the root partition and lvm-home is the home partition. Both are separate LUKS encrypted partitions also. How do I safely shrink lvm-lvroot without losing any data, and grow lvm-home?
Thanks!
Last edited by GiorgianB (2018-01-15 16:20:35)
Offline
Hello,
When you have a stacked filesystem (LVM + LUKS + EXT, ...) you grow from the outer block to the inner block and you shrink from the inner block to the outer block.
In your case (I will suppose your partitions are ext4 formatted) :
Before any operation do a backup of your system to an external disk
You grow lvm-home at lvm logical level
You grow lvm-home at cryptsetup level
You grow lvm-home at ext4 level
The link provided for cryptsetup resize is for an LVM-on-LUKS setup. It is just for you to see which command to use for cryptsetup.
Also, unless you have very good reasons to do it, the next time I would advise to setup LVM on LUKS instead of LUKS on LVM: You would not need to resize at cryptsetup level in such case (and you have only one password to setup for your root filesystem).
Last read the man pages of cryptsetup, resize2fs and lvresize to make sure you understand what you are doing and adapt the examples on the wiki with your real case.
Offline
One thing to take particular note of is that the LUKS header uses 2MiB or so.
So with LUKS on top of LVM, if you shrink the filesystem to 20G, and shrink the LUKS to 20G, the LV needs to be 20G + 2MiB.
If you'd rather have the LV to be 20G even, you need to shrink both filesystem and LUKS to 20G - 2 MiB.
Another approach is to shrink the filesystem considerably more than necessary (e.g. to 15G), then shrink the LV without worries to 20G, cryptsetup resize (or close/open), and then finally grow the filesystem again to whatever size it came out as. However if you know what you're doing, and don't confuse GiB (1024) vs. GB (1000) units, these extra steps are unnecessary.
----
In your case one thing that stands out is that you have given 20G to /tmp which should usually not be larger than a few kilobytes, a lot of people just go with tmpfs for /tmp these days, so you could simply take those 20G as a whole to add to your home. That is unless you know you have an application that wantonly puts gigs of trash in /tmp.
Last edited by frostschutz (2018-01-15 09:05:45)
Offline
Thanks. What I was doing wrong was I was doing cryptsetup resize THEN resize2fs, instead of the other way around. In retrospect your way makes much more sense. Thanks!
Offline
Please mark your post as [SOLVED] once actually solved.
Offline