Skip to content

            Lost ?  |  Need an account:
 
Home >> Knowledge Base >> Operating Systems >> Linux >> LVM Resizing Guide - Grow File System
LVM Resizing Guide - Grow File System PDF Print E-mail
(26 votes, average 4.96 out of 5)
Written by Tom Hirt   
Friday, 15 May 2009 09:02
Article Index
LVM Resizing Guide
Grow File System
Shrink File System
All Pages


Grow File System


Increasing the size of a file system managed with LVM can be done online (with the file system mounted.)  In order to grow the LV and file system:

  • Check to see if free space exists on the LV that contains the file system
  • Expand the LV if it does not contain enough free space (which could require expanding the volume group if it is out of free space)
  • Grow the file system to utilize all available space on the LV
Lets get started!
  1. First, check the size of the file system to see if it needs expanding

    [root@Linux01 ~]# pwd
    /TCPDumpLV
    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem
    Size
    Used Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    3.1G
    2.9G 69M 98% /TCPDumpLV
    Note: The disk free command shows that we have 65MB available on our file system and that its 98% use.  If we don't take action soon, we risk filling the file system.

  2. Let's find out which Volume Group contains the Logical Volume that holds /dev/mapper/TCPDumpVolGRP-TCPDumpLV

    [root@Linux01 ~]# lvdisplay /dev/TCPDumpVolGRP/TCPDumpLV
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name TCPDumpVolGRP
    LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 3.12 GB
    Current LE 100
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5
    Note: You can see the volume group for this file system is TCPDumpVolGRP

  3. Let's find out if the volume group TCPDumpVolGRP has available free space to allocate to the logical volume

    [root@Linux01 ~]# vgdisplay TCPDumpVolGRP
    --- Volume group ---
    VG Name TCPDumpVolGRP
    System ID
    Format lvm2
    Metadata Areas 3
    Metadata Sequence No 5
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 2
    Open LV 2
    Max PV 0
    Cur PV 3
    Act PV 3
    VG Size 11.91 GB
    PE Size 32.00 MB
    Total PE 381
    Alloc PE / Size 228 / 7.12 GB
    Free PE / Size 153 / 4.78 GB
    VG UUID 9fWFIS-vDlg-xOW6-Xmb8-Tkrg-GPZw-ZnUZwh
    Note: This volume group has plenty of free space.  If we were out of physical extents, we would have to add additional physical volumes to this volume group before continuing on.

  4. We will now resize the logical volume TCPDumpLV by adding 3GB

    [root@Linux01 TCPDumpLV]# lvresize -L +3GB /dev/TCPDumpVolGRP/TCPDumpLV
    Extending logical volume TCPDumpLV to 6.12 GB
    Logical volume TCPDumpLV successfully resized
    [root@Linux01 TCPDumpLV]#

  5. Confirm the new size of the logical volume

    [root@Linux01 ~]# lvdisplay /dev/TCPDumpVolGRP/TCPDumpLV
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name TCPDumpVolGRP
    LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 6.12 GB
    Current LE 196
    Segments 2
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5

    [root@Linux01 ~]# pwd
    /TCPDumpLV
    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem
    Size
    Used Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    3.1G
    2.9G 69M 98% /TCPDumpLV

    Note: You will notice that although we have increased the size of the logical volume, the size of the file system has been unaffected.

  6. We now need to resize the ext3 file system to utilize the remaining available space within the logical volume

    [root@Linux01 TCPDumpLV]# resize2fs -p /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    resize2fs 1.39 (29-May-2006)
    Filesystem at /dev/mapper/TCPDumpVolGRP-TCPDumpLV is mounted on /TCPDumpLV; on-line resizing required
    Performing an on-line resize of /dev/mapper/TCPDumpVolGRP-TCPDumpLV to 1605632 (4k) blocks.
    The filesystem on /dev/mapper/TCPDumpVolGRP-TCPDumpLV is now 1605632 blocks long.


    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem
    Size
    Used Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    6.1G
    2.9G 2.9G 50% /TCPDumpLV

Nice work, you just resized your file system while it was online!  Now lets take a look at reducing the size of a file system.

 



Comments
Add New Search
papi |28/11/2009 10:49:12
nice
jay |07/12/2009 00:57:36
great write up. :D

Would also like to know if there's a way to grow the LV to the maximum available without counting it manually and leaving slack.
thirt |14/12/2009 03:20:22
Jay - You could do something like:
Quote:
lvresize -l +100%FREE


That should use up all the remaining free space available in the volume group.

Hope that helps,
Tom
Jean  - resize dynamic disk |14/07/2010 04:33:07
you can expand the dynamic volume.
visit the web page to get more information.--http://www.dynamic-disk.com/resource/resize-dynamic-disk-partition-volume.html
Slippery |21/01/2010 08:35:30
Many thanks indeed for helping out a Windows guru but Linux amateur.

