1. LVM2 and adding disks

    As part of my media server, one of the things that I need to be able to do is to add disks when I need them. I decided to run the server from an 80Gb drive that I had spare, but knew the first drive I would add would be a 400Gb SATA drive so I installed my Debian system with LVM2 support.

    The latest kernel (2.6.8.15) has good SATA support for my Maxtor card, so I upgraded through Debian and wanted to increase my /assets LVM logical drive.

    I had already created a volume group called volume1 and I had create a logical volume called assets which I mounted at /assets

    Adding the drive was easy, just plug in the hardware and start the system up.

    dmesg

    will show that it has seen the new harddrive after it has booted, just look for a device that is the same size as the one that you have added. If the device doesn’t show up it may mean that you have installed it incorrectly or that there is some problem supporting the device that you have installed.

    The

    fdisk

    the new drive. Being a SATA drive it is seen as a SCSI device, and as it is my first SCSI device on the system it will be at /dev/sda

    fdisk /dev/sda

    Create as many partitions as needed, I created one primary partition.

    See what has happened with all the partitions by issuing the following:

    fdisk -l

    Extend the existing Volume group by:

    vgextend volume1 /dev/sda1

    Now take alook at the exist volume groups:

    lvdisplay

    Unmount the logical group that you wish to expand:

    unmount /assets

    Now checkout how much space that you have on your volume group so that you can determine how much you can add to your existing logical group.

    vgdisplay

    It will show the Free PE / Size – this will be the amount that you can resize by.

    Resize the logical group:

    lvextend -L+372.6G /dev/volume1/assets

    Check the filesystem is ok (I am using the ext3 file system, you will need other tools for other file systems):

    e2fsck -f /dev/volume1/assets

    Now resize the data in that logical group.

    resize2fs /dev/volume1/assets

    On my 400Gb drive this resizing took some time. Finally remount the drive and continue using it.

    mount /assets

    And check that you have all that space added.

    df
    By timc3 on the
    March 19th, 2006

10 Comments

  1. Thanks. I usually google around for awhile before I get something working, this one did the trick on the first try. Interestingly, I tried all the above on a live filesystem (it’s just a vmware test image, didn’t matter if I broke it), and successfully added a drive & extended the / partition. Didn’t unmount or reboot.

    Scott Says:
    May 6th, 2008 at 8:03 pm
  2. so this will keep all the data on volume1 and add the new drive size to volume1? If so thank you so much, I have been looking for a way to do this forever and haven’t been able to find a good tutorial on LVM.

    Badi Says:
    June 19th, 2008 at 5:05 pm
  3. Interestingly, I was unable to successfully add a drive and extend the partition without unmounting it first. it kept giving me some extraneous errors about matchpathcon failed: No such file or directory
    umounting the drive and trying the same exact thing worked like a charm though

    Joe Says:
    June 19th, 2008 at 10:29 pm
  4. Badi: Yes thats basically what it will do. Its just an cheap way of having expandable mount points.

    Joe: Well I am not surprised really, its probably a good idea to umount it first.

    timc3 Says:
    June 21st, 2008 at 11:16 am
  5. You can skip using fdisk and use pvcreate instead if you like.

    G-Man Says:
    June 22nd, 2008 at 6:54 am
  6. Thanks for this post. It helped me Extend my LVM. Only thing though, when I tried to use vgextend it told me that my partition wasn’t a physical volume. so i had to go to another forum to learn about the “pvcreate” command:

    pvcreate /dev/hdb (the new drive you are adding to LVM)

    Might be useful to someone else.

    NKane Says:
    July 8th, 2008 at 8:04 pm
  7. Thanks for the comment.

    timc3 Says:
    July 21st, 2008 at 8:55 am
  8. Maybe a cloud based system would match your requirements much more better.

    Robert Poehler Says:
    July 16th, 2009 at 9:38 am
  9. Well not really considering that I want this in my home.

    timc3 Says:
    July 16th, 2009 at 9:56 am

Please post a comment