1-888-310-4540 (main) / 1-888-707-6150 (support) info@spkaa.com
Select Page

How To Add More Disk Space To Your Redhat Server Without Reformatting

Add More Disk Space To Your Linux Server image
Written by Mike Solinap
Published on January 14, 2022
(Originally published in 2012, updated January 2022.) One of the common tasks for any system administrator is managing disk space on a server. A common question is how to increase disk space on a linux system. I won’t go into a boring lecture on why managing disk space is critical.  I’m sure all 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.

Let’s use RedHat for our example.

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. The disk only has 1G of free space, and we need 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 an LVM setup. LVM is readily available in the linux kernel, so no packages need to be installed in order to enable it.   Alternatively, there’s a method that involves deleting partition tables and recreating them. 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 existing 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. We can use the resize2fs> command.  This assumes your filesystem is ext3 or ext4.  If you are utilizing xfs, you can look at the xfs_growfs command.:
# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.41.4 (27-Jan-2009)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
As resize2fs progresses, you will notice that the amount of free space will start to slowly increase.  After a bit of a wait, the OS will present that it’s complete and now our root filesystem has been expanded by roughly 25G! Now you can breathe 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 contact us!  SPK has deep knowledge in infrastructure, both physical and cloud.  We’ve been working with Unix/Linux for over 20 years.  We can assist with upgrades, migrations, or simply take on the management of some of your infrastructure for you. Bradley Tinder, Systems Integrator, SPK & Associates

Latest White Papers

DevOps Visibility and Metrics for Driving Business Value eBook

DevOps Visibility and Metrics for Driving Business Value eBook

To reliably measure the business value of the software developmentprocess, organizations need better visibility across the softwaresupply chain. How do businesses improve DevOps visibility, and how does this drive business value? Find the answer to these questions and...

Related Resources

Why Microsoft Azure is the Manufacturing Industry’s Trusted Partner

Why Microsoft Azure is the Manufacturing Industry’s Trusted Partner

As the manufacturing industry continues its evolution, the choices we make today can shape the future of our operations. At SPK and Associates we’ve seen this happen repeatedly with new clients either in sticky situations, or struggling to scale. Basically, technology...

4 Advantages of SolidWorks Cloud PDM (Updated 2023)

4 Advantages of SolidWorks Cloud PDM (Updated 2023)

Considering the leap to cloud-based CAD and PDM solutions? A move to platforms like SolidWorks 3D CAD in the cloud paves the way for unmatched flexibility. Imagine accessing intricate engineering data from anywhere at any time. And, the benefits don’t end there. In...

DevOps as a Service Supercharges Development Pipelines

DevOps as a Service Supercharges Development Pipelines

It seems like just about every company is now a part-time or full-time software company. But, for small and mid sized companies, employing effective practices, such as DevOps to manage the day-to-day, might not be feasible. However, there is a solution. It’s called...