Resize root partition
We cannot predict what comes in the future even the size needed for the root partition
I am going to explain how to increase the size of ext4 in the root partition without restarting the server.
Before proceeding I would like to mention it is always recommended and good practice to backup the partition when it is not mounted since resizing a live partition a risk-related activity. The new size must be greater than the size of the existing data if not there will be data loss. This tutorial focuses on resize of Ext2, Ext3, or Ext4
If you are interested to know about the types of file systems in detail. You can refer to this article.
Check the partitions present in the system that are mounted by command:
df -h
Go to Partition table of the root device
The above partition is where the root is being mounted. Note down the sector number that is in the start section which is 4096 which we are going to use this start point when we recreate a larger partition.
If you need any help with commands and what they do you can press m
Delete the existing partition with 'd'
Type n for creating a new partition and follow the commands to create a primary partition with the same starting sector as before.
You can leave the last sector as default by not entering any number and just press enter.
Observe the partition table by command ‘p’ and see the device has started with 4096. If you observe our previous partition it had boot flag as ‘*’.
To make the partition bootable — Press ‘a’ to enable it
Save the new partition information with the command ‘w’ and you will exit out of the partition table.
To resize the partition run the command:
Run resize2fs /dev/sda1
Without any restart, the root file system will be resized to the new size.