This post is about using growpart to extend a non-LVM Linux partition. For extending a LVM volume, see my other posts - Extend a Linux LVM Volume on a VM part1, part2, and part3.
When increasing the size of a Linux parition, it normally requries the following procedures:
- Increase the size of the physical or virtual hard drive
- Extend the partition to added drive space
- Resize the file system to extended partition
Among these steps, step #2 usually sounds risky. It requires to delete the existing partition and recreating it with the new size. Most people are not confortable to do that, and they end up with adding a new bigger drive, creating a new bigger partition, formatting the new partition, and copying the files from the old partition to the new bigger. This not only is time comsuming, but only requires more physical or vritual disk space.
Recently I learned about growpart that makes step #2 much simpler and error free. Growpart may not be installed by default, but it should be available on your distro. The following is the commands to increase a Linux partition (/dev/sdb1) on CentOS.
- sudo yum install cloud-utils-growpart
- increase the disk size (e.g. /dev/sdb) and reboot
- sudo growpart /dev/sdb 1 ### there is a space between sdb and 1. 1 is the partition number
- sudo resize2fs /dev/sdb1
See growpart man page for more info.