Sunday, March 27, 2011

To srhink /local by 1GB on linux RHEL v5 with LVM/resize2fs.

Goal: To srhink /local by 1GB on linux RHEL v5 with LVM/resize2fs.

1* Requirement:- Need to un-mount fs before we can shrink

[root@server ~]# df -h /local
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol06
                      104G  188M  104G   1% /local

[root@server ~]# umount /local/
[root@server ~]# e2fsck -f /dev/VolGroup00/LogVol06
e2fsck 1.39 (29-May-2006)
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
/local: 11/13844480 files (9.1% non-contiguous), 482513/27672576 blocks
[root@server ~]# lvdisplay /dev/VolGroup00/LogVol06
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol06
  VG Name                VolGroup00
  LV UUID                8R6U7b-tKOY-Wqbt-2BKn-u3nN-Yxl9-0LTvZE
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                105.56 GB
  Current LE             3378
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5

[root@server ~]# resize2fs /dev/VolGroup00/LogVol06 104G  Reduce to 104G because lvdisplay shows LV Size is actually 105.56GB even though df -h shows 104 is the total size.
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/VolGroup00/LogVol06 to 27262976 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol06 is now 27262976 blocks long.

[root@server ~]# mount /local
[root@server ~]# df -h /local
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol06
                      103G  188M  103G   1% /local

[root@server ~]# lvreduce -L -1G /dev/VolGroup00/LogVol06
  WARNING: Reducing active and open logical volume to 104.56 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol06? [y/n]: y
  Reducing logical volume LogVol06 to 104.56 GB
  Logical volume LogVol06 successfully resized
[root@server ~]# df -h /local
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol06
                      103G  188M  103G   1% /local
[root@server ~]# lvdisplay /dev/VolGroup00/LogVol06
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol06
  VG Name                VolGroup00
  LV UUID                8R6U7b-tKOY-Wqbt-2BKn-u3nN-Yxl9-0LTvZE
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                104.56 GB
  Current LE             3346
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5

[root@server ~]# umount /local
[root@server ~]# e2fsck -f /dev/VolGroup00/LogVol06  Verify again filesystem is okay after resize & lvreduce
e2fsck 1.39 (29-May-2006)
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
/local: 11/13631488 files (9.1% non-contiguous), 475831/27262976 blocks

[root@server ~]# df -h /local
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol06
                      103G  188M  103G   1% /local

End result is that size is reduced by 1GB and not 2GB like if we used 103G at the resize2fs parameter.

[root@server ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  13
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                7
  Open LV               7
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               136.56 GB
  PE Size               32.00 MB
  Total PE              4370
  Alloc PE / Size       4338 / 135.56 GB
  Free  PE / Size       32 / 1.00 GB   Verify that 1GB free space left after lvreduce / resize2fs
  VG UUID               18QiUj-1s0O-6qGt-GujM-cPOi-acw1-HVgOUX

0 comments:

Post a Comment

 
;