The Logical Volume Manager

How to create an LVM-based ext2 filesystem

I'll assume we've got a new hard drive installed at /dev/sdb.

  1. Partition the drive, creating at least one LVM (type 0x8e) partition. We'll assume it's /dev/sdb1.
  2. Create a physical volume in that partition.
    #pvcreate /dev/sdb1
    Do the same for any other LVM partitions.
  3. Create a volume group (say its musicvg) and assign the physical volume to it:
    #vgcreate musicvg /dev/sdb1
  4. Create a logical volume in that volume group:
    lvcreate -l 100%VG -n musiclv musicvg
    Of course, you may want to adjust the size.
  5. Create the filesystem on that volume:
    mke2fs /dev/musicvg/musiclv
    Add whatever other options you like, of course.

How to add a new hard disk to a logical volume group and thereby extend an ext2 filesystem.

Let's suppose we have an ext2 filesystem at /dev/volg/vol, and we want to add more space to it by installing a new hard disk. I'll assume the new disk is at /dev/sdg, and we've create a partition on it (type 8e, of course) at /dev/sdg1. Then:

  1. Create a physical volume on the partition:
    #pvcreate /dev/sdg1
  2. Add it to the volume group:
    #vgextend /dev/volg /dev/sdg1
  3. Extend the logical volume:
    #lvextend -l 100%VG /dev/volg/vol
    Of course, you don't have to add all the space, if you don't want to do so.
  4. Check the existing filesystem:
    #e2fsck -f /dev/volg/vol
  5. Extend the filesystem:
    #resize2fs /dev/volg/vol
  6. Check the new filesystem again:
    #e2fsck -f /dev/volg/vol