LVM

From Briki
Revision as of 10:46, 21 August 2007 by 205.228.73.12 (talk) (Resizing a physical volume)
Jump to: navigation, search

Overview

  • One or more Physical Volumes (eg. /dev/sda2) are joined together in a Volume Group (eg. /dev/vg1)
  • A Volume Group is split into one or more Logical Volumes (eg. /dev/vg1/media)

Creating a new volume group & logical volume

To create a volume group (/dev/vg1) consisting of 1 physical volume (/dev/sda2), and split into only 1 logical volume (/dev/vg1/media):

  • Setup partition as a physical volume:
sudo pvcreate /dev/sda2
  • Create a volume group consisting of only this physical volume:
sudo vgcreate vg1 /dev/sda2
  • Check volume group has been created successfully:
vgdisplay

This should show 1 volume group consisting of 0 LVs (see Cur LV and 1 PV (see Cur PV).

  • Create a logical volume:
sudo lvcreate --size 30g --name media vg1
  • Format the logical volume as ext3:
mkfs.ext3 /dev/vg1/media
  • Mount the volume by adding the following line to /etc/fstab:
/dev/vg1/media   /var/media   ext3   defaults    0  2


Resizing a physical volume

For example, extending /dev/sda2. Note here that we are extending a physical volume, not just a logical one.

  • Unmount any logical volumes which use /dev/sda2
  • Use fdisk to delete old /dev/sda2 and recreate as a larger partition (this will not actually delete any data). If fdisk warns you that the partition table will not be written until the next reboot, you will need to reboot now. Remember to unmount relevant logical volumes again after rebooting.
  • sudo pvresize /dev/sda2
  • Check how many free extents exist using sudo vgdisplay - you should see extents corresponding to the increase in size of your physical partition.
  • Add this many extents to /dev/vg1/media using sudo lvextend -l +<num-extents> /dev/vg1/media
  • Resize the filesystem on /dev/vg1/media using sudo resize2fs /dev/vg1/media
  • Check that the volumes look correct with sudo vgdisplay
  • Remount /dev/vg1/media