Logical Volume Management (LVM) makes it possible to dynamically group multiple drives/partitions into what appears to be one large chunk of storage. This may sound like a daunting task, however, as I will show its quite simple.
The following assumes that lvm2 is already installed.
- Remove any existing partitions
- Initialize the disks or partitions
- Create a volume group
- Create a logical volume
- Format the logical volume
- Mount the logical volume
- Throw a wild party
I had two drives that I wanted to make one large volume group out of (I will use hde and sdc in the following examples be sure to figure out the correct devices for your drives!). If you want to use a partition of a drive you would, for example, substitute hde with hde2. I used gparted, because it kicks ass, to setup (erase everything on) the drives. Alternatively you can run the commands for each drive (as found on he LVM HOWTO ):
# dd if=/dev/zero of=/dev/devicename bs=1k count=1
# blockdev --rereadpt /dev/devicename
Next initialize the disks/partitions:
# pvcreate /dev/hde
# pvcreate /dev/sdc
Create a volume group:
# vgcreate my_volume_group /dev/hde /dev/sdc
Run vgdisplay to find out the Total PE size of the volume we just created.
Use the Total PE size (say its 10230) to create a logical volume:
# lvcreate -l 10230 my_volume_group -n mylv
Note: If you get an error message about Device Mapper and the kernel you will need to recompile your kernel with LVM and device mapper support (Device Drivers/Multi-device support/Device Mapper Support, in 2.6.18)
At this point we have what appears to our system to be a drive /dev/my_volume_group/mylv that we can format, mount, and use.
Format our new chunk o data with your favorite file system type (mine happens to be reiserfs):
# mkreiserfs /dev/my_volume_group/mylv
Mount our new storage:
# mkdir /mnt/mylv
# mount /dev/my_volume_group/mylv /mnt/mylv
Thats it... Its time to start filling up the new space and throwing the wild party. When waking up at noon the next day be sure to remember that with LVM you can, at anytime:
- choose to add more storage to your volume
- migrate data to specific disks/partitions and remove drives from the volume group
- move disks into different volume groups
- take snapshots of volumes
- use stripping
- combine this with Linux's handy software raid for data redundancy
Keep in mind that if a drive that is part of your volume group fails then the whole thing is gone so I highly recommend using a data redundant raid or as I am doing using a tools like rsync and cron to perform nightly backups of your important data.
rsync script that will backup important data in a unique directory each time its ran:
rsync -rvu --stats --delete /mnt/mylv/important_data \
See LVM HOWTO for examples of all of the cool stuff you can do: