[CentOS] Freeing pv space for snapshots

Sat Jan 6 00:04:46 UTC 2007
Paul <unix at bikesn4x4s.com>

On Thu, January 4, 2007 11:40 pm, 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.)

You guys are great!  Thanks.  It was a breeze!  I really have fun learning
more and more.  I feel like an LVM expert now.  Here's the steps I took:

First my lv was like 38G, and I wanted to make it about 32G in the end.  I
know that should be way more than enough.  I also did a dd to an image
file on a secondary drive for a precaution (always have a failsafe
recovery!)

1.  booted up on CentOS 4.4 Live CD.  -When I booted up on it, I told it
to boot nonet to not bring up the interfaces, but it did anyhow.  I did a
"ifconfig eht0 down" to do a shut on it.  Anyhow, out of all the LiveCD's
I have tried, I do like the Centos the best!

2.  e2fsck -fv /dev/VolGroup00/LogVol00

3.  resize2fs -p /dev/VolGroup00/LogVol00 30G

4.  lvresize -L 32G /dev/VolGroup00/LogVol00

5.  resize2fs -p /dev/VolGroup00/LogVol00 (size defaults to lv size)

Now I have my free PV space!

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/hda2
  VG Name               VolGroup00
  PV Size               38.22 GB / not usable 0
  Allocatable           yes
  PE Size (KByte)       32768
  Total PE              1223
  Free PE               143
  Allocated PE          1080
  PV UUID               cQCke5-zi9o-xhOW-HlR5-M46g-VbHC-99Csch

Now I am on to learning how to do a full backup with snapshots!