Making your drive larger if you have a LVM drive

LVM is the Logical Volume Mapper, which lets you tell Linux that a volume (drive or partition) is part of a group of volumes/drives/partitions, which are considered one drive and which act together as one, called a "volume group". 

If you run out of space on a Linux machine and you are using LVM, you can enlarge the drive and make it act as if it were a single drive, by adding another drive and then telling it to add that drive to the LVM volume group.

You can tell that your drive is LVM if you see mention of LVM in the output of the "disk free" command, df. Note the wording "dev/mapper"

Filesystem                         Size  Used Avail Use% Mounted on

udev                               399M     0  399M   0% /dev

tmpfs                               85M  956K   84M   2% /run

/dev/mapper/ubuntu--vg-ubuntu--lv  194G   93G   93G  51% /

Here's the simplest way to do it.

Assume you have an existing drive called /dev/sda1, and it is almost full. Assume you have added either a virtual disk image (VDI) (in a virtual machine environment), or, an actual physical new disk to your server. Let's call that drive, drive B, ie /dev/sdb.

Here are the steps.

1. Erase as linux format. (I think this may be optional):

 mkfs.ext4 /dev/sdb

2. Tell the volume grouper to consider /dev/sdb a LVM (volume grouper) volume:

pvcreate /dev/sdb

3. Get the name of the volume group. In this case, we see it gives ubuntu-vg as output:

vgdisplay 

4. Tell the volume grouper (LVM) that the group which currently contains /dev/sda to now include /dev/sdb under the volume group ubuntu-vg:

vgextend   ubuntu-vg /dev/sdb

5. Lastly, extend the filesystem in size to now include the additional space of 100GB:

lvextend -r -L +100G /dev/ubuntu-vg/ubuntu-lv

if the above command gives an error about "not enough" something or other, just reduce the number 100GB by 1 GB and see if that helps, ie 99GB. If it still complains, try 98GB. 

Warning

If one of your drives which forms part of a volume group fails, you may lose all the contents of your volume group, particularly if any files are written across two drives. I have had this happen before but I do not know if Linux has fixed it since I last had this happen. I suggest you make sure you always have backups.

Popular posts from this blog

ZFS syntax (updated)

/var/log/journal taking up lots of space

throttle traffic on apache