How To Automatically Extend The Storage Volume For Cent OS?

To automate resize the storage/disk volume of the Cent Os virtual machine on 1st-time startup of the virtual machine in VMware after VM creation. Follow the given below steps to add the script for auto disk resize.

User Query:

I have a Cent OS 7 Server (CentOS Linux release 7.3.1611 (Core)) When I have updated my server I saw an error you need extra space. But I had a 20GB disk on the server when I check disk spaces I saw only 4.5GB partition created and 16GB partition is free space not unallocated. How I can extend the partition from 16GB of free space?

Source

After creating the virtual machine and before converting it to a VM template, add the given below scripts to your VM template.

In order to Extend The Storage Volume For Cent OS login as the root user.

  • # vi /root/script.sh
  • #!/bin/bash
  • fdisk /dev/sda << FDISK_CMDS
  • n
  • w
  • FDISK_CMDS
  • partprobe /dev/sda
  • a=$(vgs | awk ‘ NR==2 {print $1;}’)
  • vgextend /dev/”$a” /dev/sda3
  • b=$(vgdisplay | awk ‘ NR==17 {print $3;}’)
  • lvextend -L +”$b” /dev/$a/root
  • xfs_growfs /dev/$a/root
  • # chmod +x /root/script.sh
  • # echo “sh /root/script.sh” > /etc/rc.local
  • # chmod +x /etc/rc.local

After adding the above script, shut down the VM and convert in a VM template.

Note:-

  1. You can make your own Cent OS script and you can change the script location path to anything. For Logical volume name or if you have ext4 file system then you can use the given below command
    # resize2fs /dev/volume_groups/Logical_volume
  2. Blank space after “n” means enter

This step-by-step guide will help you extend the storage space of your Cent OS in a simple. Following these steps will help you extend the storage space of your Cent OS in a few clicks only even without having so much technical understanding. These steps will definitely help you to do so.

Related Articles:

Looking for Something More? We can help!

Our WHMCS experts are ready to accept your custom requirements.