I recently installed RHEL6 and while I selected the option to use all disk space at the time of installation, I did not customize the partitions. The system has two 1TB drives and after installation, the logical volume of the first drive was partitioned to (ignoring the small swap area):
- 857.5G for /home
50G for /root
I use Oracle 11g, MySQL, PostgreSQL, Apache, Tomcat and a host of other applications. The databases I work with can consume 50G in a heartbeat, so resizing was called for. After some research online, I was able to put together the necessary steps to resize the logical volume. My goal was to come out with 807.5G for /root and 50G for /home. NOTE: My fall back position was to reinstall if anything went wrong with the resizing. You may wish to perform a backup of more than just your /home sub-directories or prepare for possible recovery in your chosen way (e.g. tarballs of important files). Increasing the /root logical volume was not destructive, but decreasing /home was. As always, this is what worked for me and while I would hope it can act as a guide for others, follow at your own risk.
STEP 1: Prepare for the resizing
Clearing /home
As I had already created some users, I had directories under /home. I moved these to my backup drive using: mv -r * /bkup
Unmounting /home
With /home now empty, I unmounted it: umount /home
STEP 2: Resize /home
Checking the /home partition
My logical volume is named redhatweb-lv. I used the following to first check the /home partition:
e2fsck -f /dev/mapper/vg_redhatweb-lv_home
This returned:
[root@redhat-web /]# e2fsck -f /dev/mapper/vg_redhatweb-lv_home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg_redhatweb-lv_home: 11/57098240 files (0.0% non-contiguous), 3634829/228381696 blocks
Resizing the /home filesystem
After everything checked out, I used the following to resize the /home partition to the much smaller 50G: resize2fs /dev/mapper/vg_redhatweb-lv_home 50G
This returned:
[root@redhat-web /]# resize2fs /dev/mapper/vg_redhatweb-lv_home 50G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_redhatweb-lv_home to 13107200 (4k) blocks.
The filesystem on /dev/mapper/vg_redhatweb-lv_home is now 13107200 blocks long.
Reducing the /home logical volume
The filesystem for /home was now 50G, but the logical volume was still 857.5G. To size the logical volume to the same size as the filesystem, I used:
lvreduce -L 50G /dev/mapper/vg_redhatweb-lv_home
This returned (after answering ‘y’ to the prompt below):
[root@redhat-web /]# lvreduce -L 50G /dev/mapper/vg_redhatweb-lv_home
WARNING: Reducing active logical volume to 50.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Reducing logical volume lv_home to 50.00 GiB
Logical volume lv_home successfully resized
STEP 3: Resize /root
Extending the /root logical volume
With a 50G /home partition, I should have room for an 857.5G /root partition (857.5G to start less the 50G I finished with should give me 807.5G to add to the 50G /root partition). I first took 857.5G less the new size of 50G and tried to increase the /root partition to 857.5G (the original size of 50G + the 807.5G gained by shrinking /home). The effort was rewarded with an error that there was insufficient room, so I backed off to a nice round number of 850G.
I used the following to resize the /root logical volume:
lvextend -L 856.7G /dev/mapper/vg_redhatweb-lv_root
This returned:
root@redhat-web /]# lvextend -L 856.7G /dev/mapper/vg_redhatweb-lv_root
Rounding up size to full physical extent 856.70 GiB
Extending logical volume lv_root to 856.70 GiB
Logical volume lv_root successfully resized
Resizing the /root file system
As before, the filesystem also had to be resized, but in this case, by increasing it. I used the following:
resize2fs /dev/mapper/vg_redhatweb-lv_root 850G
The above returned:
[root@redhat-web /]# resize2fs /dev/mapper/vg_redhatweb-lv_root 850G
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_redhatweb-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 54
Performing an on-line resize of /dev/mapper/vg_redhatweb-lv_root to 222822400 (4k) blocks.
The filesystem on /dev/mapper/vg_redhatweb-lv_root is now 222822400 blocks long.
STEP 4: Restore /home and test
Restoring /home directories
After resizing, I copied back the user directories that I had backed up on my second drive:
cd /bkup/home
cp -r * /home
Testing
At this point, I rebooted the system and checked to see if all services started. Some, as in Oracle, were dependent on a user directory under /home. After rebooting, my services were started and I was able to log into each of the databases I use. I have seen no ill effect from the above efforts and have well exceeded the 50G initially allocated to /root without additional problems.
Thanks for this post, it helped a lot! We recently got a new CentOS 6 server and the partitions were configured exactly how you got yours…50G on / and everything else on /home. I barely use the /home directories though and most of data sits in /var dirs. These instructions worked exactly and everything is running smooth! Appreciate the blogpost!
Thank You! I am new to Linux so I have been getting a crash course in Red Hat. I used the install guides to install RHEL 6.3 and Tenable Security Center. I happened to look at the partition sizes and home had all the free space. Your simple steps took the guess work out of RHEL convoluted solutions. All the software is installed in /opt. I had no problems unmounting home, re-sizing and everything worked after the server was rebooted. This is the solution I was looking for. I so appreciate the blogpost!
Glad it helped and glad to see you’re picking up Red Hat!
Bill
Thank you so much! I used your steps at my work and it worked perfectly.
I didn’t really have to move user folders in home directory but to be safe I copied to a backup location.
Only thing is that I forgot to mention to mount home at step 4. I don’t home directory will re-mount when it rebotts but I just mount home manually.
Nice work!
Austin
Bill,
Excellent guide. We received six new RHEL 6 computers with only 50G root partitions, too small for our needs, and were able to expand them by grabbing 100G from the logical volume with /home on it. Thanks.
These instructions are spot on.
I got to this post by searching Googling “lvextend root 50G”.
50G root partition seems to be the default for CentOS installs. We use Parallels PPA / Plesk and these servers don’t require a big /home partition, rather a large / partition would have been better.
I also didn’t have to back up data and simply remounted /home and saw all data was still intact. It appears one doesn’t have to specify the size when using resize2fs, from the manual: “If size parameter is not specified, it will default to the size of the partition.”. I did however succeed by using the same size on both the ‘lvextend’ and ‘resize2fs’ commands.
THANK YOU! I am not a linux administrator, so I was struggling with this until I found your link. This worked perfectly for me!!!!