Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Table of Contents

Introduction

LVM creates virtual block devices out of other block devices.  In the simplest case, "other block devices" are hard disk partitions.  LVM calls them "physical volumes" or PVs.

LVM groups physical volumes into volume groups (VGs).

From the volume groups' pool of blocks, LVM creates virtual block devices which it calls "logical volumes" or LVs.

Here's a diagram of all that:

In the standard Blue Light setup, the physical volumes are not disk partitions but Multiple devices (md, software RAID) devices.

Setup

In the examples the LVM physical volume (PV) is md1.

Create

...

a physical volume (PV)

Note: this step can be omitted; it is implied by the next step.

Code Block
pvcreate /dev/md1

 

Create

...

a volume group (VG)

The volume group name is was normally the first two components of the hostname separated by dot; now we use the FQDN.

Code Block
vgcreate ltsp.th /dev/md1

...

Create logical volumes (LVs)

Here we are going to create an LV for swap. 10G gives the size of the volume (10 GB)For example (10G gives a 10 GB size):

Code Block
lvcreate -L 10G -n root ltsp.th

If you want to create other volume, check the space left on the group with the following command:

Code Block
vgs

Further volumes are created using further lvcreate commands.

...

 

Operations

Show current LVM usage

Overall picture: lsblk (not available on Debian 6)

Show PVs: pvs

Show VGs: vgs

Show LVs: lvs

Activate LVM volume groups (VGs)

...

Format a logical volume (LV)

This is exactly the same as formatting any other sort of block device; only the device file path is LV-specific

...

,

...

mkfs.ext4 /for example /dev/ltsp.th/root

...

mkswap /dev/ltsp.th/swap

Extend a logical volume (LV)

...

Finally the PV is specified on the lvextend command.  For example:Examples:

lvextend --size 400G /dev/bafi.backup/th /dev/sdc1
lvextend --extents +55172 /dev/bafi.backup/blue /dev/sdb3

...

Use the lvreduce command.

Move

...

storage or logical

...

volumes (

...

LVs) between physical volumes (PVs)

Move storage

This is useful when upgrading HDDschanging physical volumes (PVs).  After adding the new HDDs, usually as a RAID 1 md array, to the volume group, the LVs can be moved from the old PV to  the new.  Finally the old PV can be removed from the VG and the old HDDs removed, usually after powering down.

For example:

pvmove /dev/md1 /dev/md3 

Move a logical volume (LV)

For example:

pvmove --name atlassian.blue.av-disk /dev/md1 /dev/sdb1

Rename a logical volume (LV)

Umount any file system contained by the LV and rename

Code Block
umount <device>
lvrename <vgname> <oldlvname> <newlvname> 

Remove a Physical Volume (PV) from a Volume Group (VG)

vgreduce VG_name PV_name

For example:

vgreduce ls1 /dev/sdb2

Troubleshooting

Messages

File descriptor * leaked on * invocation. Parent PID *

Can be safely ignored.  Can be suppressed by setting LVM_SUPPRESS_FD_WARNINGS environment variable before doing whatever produced the message.

(info) Code to generate the message was added when it was alleged that LVM was leaking file descriptors.  The message shows that a file descriptor has already been leaked when an LVM program is called.

WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!

Can be safely ignored.

(info) From https://wiki.gentoo.org/wiki/Talk:LVM#lvmetad_warning: "Normally lvmetad is not even enabled. Neither in initscripts nor in /etc/lvm/lvm.conf. But the lvm service has a useless rc_need on lvmetad. Remove it to get rid of those messages".

Recover a deleted logical volume (LV)

...

Code Block
vgchange -ay --ignorelockingfailure

You are done (smile)

Rename a logical volume (LV)

Umount any file system contained by the LV and rename

Code Block
umount <device>
lvrename <vgname> <oldlvname> <newlvname> 

Outdated

 

Outdated

 

Resize existing file system without LiveCD

...

A great howto is here http://www.gagme.com/greg/linux/raid-lvm.php 

Chrooting and installing GRUB 2 on LVM setup

...