Online resize LVM partitions – shrink home / extend root

By default, most Linux Installers create separate /home partition, occupying most of the drive space.
When server is used mostly for system services, you may transfer free space from /home partition to /root.

Before adjustment we have 98% filled root partition and 141GB free space on /home, which we would like to use:
[code]
[root@oracle ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_oracle-lv_root
50G 1G 50G 98% /
tmpfs 630M 0 630M 0% /dev/shm
/dev/cciss/c0d0p1 477M 106M 346M 24% /boot
/dev/mapper/vg_oracle-lv_home
149G 60M 141G 1% /home
[/code]

1. First step is to unmount /home partition
[code]
umount /home
[/code]
System may refuse to unmount /home if you have users logged on to the box or services running from /home. After logging off / stopping services command should succeed.

2. Shrink old /home partition to 20GB, (system will force you to check filesystem for errors by running e2fsck)
[code]
e2fsck -f /dev/mapper/vg_oracle-lv_home
resize2fs /dev/mapper/vg_oracle-lv_home 20G
[/code]

3. Reduce the LVM to 20G
[code]
lvreduce -L 20G /dev/mapper/vg_oracle-lv_home
[/code]

4. Extend /root LVM to new size, utilizing 100% of free space on disk
[code]
lvextend -l +100%FREE /dev/mapper/vg_oracle-lv_root
[/code]

5. Grow /root (ext3/4) partition to new LVM size
[code]
resize2fs /dev/mapper/vg_oracle-lv_root
[/code]

6. Mount /home
[code]
mount /home
[/code]

Result
[code]
[root@oracle ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_oracle-lv_root
178G 50G 128G 28% /
tmpfs 630M 0 630M 0% /dev/shm
/dev/cciss/c0d0p1 477M 106M 346M 24% /boot
/dev/mapper/vg_oracle-lv_home
20G 45M 19G 1% /home

[/code]

After these simple steps we have 72% of free disk space of root partition.

TL;DR

Resizing /home partition (/dev/mapper/vg_oracle-lv_home) to 20GB and transfering remaining space to /root (/dev/mapper/vg_oracle-lv_root):

[code]
umount /home
e2fsck -f /dev/mapper/vg_oracle-lv_home
resize2fs /dev/mapper/vg_oracle-lv_home 20G
lvreduce -L 20G /dev/mapper/vg_oracle-lv_home
lvextend -l +100%FREE /dev/mapper/vg_oracle-lv_root
resize2fs /dev/mapper/vg_oracle-lv_root
mount /home
[/code]

13 thoughts on “Online resize LVM partitions – shrink home / extend root

  1. Your heading “_online_ resize…” is misleading because your first
    (and necessary) step is unmounting /home.
    Online shrinking of LVM partitions is not possible.
    I stumbled over this page because I saw “online” and “shrink”
    and thought “Oooh something new I have missed something”.
    🙂 Olaf

  2. Firstly, thanks for the information. Worked perfect for me and now have plenty of room to store under /root folder. Probably would of been easier for me to set the partitions correctly when I installed fedora but hey no-ones perfect…

    Had all sorts of trouble trying to do this on my system to start with because I was logged in.
    Recommend to all to use rescue mode boot from usb/cd. This ensured no users being logged in and no files being used in /home directory. Also means you don’t have to carry out ‘lazy’ umount on /home.

    • This is common error, try following:

      1. change your directory to something not /home (cd /root)
      2. check who is logged in to the box by running who, ask them to log off/ kill their pts process (ps -dN|grep pts/3)
      3. if you have services running from home, stop them

  3. I closely followed the instructions, but have an issue after step 2.
    I successfully (without errors) ran
    e2fsck -f /dev/my_home
    resize2fs /dev/my_home 426G

    The initial size of /home was 436G, so I tried to reduce by about 10G. I still had about 40G free space in /home.

    When I want to run

    lvreduce -L 426G /dev/my_home

    I obtain an error that the location does not exists. Checking with
    df
    shows that /dev/my_home does not exist anymore. Any idea what happened?

Leave a Reply

Your email address will not be published. Required fields are marked *