One of the common tasks for any system administrator is managing disk space on a server. It doesn’t matter what operating system the server is running, free disk space is always something you keep an eye on. I won’t go into a boring lecture on why managing disk space is critical, as I’m sure many of you are well aware of what happens when a server runs out of available disk space. So, instead of getting that phone call or page saying that your server is out of space, you can manage your free space by adding more of it dynamically! Yes, with a single reboot of your machine (to install a physical or virtual disk), you can easily add more space and keep things running smoothly.
For demonstration purposes, this article will be focusing on adding more disk space to a virtual Redhat server which has a single virtual disk of 25G in size. That disk only has 1G of free space, and you need to add another 25G to handle a new application’s install and projected growth. It’s important to note that you can add more space to existing volume groups in a LVM setup. LVM is the default type of disk management that Redhat uses, so you should already have that setup. If you went the more classic route and just made partitions on the physical disks, this tutorial won’t be much help as you can’t expand existing partitions like that.
With these requirements in place, here’s a quick summary of what we’ll be doing:
1. Present a new physical disk to the server
2. Adding the new physical disk to an exisiting Volume Group.
3. Expanding a logical volume within that Volume Group to use the new disk space.
4. Notify the operating system about the change in size.
Step 1: Present the new physical disk to the server.
This is a fairly easy step. Since we’re setup with a virtual machine, we just need to login to vSphere, shutdown the operating system, and add a new virtual disk through the Settings menu. For our demonstration, I’ll be adding a new 30G disk. If you’re working with a physical server, you would need to add the new hard drive, and make sure the BIOS can see the new drive. Once you have the new drive added (either physical or virtual), start the server up again and let Redhat boot.
Step 2: Add the new physical disk to an existing Volume Group.
Now, let’s verify that we can see the new disk. If you perform an fdisk -l command, you should see the new disk. Here’s a sample output:
Disk /dev/sda: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 3133 25061400 8e Linux LVM
Disk /dev/sdb: 25.7 GB, 25769803776 bytes
255 heads, 63 sectors/track, 3133 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
In this example, we have 2 25G drives, /dev/sda and /dev/sdb. Obviously, these values will be different for your physical or virtual disks, depending on the size you installed. Now that we’ve verified that the OS can see the new drive, we need to add it to the existing Volume Group. Information about existing volume groups can be obtained through the vgdisplay command:
# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 24.84 GB
PE Size 32.00 MB
Total PE 1531
Alloc PE / Size 1529 / 24.78 GB
Free PE / Size 2 / 64.00 MB
VG UUID QoI2Oi-E8S5-l7o2-4YIo-X3lT-sGXK-kBlhyT
Before we can add the new disk to the volume group, we need to do a special format command that will turn the disk into a physical volume. This makes the disk compatible with LVM. To do so, issue the pvcreate command as such:
# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
Now that the disk is a physical volume, it can be added to a volume group. You can do this by using the vgextend command as such:
# vgextend VolGroup00 /dev/sdb
Volume group "VolGroup00" successfully extended
The new physical volume has now been added to the volume group and is ready to be allocated to a logical volume.
Step 3: Expand the logical volume to use the new space
Next, we need to run the lvextend tool to expand the volume to use the new space. For this command you need to get the path to the logical volume, which you can get by running the lvdisplay command Here’s the command to expand the volume:
# lvextend -L+24.9G /dev/VolGroup00/LogVol00
Rounding up size to full physical extent 24.90 GB
Extending logical volume LogVol00 to 47.8 GB
Logical volume LogVol00 successfully resized
Now we’ve got the new space added, but the filesystem doesn’t know about it yet.
Step 4: Update the filesystem to use the new space
The last step in the process is to resize the file system residing on the logical volume so that it uses the additional space. Since we are running Redhat, we can use the
resize2fs command as such:
# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.41.4 (27-Jan-2009)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
After a bit of a wait, the OS will present that it’s complete and now our / filesystem has been expanded by roughly 25G! Now you can breath a bit easier.
This is a very basic introduction to LVM and expanding disk sizes, if you’d like more information or want help in expanding your system, feel free to comment below! I’ll be happy to assist.
Bradley Tinder, Systems Integrator, SPK & Associates