Home » Categories » Multiple Categories

Resizing The VM Disk Size For CentOS 7

Please Note: 

This article presents example Linux commands that can be used to accomplish the procedure on a particular operating system (or systems). These examples are provided for demonstration and edification purposes, and we do not provide support outside of these instructions for current, future, or different Linux distributions. Maintenance and support of underlying operating system or virtual machine architecture is the responsibility of the customer.


This KB article describes how to increase the size of a Nagios virtual machine (VM) disk. This documentation is specifically for the CentOS 7 VM's available for download from the Nagios Enterprises website for each of the following products:

  • Nagios XI
  • Nagios Fusion
  • Nagios Network Analyzer
  • Nagios Log Server

This KB article works on any of the CentOS 7 VMs as they have identical disk configurations.

If you are using a CentOS 6 VM then there is separate documentation for those VM's as each product had slightly different disk configurations:


If you are unsure what version of CentOS your VM is running on you can execute the following command:

cat /etc/centos-release

Version 6 will output something like:

CentOS release 6.9 (Final)

Version 7 will output something like:

CentOS Linux release 7.4.1708 (Core)




The actions required to resize the virtual machine are potentially destructive by nature. We strongly recommended that you make proper backups of your Nagios server before proceeding.

A snapshot of your virtual machine is one method to provide a way to "go back" if something goes wrong. However a snapshot can only be done once you add extra disk space to the virtual hard disk (the first step in this guide). It is not possible to take a snapshot before adding the extra disk space, the virtual technology does not provide this capability. It is recommended that you shutdown and power the VM off before taking a snapshot.



Resizing The Virtual Disk

The first step is to modify the amount of disk space VMware is allocating to your Nagios image. If you are using another hypervisor like Hyper-V or VirtualBox then these settings will be slightly different from the steps below.

It is recommended that you shutdown and power the VM off before resizing the virtual disk.

The virtual disk size setting you need can be found under:

(Your VM) > Summary > Commands > Edit Settings > Hardware > Hard Disk 1 > Capacity > New Size.

For VMware Player, the disk size setting can be found using the following options on the overview page:

(Your VM) > Edit virtual machine settings > Hardware > Hard Disk (SCSI) > Utilities > Expand > Maximum disk size.

Power the VM back on after increasing the disk space.



Terminal Access

The remaining instructions require you to establish a terminal session to your Nagios server as the root user.



Resizing The Partition / Filesystem

There are two methods available for resizing the partition and filesystem:



Automated With Script

The following commands will automatically resize the partition and filesystem on your VM. Once the script has completed it will automatically restart the Nagios server:

cd /tmp
wget https://assets.nagios.com/downloads/common/scripts/extend_vm_disk.sh
sh extend_vm_disk.sh


You will see output similar to the following:

- This script will extend your disk partition and filesystem.
- This script will only work on standard Nagios OVA distributions.
- Make a BACKUP of your VM before running this script.
- Your VM will reboot with the extended filesystem.
Do you want to continue running this script? [y/n]

You will need to answer y to proceed.


After the server reboots and you login as the root user in a terminal session you will see a message similar to:

Your root / partition and filesystem have been resized
Your disk size is now 85.9GB,
And your / filesystem is 77GB
The results of all commands are in /var/log/vm_resize.log


The sizes you see in the message above will differ depending on how much extra disk space you added.


This completes the automatic steps for increasing the VM disk size. You should log into the Nagios interface to ensure everything is working OK.

If you took a snapshot of your VM before proceeding you should now shutdown the VM and delete the snapshot as it is no longer required for roll-back purposes.




Follow these steps to manually resize the VM partition and filesystem.


Resizing The Partition

You need to modify the Linux partition table within the virtual machine to recognize that the disk size has changed. This can be done using the fdisk utility, which is a partition editor. For the virtual machine provided by Nagios Enterprises:

  • sda1 is used for the boot partition
  • sda2 is the device for all logical volumes, this is the partition you need to edit

Start fdisk by executing the following command:

fdisk /dev/sda


You should print the current partition table so you can keep track of your changes as you go:

Command (m for help): p

Take a screenshot or copy the screen contents into a text file in case you want to reference it later.

