Howtos / Articles

Add New Drive to LVM Array on Ubuntu

This howto guide will go through the process of adding a new drive to a LVM array.

In this example, I have 3x 2TB drives, and will be adding 1x 3TB drive.

Devices:

Drive Size LVM Partition Size Partition Device Notes
2 TB 1.8 TB /dev/sda5 (Contains the OS in the other ~200 GB)
2 TB 2 TB /dev/sdb1
2 TB 2 TB /dev/sdc1
3 TB 3 TB /dev/sdd1 (this is the new drive)

The volume group name is “vg_storage1″, and the Logical volume name is “LogVol00″.

Create LVM Physical Volume on new disk

To add a disk to a LVM volume group, it first needs to set up as a LVM disk. To do this, run the ‘pvcreate’ command as follows:

$ sudo pvcreate /dev/sdd1

Example output:

$ sudo pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created
$

The drive will now contain the physical volume information for LVM, and can be added to a volume group.

Adding the drive to a volume group

To make the newly added disk part of a volume group, you can run the ‘vgextend’ command as follows:

$ sudo vgextend vg_storage1 /dev/sdd1

‘vg_storage1′ being the volume group name.
‘/dev/sdd1′ being the drive we want to add to the volume group.

Example output:

$ sudo vgextend vg_storage1 /dev/sdd1
  Volume group "vg_storage1" successfully extended
$

Increase the size of the Logical volume

To resize the logical volume to the maximum available size, you first need to run the following command, and note the “Total PE” value in the output:

$ sudo vgdisplay

Example output:

$ sudo vgdisplay
  --- Volume group ---
  VG Name               vg_storage1
  System ID
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  16
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               8.08 TiB
  PE Size               4.00 MiB
  Total PE              2118939
  Alloc PE / Size       1331200 / 5.08 TiB
  Free  PE / Size       787739 / 3.00 TiB
  VG UUID               qHNraE-QF3d-dknW-3qVE-SdM2-iHfr-CKkYVJ
$

Take the Total PE value, and use it in the following command (2118939 in this case):

$ sudo lvextend -l 2118939 /dev/vg_storage1/LogVol00

Example output:

$ sudo lvextend -l 2118939 /dev/vg_storage1/LogVol00
  Extending logical volume LogVol00 to 8.08 TiB
  Logical volume LogVol00 successfully resized
$

Unmount the filesystem

Stop any processes that may be accessing the filesystem that is on the LVM array you will be expanding.

This may include things like samba, nfs, ftp servers, etc. Anything that may be blocking access to unmount the filesystem.

Unmount the filesystem on the LVM array:

$ sudo umount /mnt/storage

In this case the mount point was /mnt/storage. Check your mount point using the ‘mount’ command.

Checking the filesystem

Check the filesystem for errors before attempting to expand:

$ sudo e2fsck /dev/mapper/vg_storage1-LogVol00

Increase the size of the filesystem

Finally, resize the filesystem to use the maximum size available:

$ sudo resize2fs -p /dev/vg_storage1/LogVol00

By not specifying any filesystem size, it will default to resizing to use the maximum space available.

Example output:

$ sudo resize2fs -p /dev/vg_storage1/LogVol00
resize2fs 1.41.11 (14-Mar-2010)
Resizing the filesystem on /dev/vg_storage1/LogVol00 to 2169793536 (4k) blocks.
Begin pass 1 (max = 26217)
Extending the inode table     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/vg_storage1/LogVol00 is now 2169793536 blocks long.
$

Remount the filesystem

Mount the file system again:

$ sudo mount /mnt/storage


Share this howto article!
  • Facebook
  • Twitter
  • Reddit
  • email

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>