LVM Mini HOWTO

Create a Volume using LVM

Prepare Physical Volumes

If you are placing a logical volume on a hard drive, it is useful to create a partition with type 8e (Linux LVM). This is not required; you can use the raw disk (e.g., /dev/sdi instead of /dev/sdi1). I believe that it makes the management of the disks easier because you can easily see with fdisk -l what disks are part of an LVM. Of course, you must create an LVM partition if you plan to put other partitions on the same disk (for example the boot partition or swap space).

fdisk -l /dev/sdi

Disk /dev/sdi: 2199.0 GB, 2199014866944 bytes
255 heads, 63 sectors/track, 267348 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdi1               1      267348  2147472778+  8e  Linux LVM

Special devices (such as the network block device or RAID devices) do not support partitioning. In those cases, just use the raw device. In fact, using the LVM is the only way to separate the space on these devices.

Each physical device/partition must be prepared with pvcreate. The following all ready a given device (or multiple devices).

pvcreate /dev/nbd0
pvcreate /dev/nbd{0..6}
pvcreate /dev/hda8
pvcreate /dev/md1

Create a Volume Group

vgcreate netdisk /dev/nbd{0..6}

Create a Logical Volume

lvcreate -n netdisk15 -l 73274 netdisk

Format the volume

mkfs.ext3 -j -L netdisk15 -i 524288 -m 0 /dev/netdisk/netdisk15

Increasing the size of an Existing Volume

Add devices to a Volume Group

vgextend netdisk /dev/nbd1

Increase a Logical Volume

Specify the size as the new total size, or use plus to specify how much to add.

vgextend -l +73274 /dev/netdisk/netdisk15

You can now extend the size of the ext3 partition. First umount it and check it (required).

e2fsck -f /dev/netdisk/netdisk15
resize2fs /dev/netdisk/netdisk15

Activating/Deactivating an LVM

To enable a volume and mount it.

vgchange -a y netdisk15
mount LABEL=netdisk15 /disk

To deactivate a volume.

umount /disk
vgchange -a n netdisk15
 
howto/lvm.txt · Last modified: 2006/07/11 23:10 by dpotter