[CentOS] Freeing pv space for snapshots

Fri Jan 5 06:52:18 UTC 2007
Jed Reynolds <lists at benrey.is-a-geek.net>

Alvin Chang wrote:
> On 05/01/07, Aleksandar Milivojevic <alex at 8-p.ca> wrote:
>> I've used it, and it works correctly (and it is available in CentOS
>> 4.4).  It shrinks file system as it should.  The only things Paul should
>> be careful is to first shrink file system, than logical volume and to
>> correctly calculate file system size and by how many extents he can
>> shrink logical volume.  If he shrinks logical volume too much, he might
>> end up loosing data.  Running fsck in non-destructive mode (fsck -N)
>> and/or attempting to mount file system read-only after he shrinks
>> logical volume might be a good idea to test all is OK.
> A little technique you can use is:
> 1. shrink the file system to the size slightly less than what you 
> really want
> 2. reduce LV to the size that is what you really want
> 3. expand the file system to the size of the LV (usually the resize
> program can be told to expand the file system to maximum available
> space automatically on the LV.)
>
That sounds like a pretty healthy tip!

Keep in mind that with a large LV, the slowest part of this process is 
often the fsck -f step.

The resize2fs command is not nearly as slow as the fsck -f.  But on a 
large LV, you prolly want to show the progress bar during the resize, so 
do a resize2fs -p, because I know I get nervous when I don't see output 
from a long running command.

On production systems, I've learned to have enough space to have one 
empty LV that can hold any of the other LVs so you can cleverly remount 
a copy of the LV you want to either fsck or recreate. I don't want to 
have a 2-hour reboot after 200 days uptime just to have my filesystem 
force a fsck -f on you when you very like least want it. Recreating a LV 
is a clever way to get around doing regular fscking, unless you tune 
your filesystem check way out to 3 years and 999 reboots or whatnot.

Jed