Logical Volume Management (LVM) HOWTO

This short HOWTO shows how to create and manage LVM partitions.

LVM allows you to group multiple physical partitions together, and to then divide that space up in to multiple logical partitions. Space can be moved between logical partitions as required.

In this example we use a single partition (/dev/mapper/crypthome) which has been created using DM-CRYPT on top of MD software RAID, but you could just as easily put LVM directly on top of RAID (example: /dev/md0), or directly on a physical partition (example: /dev/sda1).

User-space Toos

To install the LVM2 user-space tools:

aptitude install lvm2

Physical Volume Management

To prepare a physical volume (your target partition) for LVM:

pvcreate /dev/mapper/crypthome          # (or /dev/sda or /dev/md0)

To list physical volumes used for LVM:

pvdisplay

To move data from one physical volume to another:

pvmove /dev/crypthome /dev/someotherpartition

To remove a physical volume:

pvremove /dev/mapper/crypthome

Volume Group Management

To create a volume group (lvmhome) from a physical volume (/dev/mapper/crypthome):

vgcreate lvmhome /dev/mapper/crypthome

To show the status of volume groups:

vgscan
vgdisplay

To rename a volume group:

vgrename lvmhome lvmhome2

To delete a volume group:

vgremove lvmhome

To add another volume to an existing volume group:

vgextend lvmhome /dev/yournewpartition

To remove a volume from a volume group:

vgreduce lvmhome /dev/youroldpartition

Logical Volume Management

To create a logical volume named home in the volume group lvmhome:

lvcreate --name home --size 100G lvmhome

List and display the status of logical volumes:

lvscan
lvdisplay

To rename a logical volume:

lvrename data home newname

To delete a logical volume:

lvremove /dev/data/home

To format and mount a logical volume:

mkfs.ext3 /dev/lvmhome/home
mount /dev/lvmhome/home /home
df -h

To automatically mount a logical volume at boot list it in /etc/fstab:

/dev/lvmhome/home	/home	ext3	rw,noatime	0	0

To grow a logical volume:

umount /home
lvextend -L200G /dev/lvmhome/home
e2fsck -f /dev/lvmhome/home
resize2fs /dev/lvmhome/home 200G
mount /dev/lvmhome/home /home
df -h

To shrink a logical volume:

umount /home
e2fsck -f /dev/lvmhome/home
resize2fs /dev/lvmhome/home 50G
lvreduce -L5G /dev/lvmhome/home
mount /dev/lvmhome/home /home
df -h

Discussion

Enter your comment (wiki syntax is allowed):

Subscribe to the RSS feed for Andy's Debian HOWTOs

Article from Andy's Debian HOWTOs (http://www.besy.co.uk/debian/debian)

 
debian/how_to_setup_and_manage_lvm2_partitions.txt · Last modified: 2008/08/01 23:56 (external edit) · [Old revisions]
Recent changes RSS feed Powered by Debian Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki