Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I resize logical volume to fit filesystem automagically?

share|improve this question
up vote 3 down vote accepted

To increase the size of a filesystem you must first grow the logical volume container and then increase the size of the filesystem within. When decreasing the size of a filesystem, shrinking the surrounding logical volume is done last.

A shorthand way of expanding a logical volume and the filesystem is contains can be achieved using lvextend with the --resizefs option. For example, assume that you have a logical volume of 1000 extents that you want to grow to 1600 and then expand the filesystem within; do:

lvextend -l 1600 --resizefs /dev/vg01/lvol1

This increases the logical volume size to a total of 1600 extents and then grows the filesystem associated with it. There is no need to unmount the filesystem to perform this operation.

In order to shrink the size of a filesystem, you must first unmount it and fsck it. Then, reduce the size of the filesystem first, followed by shrinking the size of the surrounding logical volume container. Use tune2fs' to ascertain the "Block size" of the filesystem. Multiply the block size value by the number of physical extents you want the final logical volume to contain, and use that product as the argument toresize2fs`. For example if the block size is 4096 and the final number of physical extents you want in your logical volume is 1200, then the product is 4915200 (blocks). Hence:

umount /myfs
e2fsck -f /dev/vg01/lvol1
resize2fs /dev/vg001/lvol1 4915200
lvreduce -l 1200 /dev/vg01/lvol1
[ respond "y" when asked if you really want to reduce it ]
share|improve this answer

JRFerguson provided a great answer. I think the OP was looking for something like this:

lvextend -l+100%FREE /dev/path/to/your/logical/volume

It's convenient to be able to refer to the available space in relative terms than calculating the number of blocks by hand. For more information, you can check out the man page for lvextend or any of the other lvm2 commands.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.