Monday, January 8, 2007

How to resize or expand LVM partitions

A few week ago, I installed FC6 on my laptop and my slash (/) partition started to run out of space. So I decided that I would shrink my big partition and expand my / partition. Fortunately, I installed FC6 using LVM2 (Logical Volume Manager) which makes it very easy to resize partitions without even rebooting.

Here is how I did.
My partition was like this:

Filesystem1K-blocksUsedAvailableUse% Mounted on
/dev/mapper/VolGroup00-LogVol00 79353926773500752292 91% /
/dev/sda5497829209044512235%/boot
tmpfs103708401037084 0% /dev/shm
/dev/mapper/VolGroup00-LogVol0170877776149881445104537223%/home
My / partition is about 8 Gb and my /home partition is about 71 Gb.

For /home, I did:
  1. umount /home
  2. e2fsck -f /dev/VolGroup00/LogVol01
  3. resize2fs /dev/VolGroup00/LogVol01 69G
  4. lvreduce -L-2G /dev/VolGroup00/LogVol01
  5. mount /home
For / partition, I did:
  1. lvextend -L+2G /dev/VolGroup00/LogVol00
  2. resize2fs /dev/VolGroup00/LogVol00
e2fsck and resize2fs belong to package e2fsprogs-1.39-7.fc6.

resize2fs has the ability to resize mounted partitions.
From the manual of resize2fs:
[...] If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 only.). [...]
[root@tosca ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2400256 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2400256 blocks long.

I finaly end up with the following partionning:
Filesystem1K-blocksUsedAvailableUse% Mounted on
/dev/mapper/VolGroup00-LogVol00929962467793042043564 77%/
/dev/sda5497829209044512235%/boot
tmpfs1037084010370840%/dev/shm
/dev/mapper/VolGroup00-LogVol01688777761499988851033628 23%/home

Some useful LVM commands (package lvm2-2.02.06-4):
  • lvmdiskscan
  • vgdisplay
  • pvdisplay
  • lvdispay
  • vgcreate
  • pvcreate
  • lvscan
  • pvscan
  • vgscan
Some useful links:

2 comments:

HerbCSO said...

Perfect - just the info I needed in a nice, concise little package. Thanks! ;]

AtGG said...

Great post. A big THANK YOU.