Table of Contents
In this tutorial I will take you through the best steps to Install growpart command and Resize root partition in Linux (RHEL/CentOS 7/8). You might have faced a scenario where after installing Linux OS in your Server you needed more space in root partition to install more packages and libraries.
While you can increase the disk space from outside in AWS and Azure Cloud but to use that space inside the OS you need to extend the partition in partition table so that Linux will know about the addition of extra space and hence make it available for use. This work can be easily done by using tools like growpart, resize2fs, resizepart etc. Here we will only cover the installation and usage of growpart command in detail. We will see the usage of other utilities in later tutorials.
Best Steps to Install Growpart Command and Resize Root Partition in Linux(RHEL/CentOS 7/8)
Also Read: 50 Useful zypper command examples to Manage Packages on OpenSUSE Linux
Step 1: Prerequisites
a) You need to have a running RHEL/CentOS 7/8
System.
b) You should have yum
tool installed in your Server. You can check Top 22 YUM command examples in RedHat/CentOS 7 to know more about yum
command.
c) You need to have root
or sudo
access to run privileged commands. Please Check How to Add User to Sudoers to know more about providing sudo
access to the User.
Step 2: Update Your Server
If you have not updated your server from quite sometime then it is always recommended to update your Server first by using yum update -y
command as shown below. This will download and install all the latest stable updates from enabled CentOS Repo.
[root@localhost ~]# yum update -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.excellmedia.net * epel: epel.mirror.angkasa.id * extras: centos.excellmedia.net * updates: centos.excellmedia.net Resolving Dependencies --> Running transaction check ---> Package NetworkManager.x86_64 1:1.18.8-1.el7 will be updated ---> Package NetworkManager.x86_64 1:1.18.8-2.el7_9 will be an update ---> Package NetworkManager-glib.x86_64 1:1.18.8-1.el7 will be updated ---> Package NetworkManager-glib.x86_64 1:1.18.8-2.el7_9 will be an update ---> Package NetworkManager-libnm.x86_64 1:1.18.8-1.el7 will be updated ---> Package NetworkManager-libnm.x86_64 1:1.18.8-2.el7_9 will be an update ---> Package NetworkManager-team.x86_64 1:1.18.8-1.el7 will be updated ---> Package NetworkManager-team.x86_64 1:1.18.8-2.el7_9 will be an update ---> Package NetworkManager-tui.x86_64 1:1.18.8-1.el7 will be updated ---> Package NetworkManager-tui.x86_64 1:1.18.8-2.el7_9 will be an update ---> Package NetworkManager-wifi.x86_64 1:1.18.8-1.el7 will be updated ---> Package NetworkManager-wifi.x86_64 1:1.18.8-2.el7_9 will be an update ---> Package ansible.noarch 0:2.9.14-1.el7 will be updated ---> Package ansible.noarch 0:2.9.15-1.el7 will be an update ---> Package bind-export-libs.x86_64 32:9.11.4-26.P2.el7 will be updated
Step 3: Install Growpart Command in Linux Using YUM Utility
There are multiple ways to install growpart utility in Linux in which the first way is through the yum utility where you can simply run yum install cloud-utils-growpart -y
command to install the utility as shown below.
[root@localhost ~]# yum install cloud-utils-growpart -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.excellmedia.net * epel: epel.mirror.angkasa.id * extras: centos.excellmedia.net * updates: centos.excellmedia.net Resolving Dependencies --> Running transaction check ---> Package cloud-utils-growpart.noarch 0:0.29-5.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================== Package Arch Version Repository Size ======================================================================================================================================================================== Installing: cloud-utils-growpart noarch 0.29-5.el7 base 27 k Transaction Summary ======================================================================================================================================================================== Install 1 Package Total download size: 27 k Installed size: 61 k Downloading packages: cloud-utils-growpart-0.29-5.el7.noarch.rpm | 27 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : cloud-utils-growpart-0.29-5.el7.noarch 1/1 Verifying : cloud-utils-growpart-0.29-5.el7.noarch 1/1 Installed: cloud-utils-growpart.noarch 0:0.29-5.el7 Complete!
NOTE:
growpart
utility is available from EPEL
Repository so before installing growpart
package you need to make sure EPEL repo is installed and enabled. You can check more about this on How to Install and Enable EPEL Repository on RHEL/CentOS 7/8Step 4: Install Growpart Command in Linux Using RPM Utility
The second way that you can use is by installing through rpm package. In this case you need to first download the appropriate rpm version of growpart tool and then install it by using rpm -ivh cloud-utils-growpart-0.29-5.el7.noarch.rpm command as shown below.
[root@localhost ~]# rpm -ivh cloud-utils-growpart-0.29-5.el7.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:cloud-utils-growpart-0.29-5.el7 ################################# [100%]
Step 5: Resize root partition Using Growpart Command in Linux
Once it is installed you can now go ahead and resize the root partition. As you can see in below output root partition currently lies on /dev/sda
disk so we need to resize the /dev/sda2
partition.
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 500G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 499G 0 part ├─centos_ymr--hrm--01-root 253:0 0 50G 0 lvm / ├─centos_ymr--hrm--01-swap 253:1 0 15.8G 0 lvm [SWAP] └─centos_ymr--hrm--01-home 253:2 0 433.2G 0 lvm /home sdb 8:16 0 1T 0 disk sr0 11:0 1 1024M 0 rom
Here we need to resize 2nd partition of sda disk so we will use growpart /dev/sda 2
command as shown below. Check more on growpart
command Man Page.
[root@localhost ~]# growpart /dev/sda 2
Popular Recommendations:-
How to Start and Enable SSHD Service in OpenSUSE Linux
How to Start / Stop / Restart Network Service in OpenSUSE Linux
How to Check Stateful and Stateless Pods in Kubernetes Cluster
3 Easy Ways to Check/Find OpenSUSE Linux Version
6 Easy Steps to Setup and Manage Log rotation Using logrotate in Linux
Migrate CentOS 8 to CentOS Stream 8 in 6 Easy Steps
26 iostat, vmstat and mpstat command examples to Monitor Linux Performance
Practical Steps to Install iostat and mpstat command on Linux(RHEL/CentOS 7/8)