Steve
nicobo |06/02/2010 11:20:52
Thanks for this 'quickstart' tutorial.

I have two remarks :

1. I've found better to use 'lvresize -l' for growing the volume because 'lvresize -L' rounds the given size and therefore does not always end up in what you're expecting

2. In your example I find it a bit confusing to use a size in MB to resize the partition and then a (the same) size in GB to resize the volume. It probably worked for you but I'm not sure it will for everybody (?).
lazymathstudent |18/05/2010 10:07:44
just look at how much space vgdisplay reports in "Free PE / Size". The correct size is A = PE*4MB, which gives lvresize -L +A /dev/mapper/cpool-bla
Alex |18/10/2010 15:16:45
Thanks for this article it helped me a lot.
Nare |24/11/2010 10:08:01
Thnx for this tutorial :)
Bravo |21/01/2011 07:37:01
Wow, what a great and straight forward step by step guide
My gratitude for the writer
MXA |21/01/2011 08:55:55
step by step, great howto :)
Thank you
FooBar  - 1000MB vs 1024MB |06/04/2011 11:07:39
In steps 4 & 5, it looks like you reduce the file system more than you reduce the size of the logical volume. The file system is 1500MB vs 1536 MB (1.5GB) for the volume. Was this intentional to prevent resizing the volume too small? Or do either resize2fs or lvresize use mebibytes instead of megabytes?

Thanks.
Anonymous |29/04/2011 04:27:39
Great stuff buddy!!
BK  - GREAT JOB! |02/06/2011 18:43:24
Thanks to your LVM refresher course in one URL, I was able to remember how LVM functionality actually works, and wrote some documentation for our staff. It's rough, but I felt I should give back given the excellent documentation you've written.

EXPANDING LOGICAL VOLUMES ON A LINUX VM INSTANCE
First, down the server you want to add space to.
From the VM Console, add more virtual disk with more space than you need.
You do NOT want to do this many times, as Logical Volumes (LVM2) have limits.
Bring the VM Instance back online, and login as root.
Next, we need to join the virtual disk free space to the virtual disk itself.
#fdisk /dev/sda (dev/sda is “pseudo-physical” disk drive for the VM instance)
M (to print whole list of options.)
P (to print out the existing partitions)
N (to create new partition, then choose a partition type “p” in this case.)
Choose a partition # - one that is not in use, say 3 or 4.
Let the system choose start points, and to end of disk.
P (print it again, and see what you have created.)
L (to label the partition)
W (Write it to the disk)
Q (Quit. You’ve made space, now to join it to the Volume Group.)

Connect to the website below. This is where the real work begins.
Read through this section once, noting where the PINK/RED highlights are.
They provide the information to use in the next instructional steps!
(Your work above fixes problems in Item #3, when vgdisplay does not have free PE.)

http://www.tcpdump.com/kb/os/linux/lvm-resizing-guide/all-pages.html

Useful command:
lvresize -l +100%FREE /dev/mapper/VolGroup00-LogVol00
Instead of just “resizing” by adding 3GB (in the instructions) this one says to use all free space in the volume group for this partition. This is a “last step” instruction to make the change. I highly recommend to reboot and confirm your new partition sizes actually worked.
Askar  - Nice work |23/06/2011 06:44:09
For for the nice work, using these small ariticles i'm learning about LVM
Jake Tors |13/07/2011 07:56:53
just wondering where you came up with df -kh. You are asking to display in both kilobytes and human readable format at the same time. just use df -h my friend, df -h. same result.
Gene Rye  - Trying to umount the drive |20/07/2011 10:26:59
When I try to umount the drive to resize the partion smaller, I get a device busy message. root ~ puts me in my /root directory. When I df -kh the system, I get /dev/mapper/VolGroup00-LogVol00. Folloiwng Step 2, I cd /, and then umount /dev/VolGroup00/LogVol00. Get message device busy. What should I do?
thanks
Gene Rye  - More Info |20/07/2011 10:43:57
I was trying to do this through the desktop. Should this be done through the command line interface?
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:D:):(:0:shock::confused:8):lol::x:P:oops::cry::evil::twisted::roll::wink::!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

Last Updated on Tuesday, 02 June 2009 10:19
 

Forum Activity

Author:
Author: kenny22
Jan.24.12
Author: AaronRiley
Jan.15.12

Online Stats

Guests Online: 58
Members Online: 0



We thank you for visiting TcpDump and hope you find our knowledge base articles helpful. However, we need your support!!

If you found the content on our site useful, please help support us and visit one of our sponsors sites. Your support pays for the electric, servers and bandwidth required to run TcpDump and we can’t do it without your help!

Thank you again for all your support!

Best Regards,
-Tom Hirt