Debian 7 LVM Resize – How to Resize Root LVM and Filesystem

debianlinuxlvmpartitionroot

I have a Debian server and I would like to increase the "root" partition from 5GB to 17GB and to diminish the "home" partition from 14GB to 2GB.

Here's the filesystem config:

root@APP05:~# df -T
Sys. fich.                    Type     1K-blocks   Util. Disponible Uti% Monté sur
rootfs                        rootfs     5354080 1388664    3693444  28% /
udev                          devtmpfs     10240       0      10240   0% /dev
tmpfs                         tmpfs       205416     168     205248   1% /run
/dev/mapper/APP05-root        ext4       5354080 1388664    3693444  28% /
tmpfs                         tmpfs         5120       0       5120   0% /run/lock
tmpfs                         tmpfs       410820       0     410820   0% /run/shm
/dev/sda1                     ext2        233191   17794     202956   9% /boot
/dev/mapper/APP05-home        ext4      14360944  166712   13464736   2% /home

I googled for some answers, read a couple of Q&A on several forums but I'm not sure what are the right commands to achieve this. From what I understand, "/dev/mapper/APP05-root" is an LVM, so extending it's size needs to be done after extending "rootfs" size, which is a filesystem.

Can you please tell me how I should proceed?

Best Answer

So, based on @wurtel's answer and the research I've done, here's the script and the steps I came up with.

1) Unmount the "home" partition
umount /dev/mapper/APP05-home

2) Resize the "home" filesystem to a size of 2G
resize2fs -p /dev/mapper/APP05-home 2G

3) Reduce the size of the "home" logical volume to 2,1G (the volume needs to be a little bit bigger due to filesystem overhead)
lvresize --size 2,1G /dev/mapper/APP05-home

4) Resize the filesystem to match the logical volume's size
resize2fs -p /dev/mapper/APP05-home

5) Mount back the "home" partition
mount /dev/mapper/APP05-home /home

6) Increase the size of the "root" logical volume to 17.2G
lvresize --size 17.2G /dev/mapper/APP05-root

7) Increase the "root" filesystem to a size of 17.2G
resize2fs -p /dev/mapper/APP05-root 17.2G

UPDATE : I actually replaced points 6) and 7) with the followings in order to not have to specify the "root" size exactly, but to extend to all the free space
lvextend -l +100%FREE /dev/mapper/APP05-root
resize2fs -p /dev/mapper/APP05-root

This solution is inspired also from the questions: Repartitioning harddisk and http://pubmem.wordpress.com/2010/09/16/how-to-resize-lvm-logical-volumes-with-ext4-as-filesystem/

UPDATE: This solution worked and the result is the following
root@APP05:~# df -h Sys. fich. Taille Util. Dispo Uti% Monté sur rootfs 17G 1,4G 15G 9% / udev 10M 0 10M 0% /dev tmpfs 201M 168K 201M 1% /run /dev/mapper/APP05-root 17G 1,4G 15G 9% / tmpfs 5,0M 0 5,0M 0% /run/lock tmpfs 402M 0 402M 0% /run/shm /dev/sda1 228M 18M 199M 9% /boot /dev/mapper/APP05-home 2,1G 149M 1,9G 8% /home

Thanks again for all the answers, especially to @wurtel!

Related Question