about img
blogger img

buchos posts img

Corys posts image

UnderPaidLoveMonkis posts img

scotts posts image


Tutorial: Linux LVM Quickie

Scott Rippee @ 6:46 pm November 26th, 2006

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.

Steps demonstrated:

  1. Remove any existing partitions
  2. Initialize the disks or partitions
  3. Create a volume group
  4. Create a logical volume
  5. Format the logical volume
  6. Mount the logical volume
  7. 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!). gparted 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 [1]):

# 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:

CODE:
  1. #!/usr/bin/env bash
  2. DATE=`date`
  3. mount /mnt/mylv
  4. mount /mnt/backup_drive
  5. mkdir /mnt/backup_drive/${DATE}
  6. rsync -rvu --stats --delete /mnt/mylv/important_data \
  7. /mnt/backup_drive/${DATE}

See LVM HOWTO for examples of all of the cool stuff you can do:

[1] http://tldp.org/HOWTO/LVM-HOWTO/index.html

Leave a Reply

Subscribe without commenting