How to increase disk space in Linux? (2024)

increase disk space in linux

How to increase disk space in Linux: Running out of disk space in your Linux machine can be a difficult scenario that could impair system functionality and even result in the failure of vital services. Disk space expansion, however, is a frequent and doable procedure. We’ll go over how to increase disk space in Linux step-by-step in this tutorial, giving you the skills you need to handle the storage on your server.

How to increase disk space in Linux

1. Assessing Disk Space:

Before taking any actions, it’s essential to understand the current disk space usage on your server. You can use the 'df‘ command to display the available disk space and identify which partitions are running low.

df -h

This command will show you a summary of disk space usage in a human-readable format.

2. Identifying the Target Disk:

Determine which disk or partition you want to expand. Whether it’s the root partition or a specific mount point, make sure you have a clear understanding of the target location.

3. Backup Important Data:

Before making any changes to disk partitions, it’s wise to back up critical data to prevent data loss in case of unexpected issues during the resizing process.

4. Increase Disk Space in Cent OS using fdisk

Fdisk utility is very commonly used to increase disk space and it is quite simple. If you have a sandwich space where a swap partition is restricting you from increasing the space then you can delete that partition and increase the space.

check the disk partition identify the root partition and swap partitions run the below commands

lsblk
image 1
In the above list, sda2 is the root and sda3 is the swap partition

Confirm the swap partition by running the below command

fdisk -l
image
device /dev/sda3 shows partition type “Linux swap / Solaris” with ID “82”. Make a note of it

now, step 1 is to delete both partitions i.e. 2 & 3, and step 2 is to create the root partition with increased space and create a new swap partition again.

scan the disk to get the increased disk space from storage

echo 1>/sys/class/block/sda/device/rescan

launch fdisk for the disk where space needs to be created for our example it is /dev/sda (as we checked above lsblk command)

sudo fdisk /dev/sda

once launched type “p” and enter

it will show the partition table, please identify partitions to be deleted, in this example partition no. 2 and 3 will be deleted

type “d” then “2

type “d” again then “3

Now, re-create the both partitions

Create root partition

type “n” then “p” for the primary partition

press enter for the default value in start value

for the end value add the new Total space size that you want to add to the root partition. For example, the old space is 8GB and you added 6 GB so the total will be 14GB.

+14G

press “n” for signature update

create a swap partition

type “n
type “p” for primary partition press enter for default value in start
press enter again to get the maximum value for swap partition

NOTE: It is necessary to specify that the new partition is to be a swap partition.

type “t
enter partition “3
Hex Code “82” (as noted above)

image 2

It will confirm the partition has been changed to Linux Swap / Solaris.

type “w When you are sure the partitions are correct and ready for making the changes.

Check the result of the newly created partition with lsblk command

Now, make the partition swap space partition with mkswap command.

sudo mkswap /dev/sda3

It will show you the new UUID for swap partition and size.

image 3

In the final step, copy the swap uuid, and update the fstab as the screenshot

image 4

Once added, reload the daemon

sudo systemctl daemon-reload

run the df -h command to verify the new space.

How to Increase Size of Disk Partition in Ubuntu

5. Resizing the Partition through parted:

To increase disk space, you can use tools like parted or gparted for graphical interfaces. In this example, we’ll use parted:

sudo parted /dev/sdX

Replace /dev/sdX with the appropriate device identifier.

  • Check the current partition layout using print.
  • Resize the partition using the resizepart command.
resizepart PARTITION_NUMBER END
  • Exit parted and apply the changes.

Resizing the File System:

After resizing the partition, you need to resize the file system. For the ext4 file system, you can use the resize2fs command:

sudo resize2fs /dev/sdXN

6. Verifying the Changes:

Use the df command again to verify the increased disk space. Ensure that the changes have been applied successfully.

df -h

Remove any temporary files or backups created during the process. It’s crucial to keep your system clean and organized.

For Common Linux Commands, read below:

Top Linux Commands for Seamless Operations

Conclusion:

Increasing disk space on a Linux server is a manageable task with careful planning and execution. By following this step-by-step guide, you can ensure a smooth expansion of your server’s storage capacity, preventing potential issues associated with low disk space. Regularly monitor your disk space usage to stay proactive in managing server resources efficiently.

Ravi Chopra
Scroll to Top