Resize root LVM and FS in Debian 7

7,147

Solution 1

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!

Solution 2

Ignore the first "rootfs" entry, the real mount is shown by the /dev/mapper/APP05-root line.

To reduce filesystem size, first shrink the filesystem size with resize2fs, and then use lvresize to reduce the device size. To increase the size, use the utilities in reverse order.

Reducing the filesystem size needs to be done while the filesystem is not mounted. Increasing the filesystem size can be done online (while the filesystem is mounted).

Share:
7,147

Related videos on Youtube

Cosmin
Author by

Cosmin

Updated on September 18, 2022

Comments

  • Cosmin
    Cosmin over 1 year

    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?

  • Cosmin
    Cosmin over 9 years
    Thank you for your quick response, I really appreciate it!! So I tried to figure out the commands I need to execute. Is this right? resize2fs /dev/mapper/APP05-home 2G lvresize --size 2G /dev/mapper/APP05-home lvresize --size 17,2G /dev/mapper/APP05-root resize2fs /dev/mapper/APP05-root 17,2G I'm not sure for the part "Reducing the filesystem size needs to be done while the filesystem is not mounted." Do you mean I have to unmount the "home" filesystem before?
  • wurtel
    wurtel over 9 years
    Be careful with the resizing, if you resize the filesystem to 2G then I think the LVM volume needs to be a little bit bigger due to filesystem overhead. I usually err on the safe side and would resize the LVM volume to 2.1G, and then resize the filesystem again to fill the available space. And yes, you need to umount the home filesystem before doing the shrinking.
  • wurtel
    wurtel over 9 years
    Use a decimal point instead of comma, I don't expect 17,2G to work. I might be surprised though :-) Also mount /home again once you're finished with resizing that and before you start working on the root filesystem.
  • wurtel
    wurtel over 9 years
    As I suggested, I'd shrink the filesystem to a little bit less, e.g. 1.9G and then use lvresize to shrink the device to 2G, and then use resize2fs to expand to the available space; this is exactly as suggested in the stackexchange topic you link to.
  • Cosmin
    Cosmin over 9 years
    Thanks so much for all your help. I included all the remarks in the "7 points" script. It should be ok now. I also found this blog post which shows a similar situation: pubmem.wordpress.com/2010/09/16/… The main difference I see is that it uses lvreduce -L 40G, and it doesn't care about the filesystem overhead). And also, it uses lvextend -l +100%FREE to extend the second partition, without exactly specifying the size (but making sure to occupy all the free space). Is this a better approach, or should I stick to what I have?
  • geedoubleya
    geedoubleya over 9 years
    If you are unable to unmount the partition, either use lsof for find out which processes are using the mount and stop them, or do all the work at single user level, although you may lose paste functionality depending on how your console is configured.
  • frostschutz
    frostschutz over 9 years
    The size you give resize2fs should include any overhead already, otherwise results would be unpredictable. So using 2G both for resize2fs and lvresize should fit perfectly. - I used to do the same though for partitions with odd sizes. Also there is the general G/GB/GiB confusion... not all commands use the same units unfortunately. But it should be fine here...