I’ve always felt there weren’t enough straight forward guides on how to do this. This is an example of how to (relatively) quickly resize & extend a disk on CentOS 6/7. This is used when increasing the size of a disk in a virtual machine, in this example I’ll use VMWare.
Important
Make sure you have a good backup of your data
This guide assumes you’re using CentOS 6.x or CentOS 7.x
This guide assumes you’re using vCenter 5+, although the process in CentOS should still stay the same in other environments
1) Power off the VM
2) Add disk space directly on the VM.
VM Properties -> Hard Disk -> Disk Provisioning -> Provisioned Size
3) Download and mount the gParted ISO (Available Here)
Ensure the VM is set to boot to BIOS, so you can configure the boot order, CD/DVD should be first. (VM Properties -> Options -> Boot Options -> Boot to BIOS)
You can mount the ISO from a datastore, or use the console by clicking the CD/Wrench Icon and selecting “Connect to ISO on Local Disk…”
4) Boot into gParted and resize the volume. You can select the default values for all prompts.
Click the disk, select resize
Change the ‘New Size’ to be the new size of the disk, click resize.
Click the disk, click apply/apply. (Note: If there are errors in gParted you should always read/investigate)
When complete, right click the previously locked drive(s) and click “Activate” then close.
Edit VM settings to boot into BIOS on next reboot
Shutdown the machine and boot back into BIOS, you’ll want to ensure the Hard Disk is first in the boot order
5) Boot into CentOS
6) It’s recommended you create a snapshot at this point, as if things go wrong it will be hard to recover.
7) If there’s a volume group, you may need to remove any missing volume group references.
Check volume groups
sudo vgs
Remove all missing physical volumes from the volume group
sudo vgreduce --removemissing
8) Find the physical volume you want to resize
sudo pvdisplay
9) Resize (expand) your physical volume.
sudo lvm pvresize -v PHYSICAL_VOLUME
10) Find the logical volume you want to expand
sudo df -h
11) Resize your logical volume and expand the file system to fit.
For CentOS 7 and below
sudo lvextend -l +100%FREE LOGICAL_VOLUME
sudo resize2fs FILESYSTEM
CentOS 7+ uses the XFS filesystem, therefore you should use xfsprogs
sudo yum –y install xfsprogs.x86_64
sudo xfs_growfs FILESYSTEM
12) Use df -h and fdisk -l to check disk usage and verify everything looks good
Comments