You may need to add new disk to your Linux LVM for various reasons such as for adding capacity for your existing applications or new applications. This post aims to show you how you can add a new disk to your existing LVM as well as to a new LVM. The difference between adding a new disk to a new LVM and to an existing LVM is that in the latter case you do not have to create a new volume group using vgcreate command.
Required steps to expand Linux LVM:
- Add the new disk and then run ‘fdisk’ command to see the status of the newly added disks. At this stage if you run the “df -h” command you will not see any new disk because it was not initialized.
- To initialize the disk, run the following command.
pvcreate /dev/sdb /dev/sdc
- Create a new volume group. If you want to add the new disk to you existing volume then type vgdisplay command and note the volume group name that you need to use to create logical volume shown in step 4. To create a new volume named TestVG and to add the new disks to it use the command as shown below.
root@debian:/# vgcreate TestVG /dev/sdb /dev/sdc
After creating the new volume, check the new volume group using vgdisplay command.
- Create a logical volume. To carve out a new logical volume inside the volume group use:
root@debian:/# lvcreate -n TestLV -L 4.29G TestVG
- Next create a file system for the logical volume. Unless you create file system, you will not be able to use your logical volume.
root@debian:/# mkfs.ext3 /dev/TestVG/TestLV
- Mount the new logical volume in a directory. Create a new directory or mount it in an existing directory.
root@debian:/# mkdir mydata
To mount the new LVM in the new directory, type the following command.
root@debian:/# mount /dev/TestVG/TestLV /mydata
Now, use df –h command to see the new LVM space.
Since we have created a new volume group (TestVG), we do not have to use lvextend command in order to extend the LVM partition. If TestVG were an existing volume group in which we added two new disks, then we had to use the following two commands to expand the LVM and to extend the file systems.
root@debian:/# lvmextend -L +4.3G /dev/TestVG/TestLV
root@debian:/# resize2fs /dev/TestVG/TestLV
Adding a second hard disk to an existing volume group.
For instance, you have only one hard disk in your Linux system, and need to more space in order to add capacity.
#Press ‘n’ to create a new partition.
# press ‘p’ for creating primary partition
#press enter to assign the size of default first sector
# +20B (for the last sector; it will add 20GB of space)
# Press ‘w’ to write
#vgextend debian-vg /dev/sdb1
For example you want to extend the /var directory
# lvextend /dev/debian-vg/var /dev/sbd1
# resize2fs /dev/debian-vg/var
How to migrate data from Linux drive to SAN (storage area network)
At first, you need to initialize the SAN device using the following command:
For example, your current volume group name is TestVG. Extend this volume group for SAN.
# vgextend TestVG /dev/sde
# pvmove /dev/sdc /dev/sde
# pvmove /dev/sdd /dev/sde
Now, you can reduce the local drive.
#vgreduce TestVG /dev/sdc /dev/sdd
Mount a USB drive to expand Linux disk space
#mount /dev/sdb1 /mnt/usb