Monday 4 January 2016

Linux - expanding LVM volume

I have set up a new media sharing Debian box which I need to expand the size of the existing home logical volume to allow me to store my media content in one place. The process is relatively straight forward assuming the server has LVM up and running already. We need to follow the process of:-
  1. Install the new disk(s)
  2. Partition the new disk(s)
  3. Prepare the PV's (Physical Volumes)
  4. Extend the existing VG (Volume Group)
  5. Extend the existing LV (Logical Volume) and the associated filesystem
Currently the server has a single 250GB drive, to which I am adding 2 x 2TB disks that have been liberated from Desktop USB HD enclosures. Sure they may not be the fastest drives, or have the best MTBF numbers but they were cheap and serve my reuse and make do approach to IT. After powering the system down, installing the drives and booting back up again I can check my drives are in place using the command fdisk -l. Assuming the disk(s) are all present and correct simply delete any existing partitions and create a new one on each disk. Use caution with fdisk as you could delete your data if you make errors. Use your favorite search engine if you are not sure. In my example there are 2 x 2TB disks, so I have 2 new PV's to create as shown below:
root@content:~#pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
root@content:~#pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created
Once the PV's are created we need to extend the existing volume group (which on my system is called content-vg):
root@content:~#vgextend content-vg /dev/sdb1
  Volume group "content-vg" successfully extended
root@content:~#vgextend content-vg /dev/sdc1
  Volume group "content-vg" successfully extended
Once we have extended the volume group to include the 2 new disks, we just need to expand the logical volume and file system to use the free space:
root@content:~#lvextend -r -l 100%FREE /dev/content-vg/home
Now when we check with df we can see the increased space available on my home volume. Other command useful along the way are pvdisplay vgdisplay and lvdisplay. I am not about to document them all here, as compious information is available 3 clicks from your favorite search engine. Once we have extended the volume group to include the 2 new disks, we just need to expand the logical volume and file system to use the free space: Thats All Folks.

No comments:

Post a Comment

All comments made are subject to moderation.