The Device Mapper (DM) used by LVM2 is a general block-device mapping layer. This means that you can use any block device as an LVM Physical Volume. The most useful upshot of this is that you can use RAID devices as LVM PVs:

 1. mdadm --create --level=5 --raid-devices=3 /dev/sda1 /dev/sda2 /dev/sda3
 1. pvcreate /dev/md0
 1. mdadm --create --level=5 --raid-devices=4 /dev/sda4 /dev/sda5 /dev/sda6 /dev/sda7
 1. pvcreate /dev/md1
 1. vgcreate my_vg1 /dev/md0 /dev/md1

The above creates two RAID5 arrays (presumably /dev/sda{1,2,3} are a different size to /dev/sda{4,5,6,7}), and pools them together into a single volume group called my_vg1. Space can then be allocated from that volume group using lvcreate. The full size of the VG will be twice the size of /dev/sda{1,2,3} plus three times the size of /dev/sda{4,5,6,7} – in other words, the size of the two RAID5 arrays put together.

Using disk partitions as block devices

Other block devices that you can use include disk partitions. If you have a disk with some free space you can create a partition in it (for example using cfdisk) and then use that disk partition as a Physical Volume: Note: /dev/hda6 is for example only, substitute your own partition in the commands below. The partition doesn't need any formatting and will in fact be 'wiped clean' losing any data that maybe on it.

pvcreate /dev/hda6

That second command should list your new PV. Once you have created all your PVs you can create a Volume Group with them:

vgcreate my_vg /dev/hda6

Again, the second command should list your new Volume Group, my_vg. Now you create several smaller Logical Volumes from your Volume Group. If you leave some spare space in the VG you can resize some of your LVs at a later date if they become overcrowded.

lvcreate -L40G -nmy_lv1 my_vg
lvcreate -L4G -nmy_lv2 my_vg
lvcreate -L10G -nmy_lv3 my_vg

The above commands will create three new LVs called my_lv1, my_lv2, my_lv3. The sizes are specified after the -L with G denoting gigabytes. The last parameter is the name of the Volume Group that will 'house' your LVs. lvdisplay should list all three of the new LVs.

To use the LVs you need to format them and then mount them:

Format using the ext3 disk format:

mkfs.ext3 /dev/my_vg/my_lv1
mkfs.ext3 /dev/my_vg/my_lv2
mkfs.ext3 /dev/my_vg/my_lv3

Now to mount them somewhere (we first create mount points. You may have some place you want to use already):

mkdir /mnt/movies /mnt/photos /mnt/data
mount /dev/my_vg/my_lv1 /mnt/photos
mount /dev/my_vg/my_lv2 /mnt/data
mount /dev/my_vg/my_lv3 /mnt/movies

We can now use our LVs. To ensure they are available after the next reboot you may want to put entries in your /etc/fstab file. To see their usage and capacity you can use the command:


LogicalVolumeManagement/UseAnyBlockDevice (last edited 2005-11-24 11:58:09 by 194)