How to automatically extend the storage volume for Ubuntu OS

How To Automatically Extend The Storage Volume For Ubuntu Operating System?

To automate resize the storage/disk volume of the Ubuntu 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.


Custom WHMCS Solutions


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

Login as a 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 “$a” /dev/sda3
b=$(vgdisplay | awk ' NR==17 {print $3;}')
lvextend -L +"$b" /dev/$a/ubuntu-lv
resize2fs /dev/$a/ubuntu-lv
# 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 it to a VM template.

Note:- You can make your own script for you can change the script location path to anything. For Logical volume name or if you have xfs file system then you can use the given below command
# xfs_growfs /dev/$a/ubuntu-lv

Related Articles:

Looking for Something More? We can help!

Our WHMCS experts are ready to accept your custom requirements.