How to 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 partition.

Before adjustment we have 98% filled root partition and 141GB free space on /home, which we would like to use:

[[email protected] ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_test-lv_root

                       50G   1G   50G  98% /

tmpfs                 630M     0  630M   0% /dev/shm

/dev/cciss/c0d0p1     477M  106M  346M  24% /boot

/dev/mapper/vg_test-lv_home

                      149G   60M  141G   1% /home

1. First step is to unmount /home partition

umount /home

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)

e2fsck -f /dev/mapper/vg_test-lv_home

resize2fs /dev/mapper/vg_test-lv_home 20G

3. Reduce the LVM to 20G

lvreduce -L 20G /dev/mapper/vg_test-lv_home

4. Extend /root LVM to new size, utilizing 100% of free space on disk

lvextend -l +100%FREE /dev/mapper/vg_test-lv_root

5. Grow /root (ext3/4) partition to new LVM size

resize2fs /dev/mapper/vg_test-lv_root

6. Mount /home

mount /home

Result

[[email protected] ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vg_test-lv_root

                      178G   50G  128G  28% /

tmpfs                 630M     0  630M   0% /dev/shm

/dev/cciss/c0d0p1     477M  106M  346M  24% /boot

/dev/mapper/vg_test-lv_home

                       20G   45M   19G   1% /home

 

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

 

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


umount /home

e2fsck -f /dev/mapper/vg_test-lv_home

resize2fs /dev/mapper/vg_test-lv_home 20G

lvreduce -L 20G /dev/mapper/vg_test-lv_home

lvextend -l +100%FREE /dev/mapper/vg_test-lv_root

resize2fs /dev/mapper/vg_test-lv_root

mount /home

 

If you're looking for a place to host your website or application please take a moment to check us out, we offer cPanel Web Hosting, Reseller, Cloud VPS and Dedicated (bare metal) servers: https://owned-networks.net

  • LVM, resize
  • 8 Users Found This Useful
Was this answer helpful?

Related Articles

ownCloud Auto Install Script on Debian 7

Here is an easy way to install ownCloud on Debian 7 with a script, but first, for those who...

NGINX – Allow access only to certain IPs

Nginx has a nice module that not many people know about, it basically enables us...

How to configure NTP client in CentOS

What's NTP? NTP stands for Network Time Protocol, and it is an Internet protocol used to...

Initial Server Setup on CentOS 6

Here are some recommendations to setup your VPS or server when you first get it, some of these...

How To Install nginx on CentOS

What is NGINX? Nginx (pronounced "engine-x") is an open source reverse proxy server for HTTP,...