Enlarge Linux Partition using ext4 filesystem. (Without LiveCD) Ubuntu 20.04 LTS.

shape
shape
shape
shape
shape
shape
shape
shape

In this tutorial I’ll show you how to enlarge a Linux partition that uses the ext4 file system. What is usually done in this process by users is to use a LiveCD to boot up, and from running the system directly from the cd or pen drive, they edit the root partition of the system, but there is a way to perform this process by booting normally from the system installed on your disk.

In this process we will use Linux Ubuntu 20.04 LTS, and the procedures will be carried out via the command terminal, you will need to be logged in as the root user. I recommend that you back up your data before carrying out this procedure, and save it on an external drive in case you need to restore it.

Assuming that you have already made the backup, the first thing to check is the disk, we need to know what the total size of the disk is, and what the total size of the partition being used is. To do this, use the following command:

lsblk

We have the following output:

In my case my disk is the sda device, and it has 20 Gb of space, and my partition is only using 9.3 Gb of the total disk space.

We can also see this information using the following command:

fdisk -l /dev/sda

We have the following output:

To manipulate the disk we will use fdisk, type the following command in the terminal:

fdisk /dev/sda

In my case the disk is sda, if in your case the disk to manipulate is another, type the command selecting the corresponding disk, example:

fdisk /dev/sdb.

With fdisk open, type the letter p into the terminal, this will list the existing partitions.

In the first rectangle we can see the disk again, and in the second the partition it has, in my case I only have one partition the rest of the disk space is not being used.

We’ll have to delete the main partition, that’s right delete it, don’t worry your system won’t stop working after deleting the main partition, these changes will be applied when you exit fdisk. If you have other partitions on your disk, and you want to delete them to make the main partition bigger, they must be unmounted before using fdisk to delete them. You can unmount partitions using the command umountor if it is a swap partition, the command to unmount it is swapoffAfter unmounting the partition, it can be deleted.

To delete a partition use the d command in fdisk, in my case I only have one partition, so it was deleted directly, if there is more than one partition you will be asked for the number of the partition you want to delete.

After deleting the main partition we will have to create a new one, now with the desired size, to create a new partition type n in fdisk, you will be asked for the type of partition, the partition number, first sector and last sector, enter the data as desired, in the example it was:

Partition type: primary

partition number: 1

first sector: 2048 (Where to start the partition on the disk)

last sector: 41943039 (This is where we define the size, we can indicate the sector, or also the desired size, example: +20GB)

When asked if you want to remove the signature, type no.

New partition created, we can again use the p command to check the partitions.

After checking the new partition, we have a very important step that cannot be missed or ignored: we have to tell the system what our boot partition is, if we don’t do this the system will no longer start. DON’T SKIP THIS STEP.

To indicate the boot partition for the system, use the a command in fdisk.

in my case it selected partition 1 automatically because I only have it, but if there is more than one partition, select the boot partition indicating the number of the corresponding partition.

After assigning the boot partition, we can write the changes to disk and exit the fdisk disk utility.

To do this, use the w command.

Once you have completed the steps using fdisk, you must restart the system.

Once the system has restarted, we still have one last step to take: we need to use the resize2fs command so that the system sees all the space allocated to the new partition.

Run the following command:

resize2fs /dev/sda1

We will have the following output:

Finally we have our partition with the new size, we can see this information using the commands:

lsblk
df -h /dev/sda1

We have the following output:

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest news

Latest news directly from our blog.