Posts tagged ‘lvm’

Lucky me, I need to upgrade yet another machine, and it’s my email server. LVM (which I am not a big fan), takes all of the drive by default, and so now I want to resize the volume to be much smaller, then install the new operating system on the same drive (in some of the free space).

Quick Answer:
1. boot rescue cd, don’t mount drives
2. run:

lvm vgchange -a y
e2fsck -f /dev/VolGroup00/LogVol00
resize2fs -f /dev/VolGroup00/LogVol00 100G
lvm lvreduce -L100G /dev/VolGroup00/LogVol00

More Detail:
First I looked to see how much space I’m using.

[root@au1 c]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 297673144  49140752 233167480  18% /
/dev/sda1               101086     61896     33971  65% /boot
tmpfs                  3109444         0   3109444   0% /dev/shm

so around 50G, kid of a shame because I normally allocate 50G for the installed OS. No worries, I decide to go with 100G. (It’s a 250G drive I think) – hmm… TODO: check it’s not a 300G or 500G drive. Damn, I think it’s 500G…

Insert rescue CD into drive (eg the normal install disk (CentOS 5.4 64bit)).
At the prompt type: linux rescue
and then “Skip” the mounting of the drives.

lvm vgchange -a y
e2fsck -f /dev/VolGroup00/LogVol00
resize2fs -p -f /dev/VolGroup00/LogVol00 100G
lvm lvreduce -L100G /dev/VolGroup00/LogVol00

e2fsck and resize2fs will probably take a long time. For me e2fsck was probably around 5 minutes. resize2fs is certainly longer than that and I won’t know how long as I forgot to add in the -p and I’m about to head out for lunch (Happy Birthday Paul!).

If the Logical volume can be unmounted, then you can do these things without the rescue cd.

after reboot:
[root@au1 c]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 101573920 49124416 48255200 51% /
/dev/sda1 101086 61896 33971 65% /boot
tmpfs 3109444 0 3109444 0% /dev/shm