Monday, July 5, 2010

Resizing LVM Partition

The bottom line about resizing ext3 logical volumes is that it is easy to make them bigger, but difficult to make them smaller.

Because online resizing is not supported by resize2fs, one has to be able to umount the partition to resize.

For some partitions, such as /home or /opt,  this is easy if you can just umount it, and resize.

For partitions like /var, you need to boot it into single user mode.  For /, you need to boot into rescue mode (from a live CD or src DVD) because / is mounted on single user mode.

  • If you boot into rescure mode, make sure you choose "Skip" when you are asked to mount disks with your Linux installation.
  • To activate the LVMs in RHEL/Fedora single user or Rescue Mode, run this from the command line:
    • lvm vgchange -a y
  • For a list of LVM commands, run:
lvm help


There is a really good LVM HowTo here http://www.ibiblio.org/pub/Linux/doc...LVM-HOWTO.html

 
I was sucessfull in reducing the root LVM logical volume on a default CentOS install to 10G with the following commands:

Boot with rescue CD. Skip mounting of the system partitions.
    # lvm vgchange -a y
    # e2fsck -f /dev/VolGroup00/LogVol00
    # resize2fs -f /dev/VolGroup00/LogVol00 10G
    # lvm lvreduce -L10G /dev/VolGroup00/LogVol00

Note:
  1. -f is necessary to get fsck to actually do check file system since there was no error in file system.   At first I recieved a message "Please run e2fsck -f /dev/VolGroup00/LogVol00" when trying to run resize2fs after I had run e2fsck without -f (thus nothing was done).  
  2. The same steps works for when booting into single user mode to reduce the size of /var.

1 comment:

  1. The LVM-HowTo link does not work. I could have meant the LVM-Howto on TLDP:

    LVM HOWTO

    Which seems to be best LVM doc that I can find.

    ReplyDelete