This assumes you already have expanded the hard drive within VMware or VirtualBox, or whatever your virtualization solution you use. You will also need to make sure parted is installed on the system you are working on. This guide is using GNU parted 3.1
Disclaimer: Parted is a partition modification tool make sure you have a good backup/snapshot of your machine before proceeding as you may lose data when using the parted tool. I am not responsible for your lost data. Again, make sure you have a VALIDATED backup or snapshot of the machine you are working on.
Steps on Linux
- Get linux to recognize the new hard drive size
To check what size hard drive linux sees run:
You should see something like the following:
- Extend the partition table.
Depending on the number of physical drive you have you may have to select the disk you want to modify. I only have one disk and did not have to do this. but you may need to run the command:
selectAnd enter your drive device that you got from the information in step 1.
I always run
You will then run the command:
resizepart XWhere X is your partition number that you are expanding. You will then be asked how big you want the partition to be. I set this to the size of the hard drive as it appears in linux. In my case it reads 322GB even though it is 300GiB. I set slightly over to make sure I captured all of the disk and it seemed to shrink it down the appropriate amount. So I would recommend this to other users, but I have not tested it myself.
I reran the
- Extend the Physical Volume
This is easy enough just run
Where “/dev/X” is your device. No other parameters are needed it will extend the physical volume to the maximum usable size. I verified this by running
pvsbefore and after the
- Extend the Logical Volume
Now there are a few ways you can go at this point if you want to extend multiple Logical Volumes you would use a command like this:
lvresize -L +500M /dev/VG/LV
Where “+500M” is the size you want to increase the logical volume by and “/dev/VG/LV” is the path to the logical volume you want to extend.
In my case however, I only wanted to extend one logical volume and I wanted it to use the rest of the physical volume possible, so I used the command:
lvresize /dev/centos/root /dev/sda2
lvresizeto use all available space on the physical volume for my logical volume /dev/centos/root.
- Extend the Partition
This part depends on your filesystem type, you can figure this out with the command
df -ThIf you are using ext2/ext3/ext4 you want to to use the resize2fs tool. See the man page for more details on how to use this tool. But the jest of it is:
I however am using xfs as it is the default for CentOS 7. I ran the command:
This finishes nearly instantly and rerunning:
df -Thwill show you if the new size has taken or not.