[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Script to automatically extend LVM volumes

Now that the linux kernel support extending ext3 file systems without
umounting, it make sense to start small and extend on demand.  I've
finally gotten around to write a script to automatically resize LVM
volumes when they are too full.  It is currently in svn, in the
debian-edu-config package.

It can be downloaded from

To use it, create a file /etc/fsautoresize looking like this (without
the indentation):

  /.*  5%  20g 10%
  /usr 10% 10g defaults
  /home 10% 30g defaults

The first field is a regex, the second the the limit on how little
space left is allowed before the volume is resized (can be absolute
size or fraction of current volume size), the third is the upper limit
(when to no longer extend the volume), and the latter is the increment
as an absolute size or relative to the current volume size (defaults
is 10%).

The script is still in early development, so do not expect too much.
It will not do anything without extra options.  These options might
change.  The -n option turn off dryrun, and make it run the lvm tools.

Here is an example run on my laptop:

  # ./debian-edu-fsautoresize -n)
  exec: lvresize -L22634432.4k /dev/systemvg/homelv
    Rounding up size to full physical extent 21.59 GB
    Extending logical volume homelv to 21.59 GB
    Logical volume homelv successfully resized
  exec: resize2fs /dev/mapper/systemvg-homelv
  resize2fs 1.40-WIP (14-Nov-2006)
  Filesystem at /dev/mapper/systemvg-homelv is mounted on /home;
    on-line resizing required
  old desc_blocks = 2, new_desc_blocks = 2
  Performing an on-line resize of /dev/mapper/systemvg-homelv to
    5658624 (4k) blocks.
  The filesystem on /dev/mapper/systemvg-homelv is now 5658624 blocks long.

I would now like some feedback on the behavoir.  Is this useful as it
is?  I suspect we want to run it as a daemon or from cron, and provide
a default file with instructions on how to resize the various volumes.
Be aware that error handling is sparse.  It can not be used for file
system reduction, so if lvresize ask if it is ok to reduce the size,
answer no. :)

The code is still little big of a mess, but it is structured to
support several file systems and volume systems (I plan to implement
Veritas support for use at work), and I believe it will save me some
work there in the future.

Petter Reinholdtsen

Reply to: