In this guide, we will show you how to use the resize2fs instruction in the Linux shell to resize partitions. Before moving on to resizing partitions, we must ensure that our Linux system is fully updated and upgraded. If not, open your shell application from the Linux system and try the instructions shown below using the "apt" utility in its query area. The update instructions will update your Linux system within a few minutes.
After updating your Linux system, make sure you are using an upgraded system. By trying the upgrade instructions through the "apt" utility, you can ensure that the system has been upgraded.
The Linux system upgrade process, for example Ubuntu 20.04, may require your confirmation to proceed with the system update. You should tap "y" from the keyboard and press Enter.
Before resizing partitions, we should have an overview of all the disks or devices in our Linux system. To check partitions, Linux provides the "lsblk" instruction. After running it, we have all the devices listed on the terminal screen. Our virtual drive "sda" is listed below in the list with a size of 40GB. In addition, it has 2 partitions. The sd1 partition is the root directory while the other is the main drive.
Whenever you want to get more information about the drive you have, and its partitions, you tend to use the fdisk instruction in the shell. The fdisk instruction should be used with the path to the "sda" drive, which is "/dev/sda".
After executing these instructions, you will enter an interface where you can make adjustments to sda. Write "p" to get drive information such as its model, total units in bytes, sector size, input/output parsing size, label type i.e., des, and identification number along with information about its partitions. You can see the total amount of memory assigned to each partition and the partition type along with some sector IDs and data.
After getting information about the partitions we have in the sda directory, we need to delete partitions to resize them. We can choose to delete any partition or all partitions and create a new one as well. To delete a partition from the "sda" directory, we must add the "d" keyword in the "Command" area.
After running the "d" command, we will be asked to add the partition number according to the partition we have. This partition number will determine the partition to be deleted. It will show you the partition number along with the default number of the partition to be deleted, which is the recommended partition number of 5.
Suppose you want to delete partition number 2 i.e. sda2. For this, enter "2" and press Enter to continue. You will get a success message that partition 2 has been deleted successfully. After this, try using the "d" instruction once again to delete another partition on the sda device. This time, it selects partition 1 itself and successfully deletes it as per the output. After deleting all partitions, I will not allow you to run the "d" instruction again.
After deleting all the partitions, we have to create a new partition within the same sda device. For this, try the "n" command in the command area we have provided. After using this instruction, you will be given two options to select the type of partition. The letter "p" refers to "primary" partition and "e" means "extend" partition. The "Select" query area wants you to specify the type of partition you want to create. If you do not specify it, the primary partition will be selected by default as shown in the figure below. You need to add a number to the partition. If it is not specified it will select number 1. Specify a size for this partition which is 2048 equal to 40GB.
After selecting the sectors, your partition will be successfully created, i.e. a partition of size 40 has been created. After this, you will be asked a question whether you want to delete the signature or not. Tap "Y" to delete it; otherwise, tap "N" to avoid deleting the signature. Here, we will not delete the signature.
After using the "p" command once again, you will see that the device "sda1" has been created with size 40 and type "Linux".
Saatnya menulis perubahan. Untuk itu, Anda harus menggunakan instruksi “w” pada antarmuka sda yang sama dan tabel partisi Anda akan berhasil diubah. Disk kemudian akan disinkronkan bersama.
It's time to use the resize2fs instruction to resize your sda1 device according to the new partition we have created. For this, use the "resize2fs" instruction along with the path "/dev/sda1" in the Linux terminal as shown. After using this instruction, your sda1 partition will be resized.
The use of the "df" instruction with the "-h" option shows us that the sda1 partition has been resized automatically.