Resizing Logical Volume (LVM) on ext3 – openSUSE SLES RedHat – Extend Shrink Reduce

There are a few steps you have to take to resize a partition. First, you have to resize the filesystem (be sure to do this before you reduce the lv, as that could cause data loss).

In this instance I’ll be resizing a mount location at /app. If you want to shrink the /home partition make sure you go into runlvl 3 (sudo init 3) and get out of the /home directory (cd /).

To shrink the file system lets unmount it by running:

sudo umount /apps

First run a check on the file system:

sudo fs2chk -f /dev/volumegroup/logicalvolume

note: you can find the volume group name, or logical volume name you can use vgscan and lvscan (both are located in /sbin/)

Now lets shrink the ext3 partition:

sudo resize2fs /dev/volumegroup/logicalvolume 10G

note: 10G is the NEW size that you want it to be

Once those are completed, you can finally shrink the Logical Volume (isn’t this what we wanted in the first place?), to do this do:

sudo lvreduce -L 10G /dev/volumegroup/logicalvolume

note: Use the same output you defined in the resize2fs command.

Here are some extra usages of lvreduce via the man page

-l, –extents [-]LogicalExtentsNumber[%{VG|LV|FREE}]
Reduce or set the logical volume size in units of logical extents. With the – sign the value will be subtracted from the logical volume’s actual size and without it the will be taken as an
absolute size. The number can also be expressed as a percentage of the total space in the Volume Group with the suffix %VG or relative to the existing size of the Logical Volume with the suf-
fix %LV or as a percentage of the remaining free space in the Volume Group with the suffix %FREE.

-L, –size [-]LogicalVolumeSize[kKmMgGtTpPeE]
Reduce or set the logical volume size in units of megabyte by default. A size suffix of k for kilobyte, m for megabyte, g for gigabytes, t for terabytes, p for petabytes or e for exabytes is
optional. With the – sign the value will be subtracted from the logical volume’s actual size and without it it will be taken as an absolute size.

Lets remount our partition and jump for joy:

sudo mount /dev/volumegroup/logicalvolume /app

note: If this mount point is defined in /etc/fstab, you can remount via sudo mount -a (this will mount everything in /etc/fstab).

To extend a Logical Volume (this can be done in real time and no un-mounting is required)
First lets extend the logical volume

sudo lvextend -L+10G /dev/volumegroup/logicalvolume

Here are more usages of lvextend from the man pages:

-l, –extents [+]LogicalExtentsNumber[%{VG|LV|PVS|FREE}]
Extend or set the logical volume size in units of logical extents. With the + sign the value is added to the actual size of the logical volume and without it, the value is taken as an absolute
one. The number can also be expressed as a percentage of the total space in the Volume Group with the suffix %VG, relative to the existing size of the Logical Volume with the suffix %LV, of
the remaining free space for the specified PhysicalVolume(s) with the suffix %PVS, or as a percentage of the remaining free space in the Volume Group with the suffix %FREE.

-L, –size [+]LogicalVolumeSize[kKmMgGtTpPeE]
Extend or set the logical volume size in units of megabytes. A size suffix of M for megabytes, G for gigabytes, T for terabytes, P for petabytes or E for exabytes is optional. With the + sign
the value is added to the actual size of the logical volume and without it, the value is taken as an absolute one.

-i, –stripes Stripes
Gives the number of stripes for the extension. Not applicable to LVs using the original metadata LVM format, which must use a single value throughout.

-I, –stripesize StripeSize
Gives the number of kilobytes for the granularity of the stripes. Not applicable to LVs using the original metadata LVM format, which must use a single value throughout.
StripeSize must be 2^n (n = 2 to 9)

To extend the filesystem do

sudo ext2online /dev/volumegroup/logicalvolume

note: this can be done in real time

Bonus:
If you wanted this space for an existing logical volume, you can run lvextend -L XXG /dev/volumegroup/logicalvolume.
Note: XX is the space you took away from the other reduced partition.


1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

About ben.kevan

I am ben kevan.. Well yeah. .that's about it.

3 Comments

  • Dapid Candra
    January 13, 2010 | Permalink |

    Hi,

    I see that you only mention about reducing the lv.

    I tried to extend one of my lv. and using lvdisplay, I can see that the size already extend. (from 250GB t0 390GB). But, using df I can only see 250GB (the original size). What is wrong? and what should I do?

    This is out put from df -h

    /dev/mapper/VolGroup00-LogVol06
    250G 231G 7.2G 97% /oracle

    and this is output from lvdisplay

    — Logical volume —
    LV Name /dev/VolGroup00/LogVol06
    VG Name VolGroup00
    LV UUID 1AVRAH-nZaV-Vvia-26Ev-REdh-T0KT-KPBNsS
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 390.66 GB
    Current LE 12501
    Segments 3
    Allocation inherit
    Read ahead sectors 0
    Block device 253:2

    Thanks,

    Dapid Candra

  • January 13, 2010 | Permalink |

    @Dapid Candra

    Thanks for the comment. If you’ve already ran lvextend then what you’ll want to do is do an ext2online /dev/mapper/VolGroup00-LogVol06

    Which will extend the actual filesystem to the new size which is indicated via the lvdisplay.

    Let me know if you have any questions.

  • Dapid Candra
    January 14, 2010 | Permalink |

    Your tips is the exact solution for the problem. I just run it and after finish df result show the size already 385GB.

    There is discrepancy between lvdisplay size information and df, but comparing to other mount points (other lvs), the difference is common.

    Thank you Sir.

2 Trackbacks

Leave a comment

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Your email is never shared. Required fields are marked *