Wednesday, February 5, 2014

Reduce LV and File System

At some point you may need to free up some LV space, but you will also need to reduce the underlying filesystem too.  Here's what to do...

Check the current space usage and see if any can be used:-

[root@sbt-centos ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_sbtcentos-lv_root
                       50G  3.9G   43G   9% /
tmpfs                 940M  372K  939M   1% /dev/shm
/dev/sda1             485M   91M  369M  20% /boot
/dev/mapper/vg_sbtcentos-lv_home
                       45G  3.6G   40G   9% /home
/dev/mapper/vg_sbtcentos-lv_data
                      985M   18M  918M   2% /data



Check the LV:-
 
[root@sbt-centos ~]# lvs
  LV      VG           Attr      LSize    Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_data vg_sbtcentos -wi-ao--- 1000.00m                                            
  lv_home vg_sbtcentos -wi-ao---   45.57g                                            
  lv_root vg_sbtcentos -wi-ao---   50.00g                                            
  lv_swap vg_sbtcentos -wi-ao---    3.94g                                            



It looks like /data has some free, lets reduce that.  Unmount it first:-

[root@sbt-centos ~]# umount /data/


Do an lvreduce, but don't forget the -r, this will resize the underlying filesystem at the same time:-

[root@sbt-centos ~]# lvreduce -L -512M /dev/vg_sbtcentos/lv_data -r
fsck from util-linux-ng 2.17.2
/dev/mapper/vg_sbtcentos-lv_data: 11/64000 files (0.0% non-contiguous), 8438/256000 blocks
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_sbtcentos-lv_data to 124928 (4k) blocks.
The filesystem on /dev/mapper/vg_sbtcentos-lv_data is now 124928 blocks long.

  Reducing logical volume lv_data to 488.00 MiB
  Logical volume lv_data successfully resized


Remount the filesystem:-
 
[root@sbt-centos ~]# mount /dev/vg_sbtcentos/lv_data /data/

And check space usage:-

[root@sbt-centos ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_sbtcentos-lv_root
                       50G  3.9G   43G   9% /
tmpfs                 940M  372K  939M   1% /dev/shm
/dev/sda1             485M   91M  369M  20% /boot
/dev/mapper/vg_sbtcentos-lv_home
                       45G  3.6G   40G   9% /home
/dev/mapper/vg_sbtcentos-lv_data
                      481M   17M  439M   4% /data
[root@sbt-centos ~]# lvs
  LV      VG           Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_data vg_sbtcentos -wi-ao--- 488.00m                                            
  lv_home vg_sbtcentos -wi-ao---  45.57g                                            
  lv_root vg_sbtcentos -wi-ao---  50.00g                                            
  lv_swap vg_sbtcentos -wi-ao---   3.94g  




No comments:

Post a Comment