Recently needed to free up more space on my RHEL /root LVM partition; and given disks are at a premium currently and i actually dont have any spare drive bays (too many disks!) i needed to pinch some drive space from /home and move to /root to allow me to continue my Piwigo server.
So, the situation:
[root@rhelserver /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_rhelserver-lv_root 50G 44G 2.8G 95% /
/dev/mapper/vg_rhelserver-lv_home 50G 5G 45G 5% /
The plan is to take that spare 40G, and add it to my /root LVM. So, first things first, back up /home (stick it in a tar ball on seperate server/drive somewhere). Once done, “umount /home” (as root). This will likely fail, as mine has lots of open files. So run “lsof | grep /home” and begin shutting things down (such as SABnzbd, ps3mediaserver, etc for example). Other things you may need to kill, using “ps aux | grep /home” and then using “kill -9 pid” where pid is the number, i.e. 11457.
Once /home is successfully unmounted, we can begin our shrink. Im going to shrink mine to 10GB, so firstly, we need to:
1. e2fsck -f /dev/mapper/vg_rhelserver-lv_home
This forces a fsck on the volume; resize2fs wont run otherwise.
2. resize2fs /dev/mapper/vg_rhelserver-lv_home 8G
Shrink it to something smaller than your destination size; i did this on recommendation of a guide i can no longer find, mentioning Base2 vs Base10 issues in resizing.
3. lvreduce -L 10G /dev/mapper/vg_rhelserver-lv_home
Almost done, reduce the logical volume to the size you intend, i.e. 10GB.
4. resize2fs /dev/mapper/vg_rhelserver-lv_home
This will complete the resizing. Now, if you “mount /home”, and run “df -h”, your new /home logical volume of 10GB is active and mounted. However, now your “vgs” output will show a spare 40GB (or so), that needs to be added to root.
5. lvextend -L 90G /dev/mapper/vg_rhelserver-lv_root
Add together the exisiting size (50GB) plus the free space (40GB) to give you the DESIRED root logical volume size. We are specifying the end-size here, NOT how much we want to grow it by.
6. resize2fs /dev/mapper/vg_rhelserver-lv_root 90G
Finally, resize the root volume, and hey presto:
lv_home vg_rhelserver -wi-ao-- 10.00g lv_root vg_rhelserver -wi-ao-- 90.00g
[root@rhelserver /]# df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_rhelserver-lv_root 89G 44G 41G 53% /
/dev/mapper/vg_rhelserver-lv_home 9.9G 4.1G 5.4G 44% /home