Time to time we can face the problem that our storage is running out of space on our Linux box. Now what options do we have?
We can attach a new storage to the system and mount it in the filesystem but that gives us less flexibility, let’s say we have 100GB free space left, and we have a 100GB disk to use. Now we can mount it in a subdirectory in our filesystem, but if we have a 150GB file to store on the machine, then we have a problem.
Luckily LVM is to the rescue. It let you expand a logical volume throughout multiple disks, behaving like spanned volumes in the Microsoft world, which writes data sequentially to the volume, filling up the physical devices one after another. Slower than a RAID0 type array, but safer in case of a disk failure. However, if needed stripping can be configured on LVM, more on this later.
In our example we start with a 2TB volume, consists of four 512GB physical disks, mounted in /BigVolume.
STARTING STATE
Let’s assume we are running out of space on the volume and we need 200GB more. The beauty of LVM is that we can add a new disk with any size to our virtual group, and expand our volume on the fly, without any downtime.
ADDING THE NEW DISK
We add a 200GB disk, not a regular 256GB sized as let’s say this is all we have. As the default physical extent size is 4MB by default that we use here, we can specify any sizes that are an increment of these extents.
Here is the system after adding the disk. Note, that after adding the disk to a virtual machine we can either reboot the box or we have the option to rescan the SCSI buses while powered up:
echo "- - -" > /sys/class/scsi_host/host0/scan echo "- - -" > /sys/class/scsi_host/host1/scan echo "- - -" > /sys/class/scsi_host/host2/scan …
Depending on how many “hostX” buses you have, these commands scan all the “channels, SCSI targets and LUNs” on each.
There we go, the disk is recognized as /dev/sdf
First we set it up as a physical disk for LVM, then add it to our existing virtual group called “MyVG”. Then we can expand our VOL volume from 2TB to 2.2TB, adding all the available extents (4MB) to it. As a last step we expand the EXT4 file system on the volume on the fly.
# Set disk as a physical LVM disk pvcreate /dev/sdf # Add the disk to the VG group vgextend MyVG /dev/sdf # Expand the “VOL” volume to the maximum available size lvextend -l +100%FREE /dev/MyVG/VOL # Expand the filesystem to occupy the whole volume resize2fs /dev/MyVG/VOL
We have our volume intact, expanded by 200GB now, without any downtime 🙂
Comments