Monday 30 March 2015

CentOS / RHEL Disk space re-sizing / Reallocation


Disk space rallocation in Linux-RHEL/CentoOS

Reducing the size of the /home/ from 500GB to 50GB and allocating it /root
 
scenario :
[root@cloud ~]# df -h /home/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cloud-LogVol00
                             12G  9.2G  1.9G  84% /home

Follow the steps :


Step 1:
unmount the the /home

[root@openstack ~]# umount /home/
Step 2:
check the filesystem for Errors using e2fsck command.
[root@openstack ~]# e2fsck -f /dev/mapper/vg_openstack-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_openstack-lv_home: 11/3276800 files (0.0% non-contiguous), 251699/13107200 blocks
[root@openstack ~]#
Note: In the above command e2fsck , we use the option '-f' to forcefully check the filesystem , even if the filesystem is clean.

Step 3:
Shrink the size of /home to desire size.
[root@openstack ~]# resize2fs /dev/mapper/vg_openstack-lv_home 50G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/vg_openstack-lv_home to 13107200 (4k) blocks. The filesystem on /dev/mapper/vg_openstack-lv_home is now 13107200 blocks long.
Step 4:
Now reduce the size using lvreduce command.
[root@openstack ~]# lvreduce -L 50G /dev/mapper/vg_openstack-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 5:
For the safer side , now check the reduced filesystem for errors
 
[root@openstack ~]# e2fsck -f /dev/mapper/vg_openstack-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_openstack-lv_home: 11/3276800 files (0.0% non-contiguous), 251699/13107200 blocks [root@openstack ~]#


Step 6:  
 Mount the file system and verify the size.



[root@openstack ~]# mount /home/
[root@openstack ~]# df -kh
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/vg_openstack-lv_root   50G  6.0G   41G  13% /
tmpfs                              16G  228K   16G   1% /dev/shm
/dev/sda1                         485M   40M  420M   9% /boot
/dev/mapper/vg_openstack-lv_home   50G  180M   47G   1% /home


Step 7:

Resize the desired partition with required space

lvextend -L 75G /dev/mapper/vg_openstack-lv_root
resize2fs /dev/mapper/vg_openstack-lv_root

check the sze of the partion changes 
df -kh


and you done resizing the partition.

No comments:

Post a Comment