How to resize an encrypted disk (LUKS encryption)?
Hi guys,
How can we resize a disk that is fully encrypted?
Through the "normal" way I promptly got the message: "Error determining filesystem blocksize" (as expected). I tried to search around in Linode documentation but i didn't found any answer for this case.
I know we can indeed resize an encrypted partition, tough i'm not sure how to proceed within Linode setup/configuration.
The disk that I want to resize represents the database partition of my system that is fully encrypted with LUKS encryption. I'm now in need of more space and I still have around 48% to be allocated.
Does anyone know how should I proceed?
Note: I'm using CentOS 7.
Thanks in advance.
Best regards,
J
2 Replies
Make sure you have a backup before trying.
Assuming that you are using LUKS with ext4, and partition has already been extended.
If partition not extended, then first extend it:
parted /dev/xxx
. > resizepart {partnumber} END
I don't recollect precisely, but I think this should do.
cryptsetup resize cryptname
resize2fs /dev/mapper/cryptname
If you are using LVM in LUKS, then:-
pvresize /dev/mapper/cryptname
lvresize -l+100%FREE /dev/vgname/lvname
e2fsck -f /dev/vgname/lvname
resize2fs /dev/vgname/lvname
You may have to unlock LVM, after pvresize:-
pvchange -x -y /dev/mapper/cryptname
... #after lvresize
pvchange -x n /dev/mapper/cryptname
Thank you for the feedback, @bountysite! and sorry for my late reply!
Although my doubt it's before these steps.
Let me try to add more detail to my case.
I want to resize my /dbdocs partition which was encrypted with LUKS with ext4 (as you guessed).
lsblk command of my instance:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdd 8:48 0 96.9G 0 disk
└─backups 251:0 0 96.9G 0 crypt /backups
sdb 8:16 0 160M 1 disk
└─sdb1 8:17 0 160M 1 part
sde 8:64 0 46.7G 0 disk
└─dbdocs 251:1 0 46.7G 0 crypt /dbdocs
sdc 8:32 0 260M 0 disk [SWAP]
sda 8:0 0 23.8G 0 disk /
In Linode Manager the dbdocs disk was defined as 47808MB.
My usage storage quota in my instance is 52%, meaning that I can still allocate 48% more.
My doubt is, since through the "normal" way I can't resize the disk (since it's an encrypted disk), how can I add this extra space/make this extra space available for the specific disk (through the command line?)?
If my thinking is correct, only after making this space available we can proceed to resize procedure.
Thanks once again.
Best regards,
J