Monday, 18 November 2013

How to reduce LVM

Be careful while reducing LVM, or else their may be a chance of file system get corrupt.

Do this simple technique when you are reducing LVM, leave 10% free when you are reducing say if you are reducing 100GB to 60GB reduce, and when you are reszing leave 10% of 60 = 6 and now 60-6=54. First resize to 54M then reduce to 60M. Check another example,

total space say 300gb and we need the final size after resize to be 200gb then replace 200gb 's 90%  ie, 10*200 / 100 = 20 200-20 = 180Gb. ie, use the 10% ie, use this 180GB when resize the volume and use the correct size(200GB) that we need when reducing the the lvm,

# umount mount point

Check the file system
# e2fsck -f /dev/vgname/lvname

here lvm size is 900MB and need to reduce it to 750MB, then find the 10% of 750Mb ie, 10*750 / 100 = 75 then 750-75=675. so re-size using 675

# resize2fs /dev/vgname/lvname 675M

# lvreduce -L 750M /dev/vgname/lvname

# mount mountPoint


# umount /lvm-ctechz

# e2fsck -f /dev/vg-ctechz/lvm-ctechz

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
/dev/vg-ctechz/lvm-ctechz: 12/122880 files (8.3% non-contiguous), 142573/230400 blocks

# resize2fs /dev/vg-ctechz/lvm-ctechz 675M

resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg-ctechz/lvm-ctechz to 172800 (4k) blocks.
The filesystem on /dev/vg-ctechz/lvm-ctechz is now 172800 blocks long.

# lvreduce -L 750M /dev/vg-ctechz/lvm-ctechz

  Rounding up size to full physical extent 752.00 MB
  WARNING: Reducing active logical volume to 752.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvm-ctechz? [y/n]: y
  Reducing logical volume lvm-ctechz to 752.00 MB
  Logical volume lvm-ctechz successfully resized

# mount /dev/vg-ctechz/lvm-ctechz /lvm-ctechz/

# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg-ctechz/lvm-ctechz
  VG Name                vg-ctechz
  LV UUID                jZEuoN-16MG-30eX-SZaI-8ETO-ZguH-YRVyeN
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                752.00 MB
  Current LE             188
  Segments               2
  Allocation             inherit
   Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

[root@localhost ~]# lvs
  LV         VG        Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lvm-ctechz vg-ctechz -wi-ao 752.00M

So we successfully reduce our lvm of 900MB to 750MB.

1 comment:

  1. Just wish to say your article is as astonishing. The clarity in your post is simply cool
    and i could assume you're an expert on this subject.
    Well with your permission allow me to grab your RSS feed to keep up to date
    with forthcoming post. Thanks a million and please carry on the gratifying work.

    my web-site; dimitry Van Nuys