Need to resize the EXT4 partition on your Linux device? If you want a less risky method so you don’t have to lose your data, then this tutorial is for you.
In many cases, Linux users need to resize their partitions so that they can get the best out of the free spaces. But it seems to be a difficult and risky process. A lot of the advice out there is outdated too. So we made this easy-to-follow guide so that you can resize the EXT4 or other partitions on Linux with ease.
Prerequisites to Resize EXT4 Partition on Linux
Before you start resizing anything, make sure you have everything in place:
- Root access. Else, you will need to type sudo a lot.
- Unmounted partition. While it’s possible to “live resize” a mounted one, it’s not at all recommended, especially for beginners.
- Disk space. You need to have free space left after the partition you want to resize. You will see why later in the tutorial.
- Data Backup. You should always be on the safe side by backing up your important data.
- Terminal for issuing commands
How to Resize EXT4 Partition on Linux
Once you have fulfilled all the requirements, head on to the steps to start resizing the EXT4 partition.
Resize EXT4 Partition on Linux Using Terminal
In this portion, we are going to go over the necessary means to resize the partitions using the Terminal
Resize With the growpart Command
In this method, we will only issue commands from the Terminal to resize the partitions. For that, we will use the
growpart command. But before that, you need to install the “cloud-guest-utils” package. Install it with this command:
$ sudo apt install cloud-guest-utils
Once the installation is done, you can start using the
growpart command. Use it like this to resize a partition:
$ sudo growpart /dev/sdX N
Replace X with the correct disk name and N with the correct partition number. So an example code for resizing the first partition on
/dev/sda would look like this:
$ sudo growpart /dev/sda 1
If you’re not sure which partition you want to resize, or you want to double-check, use this command to get a detailed table of all your disk partitions:
$ df -h
After that, you can continue with the resizing. So first, issue the
$ sudo growpart /dev/sda 1
Since there are other partitions blocking space in our case, the change didn’t take effect. You can remove the other partitions first and then use this command to enlarge the wanted partition. So if you’re facing the same problem, follow these steps:
Use the following command to tweak the disks in your system:
$ sudo cfdisk dev/sda
You should enter a screen like this one below:
From there, choose any partition you want to be removed or modified. You can use “Delete” to delete the partition or “Resize” to modify the space.
Once done, use “Quit” to exit. Now run the
growpart command again:
$ sudo growpart /dev/sda 1
If it was successful, you should get a message like this:
“CHANGED: partition=N start=NNNN old: size=NNNN end=NNNN new: size=NNNN,end=NNNN”
The Ns are just placeholders for the old and new sizes of your disks.
After that’s done, run this command:
$ sudo e2fsck -f /dev/sdb1
The above command will check for your EXT4 file system and see if it’s clean. Adding the
-f flag forces it to do the checking even if your file system looks clean.
Now follow that with this command below:
$ sudo resize2fs /dev/sda 1
You should receive a message about the new block size of the partition.
This command is super helpful for resizing EXT 2/3/4 file systems. You can enlarge or shrink an unmounted file system with it.
Resize with the
Another way to resize an EXT4 partition in Linux is to use the
fdisk command. It’s a bit of a lengthy process but it does the job.
Before doing so, unmount the specific partition with this command:
$ umount <partition>
$ # For example, umount /dev/sda1
Use the below command to start the resizing process:
$ sudo fdisk /dev/sda
You will be asked to input something into a prompt after the message “Command (m for help)”. Enter ‘p’ to print the partition table.
Then enter ‘d’ to delete a partition. Enter the partition number you want to delete. If you want to delete multiple partitions, you can do so in this same process.
Now enter ‘n’ to create a new partition. You will be asked what type of partition you want to create. Enter ‘p’ for primary or ‘e’ for extended. Then give it a partition number. After that, determine its size by appointing a starting point and ending point. You can check the below screenshot to understand what we mean.
As you can see, you need to input the correct range to make it work.
You can create more partitions in this way. Here we created an extended partition, as seen in the picture below.
You can enter ‘p’ to see the new partition table. Once done, add the logical partition in the same way.
Recheck the partition table by entering ‘p’ again. Then enter ‘t’ to change a partition’s system id. For the partition number, enter the one for the logical partition. And for Hex Code, enter 82.
You can enter ‘p’ once more to confirm if it worked. Then enter ‘w’ to write the table to disk and exit.
When that’s done, use this command to verify if there are any errors:
$ e2fsck -f <partition>
Then follow it with this command for extending the file system:
$ resize2fs <partition>
Now mount the partition again with this command:
$ sudo mount /dev/sda1 <directory>
Resize with the
The parted command is another great utility for creating and resizing Linux disk partitions.
Install parted on your device using this command:
$ sudo apt-get install parted
If you’re running into some ‘lock files’ errors while installing it, this guide shows you how to solve them.
Run this command to enter the tool:
$ sudo parted
You can now issue different commands to work inside the parted environment. For example, enter ‘print’ to see the current disk spaces.
To resize a partition, run this command inside parted:
Then enter the partition number you want to resize. Lastly, allocate the size of the partition.
Now enter ‘print’ again to check if the resizing took place.
Resize EXT4 Partition on Linux Using GUI
If you’re more comfortable working with the GUI, then you have the option to resize the EXT4 partition from there. We will use “Gparted Partition Editor” for that.
First, you need to install it. So use the following command:
$ sudo apt install gparted
After you install it, launch the application with this command:
You will get a password prompt. Enter your password to proceed.
Once you enter your password, Gparted will start, and you should see the following screen:
As you can see, you get a clear graphical representation of your disks, how much space each contains, and any free memory.
From the menu button, you can create a new partition, delete a partition, resize or move a partition, and more.
After you finish resizing, check back your disks to see if you have changed their sizes. You can use this command:
$ df -h
You can also use this command:
$ lsblk -f
When Should You Resize Partitions?
Resizing partitions comes with great responsibilities. So this isn’t something you should take lightly. Only resize your Linux partitions when it’s necessary. This includes situations when –
- You run out of space.
- You want to redistribute space.
- You want to change the partition layout.
- You want to improve performance.
Best Practices to Resize EXT4 Partition on Linux
If you want to resize the EXT4 partition or any other partitions on Linux, you should follow some best practices. These tips will help you complete the resizing process with less hassle and risks.
Back-Up all the Important Data
You never know when something can get wrong. And trust us, it’s very natural that something may get wrong when dealing with partitions’ sizes. So create a backup of at least your important files and documents. But it’s best to save everything.
Unmount the Partition
Unmounting the partition ensures you’re not directly writing any data into it. After you finish resizing, you can mount the partition again.
Check the File System
Different file systems may have different methods of resizing. We’ve covered EXT4 types here. Several other file systems may require different tools and prerequisites.
Verify the Resizing
After you resize a partition, you should verify whether it really worked or not. You can do this in multiple ways. You can use:
- df -h
- print(if you’re using parted)
Any of these commands will let you know the before and after disk spaces so you can notice any changes.
Reboot After Resizing Your Partitions
It may not always be necessary, but you should reboot your Linux device after changing the disk and file system sizes. Sometimes, it’s also necessary to do a reboot for the changes to take effect.
Reboot using the following command:
$ sudo reboot
Resizing partitions in your Linux system is definitely challenging. There is also the risk of data loss. That’s why we recommend you create a backup of all your data.
If you’re a total beginner, it’s safe not to resize partitions without prior knowledge. You can either ask an expert to deal with it on your behalf. Or you should learn about disk partitions, resizing them, and the necessary comments thoroughly first.
Of the two ways we showed you, the GUI method seems to be newbie-friendly, so you may want to follow that. If you need any help with following this tutorial, let us know in the comments.
If this guide helped you, please share it.