To resize a partition, you actually "delete" it and then add a new one with the new size, making sure to place the beginning of the new partition at the same sector/cylinder as the old one started. This process is NOT destructive, your data still remains on the disk. These first steps are for deleting the partition:

Command (m for help): d
Partition number (1-4): 2


These next steps re-create the partition:

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2


You will be prompted for the first and last sectors to use, simply accept the defaults for the start and end point (just press Enter). Double-check that they make sense when compared to the information printed earlier.

Next you need to configure the partition type to LVM (8e):

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'


At this point you are done making your changes, and just need to write them to the disk. It is a good idea to print (p) the new partition table to ensure you entered things correctly. Once thing look okay, you can commit (write) the partition table to disk: 

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.


The write command will exit the fdisk program. You will now need to reboot the virtual machine to allow the kernel to recognize the new partition table, execute the following command:



Resizing The Physical Volume (PV)

The CentOS system installed in the virtual machine image we ship uses Logical Volume Management (LVM) for its partitions. If you have never worked with LVM before and want to better understand the terminology herein, visit:

In order to make use of the newly increased disk space, LVM needs to be told that it is there and should be used. For this step you will adjust the size of the physical volume to match the new size of the partition. Establish a terminal session to your Nagios server and then execute the following command:

pvresize /dev/sda2


This should produce the following output:

  Physical volume "/dev/sda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized


Resizing The Logical Volume (LV)

The next step is to resize the logical volume to use the new space available in the LVM physical volume. Execute the following command:

lvresize /dev/mapper/centos-root /dev/sda2


This should produce the following output (it will differ depending on how much disk space you're adding):

  Size of logical volume centos/root changed from 36.99 GiB (9470 extents) to <77.00 GiB (24831 extents).
Logical volume centos/root successfully resized.


Resizing The Filesystem

The last step is to change the filesystem residing on the logical volume so that it knows to put files in that space.

First, determine if you have an xfs or ext filesystem by running the following command:

 df -Th /

The output should display the filesystem type in the Type column.

If XFS, then execute the following command:

xfs_growfs /dev/mapper/centos-root

If EXT, then execute the following command:

resize2fs /dev/mapper/centos-root

This should produce the following output (it will differ depending on how much disk space you're adding):

meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=406016 blks
         =     sectsz=512  attr=2, projid32bit=1
         =     crc=1       finobt=0 spinodes=0
data     =     bsize=4096  blocks=1624064, imaxpct=25
         =     sunit=0     swidth=0 blks
naming   =version 2        bsize=4096   blocks=2560, version=2
         =                sectsz=512   sunit=0 blks, lazy-count=1
realtime =none            extsz=4096   blocks=0, rtextents=0
data blocks changed from 1624064 to 4769792


You're done! You can confirm the disk resize worked by using df -h to display a summary of filesystem size and usage. 

If you took a snapshot of your VM before proceeding you should now shutdown the VM and delete the snapshot as it is no longer required for roll-back purposes.



Final Thoughts

For any support related questions please visit the Nagios Support Forums at:


4.33 (12)
Article Rating (12 Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
Nagios XI - Using rrdcached with Nagios XI
Viewed 4472 times since Thu, Jan 28, 2016
SSL/TLS - Understanding Certificate Warnings
Viewed 32176 times since Wed, Jun 14, 2017
Nagios XI - Update Components And Wizards
Viewed 4083 times since Sun, Feb 3, 2019
Nagios XI - Using SSL with XI Active Directory
Viewed 3770 times since Thu, Jan 28, 2016
Nagios XI - Profile Build Failed
Viewed 10634 times since Tue, Aug 2, 2016
Nagios Log Server - Removing An Instance From A Cluster
Viewed 2999 times since Wed, Mar 21, 2018
Nagios XI - MySQL/MariaDB - Max Connections
Viewed 33348 times since Thu, Jun 2, 2016
Nagios XI - Checking System Status
Viewed 5198 times since Wed, Jul 19, 2017
Nagios XI - Maximizing Performance In Nagios XI
Viewed 4665 times since Thu, Jan 28, 2016
Nagios XI - Utilizing a RAM Disk in Nagios XI
Viewed 6068 times since Thu, Jan 28, 2016