LVM Usage Examples

For documentation purposes, here’s the procedure to resize a partition on an LVM system. For more detail, see the LVM howto at http://tldp.org/HOWTO/LVM-HOWTO :

I. Example on growing a filesystem

1. pvscan to see if you’ve got enough free extents to grow your partition. If so, skip to step 4. If not, go on to step 2.

2. Make a partition for the new physical volume. If you’re adding a whole disk, you can skip to step 3. With parted, you can do this non- interactively, which we did to run it as a script across all machines: in this case, we did:

parted /dev/sda mkpart primary ext3 73.3G 501G

2a. If you receive an error message saying that the new partition table won’t be readable yet, run:

partx -v -a /dev/sda

3. Create the physical volume on the new partition (or the new whole disk). In this case, we did:

pvcreate /dev/sda4

4. vgextend your existing volume group onto the new physical volume In this case, we did:

vgextend /dev/vglab /dev/sda4

5. resize the logical volume that you care about. (NOTE: if shrinking, you must unmount the partition first! See Example II. Depending on the partition, this will probably require you to boot from a rescue disk.) In this case, we did:

lvresize /dev/vglab/lvtmp -L100G

6. resize the filesystem residing on the logical volume. In this case, we did:

resize2fs /dev/vglab/lvtmp

II. Example on shrinking a filesystem

To shrink an ext3 filesystem, you *do* have to unmount.

1. umount /home
2. resize2fs /dev/VolGroup00/Home00 1500M
3. e2fsck -f /dev/VolGroup00/Home00
4. resize2fs /dev/VolGroup00/Home00 1500M
5. lvreduce -L 1500M /dev/VolGroup00/Home00
6. e2fsck -f /dev/VolGroup00/Home00
7. mount /home

III. Example on removing a filesystem and growing on another filesystem

1. umount /home
2. lvremove /dev/VolGroup00/Home00
3. lvresize -l +24 /dev/VolGroup00/LogVol00
4. resize2fs /dev/VolGroup00/LogVol00