User Tools

Site Tools


technology:linux:lvm

Logical Volume Manager (LVM)

This is not intended to be a complete reference for LVM. Instead, its a short how-to about my particular install. If your needs aren't identical, you might need to make adjustments.

LVM is a great way to expand storage dynamically. When combined with the drive failure warnings provided by the LM Sensors tool, a certain level of failure avoidance is offered, thus providing a certain level of fault tolerance1).

There is a simple procedure for setting up LVM. The easiest way (which I didn't use) is to set it up during the OS install. Some Linux distros support it while others don't. I didn't have enough drives to need LVM when I built my system, so I added it later.

The process below assumes you have followed the same installation procedure (meaning you are installing LVM onto an already existing system).

Installation

  1. Become root for the installation process. So at the command prompt, run the sudo -i command and enter your root password.
  2. Install the package. On Ubuntu, its called 'lvm2' and you install it with:
    apt-get install lvm2
  3. Make sure the kernel module is loaded with:
    modprobe dm-mod
  4. Partition your harddisk(s) with fdisk. This does the physical partitioning of the drives. My 3 disks are partitioned as type 83 as shown here. Other people recommend type 8e, which fdisk lists as Linux LVM. Maybe thats the standard for new systems starting with LVM2, but I started with LVM1 and migrated. :-)
       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1   *           1       12853   103241691   83  Linux
    /dev/hda2           12854       36481   189791910    5  Extended
    /dev/hda5           12854       13375     4192933+  82  Linux swap / Solaris
    /dev/hda6           13376       36481   185598913+  83  Linux
    /dev/hdc1               1       24792   199141708+  83  Linux
    /dev/hdd1               1       24321   195358401   83  Linux
  5. Run pvcreate2) on each partition that will become part of your LVM system, like this:
    pvcreate /dev/hda6
    #my CD drive is /dev/hdb
    pvcreate /dev/hdc1
    pvcreate /dev/hdd1
    ...
  6. Use vgcreate to setup a volume group on top of the physical volumes:
    vgcreate vg1 /dev/hda4 /dev/hdc1 /dev/hdd1
  7. Create a logical volume named video on the volume group. The size is 595gb in my case. Your system might be different.
    lvcreate -n video -L 595G vg1
  8. Format the logical volume using the filesystem of your choice. I used xfs because it has great delete performance on large files, and MythTV creates lots of large video files.
    mkfs.xfs /dev/vg1/lv1
  9. Add an entry to /etc/fstab so the volume group gets mounted at boot time. Notice the device mapper's location is being used rather than the logical device itself (/dev/vg1/lv1).
    /dev/mapper/vg1-lv1  /video      xfs     defaults        0     2
  10. Use /video as the storage location for videos in MythTV's setup program.

Adding a New Drive to LVM

  1. Physically install the drive and power on the system. The device mapper should find the new drive and load it as a device. In this case, my new SATA drive was labeled as
    /dev/sda
  2. Get into fdisk3) and create a partition for the entire drive. Creating a partition is optional since LVM can use the entire drive, but it will keep other OSes from overwriting the drive if you ever install it in another system. I used a primary partition and it became
    /dev/sda1
  3. Run pvcreate /dev/sda1 to create a physical volume out of the primary partition
  4. Run vgextend vg1 /dev/sda1 to add the physical volume to the volume group (my volume group is called 'vg1')
  5. Run lvextend -L+460G /dev/vg1/lv1 to add 460gb to a logical volume (Note that 'vgs' command showed how much free space is available).
  6. Make sure the volume group is mounted and run xfs_growfs /video. Here '/video' is the mountpoint of my volume group.

Your filesystem may be different (ext2, ext3, reiser, jfs, etc…) and your mountpoint may have a different name. But the idea is the same…you create a physical volume, add it to a volume group, then extend the size of a logical volume with the volume group, and finally use the normal file system utilities to grow the size of the filesystem.

Thoughts on Filesystems

As a side note, be careful when choosing a filesystem. The filesystem's characteristics do matter. Some are not shrinkable, which will be important if you need to remove a drive later. Others are not growable, which seems to defeat the purpose of using LVM. For me, with MythTV, I am concerned about the efficiency of dealing with large files…creating them, reading them, and then deleting them. The recording, playback, and delete performance of my system (respectively) are impacted by my choice of filesystem.

After a bit of research, I decided on XFS. So far it has been a great choice. I highly recommend it for MythTV systems using LVM for storage management.

1) if the system owner obeys the warnings offered by the 'sensors' program, a failing drive can be cleared of content, replaced, and added back into the volume group with no loss of data
2) stands for 'physical volume create'
3) a complete discussion of fdisk is here
/home/cfreyer/public_html/data/pages/technology/linux/lvm.txt · Last modified: 2008/05/19 01:16 by Chris Freyer