Home » Categories » Multiple Categories

Resizing The VM Disk Size For CentOS 7

Overview

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)

 

 

Important!

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:

================================================================================
==== WARNING: DO NOT EXECUTE THIS IF YOU HAVE MODIFIED YOUR DISK PARTITIONS ====
================================================================================
- 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.

 

 

Manually

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:

reboot

 

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. 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):

resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/centos-root is mounted on /; on-line resizing required
old_desc_blocks = 8, new_desc_blocks = 10
The filesystem on /dev/mapper/centos-root is now 20184065 blocks long.

 

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:

http://support.nagios.com/forum/

0 (0)
Article Rating (No 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 - License Maintenance Status Check
Viewed 4893 times since Thu, Feb 25, 2016
Nagios Network Analyzer - How To Configure SSL
Viewed 1601 times since Thu, Jan 28, 2016
Nagios Log Server - Managing Indices
Viewed 1686 times since Thu, Jan 28, 2016
Nagios Network Analyzer - Integrating Network Analyzer With Nagios XI And Nagios Core
Viewed 3059 times since Thu, Jan 28, 2016
Nagios XI - How to Manage Remote Nagios XI Servers
Viewed 2617 times since Thu, Jan 28, 2016
Nagios XI - Offloading MySQL to Remote Server
Viewed 4654 times since Thu, Jan 28, 2016
Nagios XI - Changing The System Time
Viewed 4418 times since Mon, Jan 25, 2016
Nagios XI - Understanding the Nagios XI Directory Structure
Viewed 2583 times since Thu, Jan 28, 2016
Nagios XI - Configuring SSL for Nagios XI
Viewed 3229 times since Wed, Jan 27, 2016
Nagios XI - Using The Custom Includes Component
Viewed 3671 times since Tue, Oct 18, 2016