THANKS TO Bill Hamilton and sonassi for sharing Very IMP doc.
When shrinking, you should perform actions in this order •Resize the file system •Resize the logical volume When growing, you should perform actions in this order •Resize the logical volume •Resize the file system
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
As I had already created some users, I had directories under /home. I moved these to my backup drive using: mv -r * /bkup
With /home now empty, I unmounted it:
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
[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
[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
[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/homecp -r * /home
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.