fbpx Increase Disk Space Linux: growpart, resize2fs, xfs_growfs | Certificação Linux

How to Increase Disk Space in Linux

📅 11/23/2023 ⏱ 2 min ✍️ Uira Ribeiro
how-to
How to Increase Disk Space in Linux
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

Expanding Partitions on Linux: A Practical Guide with growpart, lsblk, resize2fs and xfs_growfs


Introduction:

Expanding a partition on a Linux system may seem like a daunting task, but with the right tools and a clear understanding of the process, it is a manageable task. In this article, we will guide you through the steps to increase the size of a Linux partition using the growpart, lsblk, resize2fs and xfs_growfs commands.

This is especially useful in virtual machine environments, where it is easy to change the size of disks.


1. Checking the Current Partition State with lsblk:

Before starting to expand a partition, it is crucial to understand the current layout of your disk. The lsblk command is a powerful tool to list all partitions and block devices, along with their mount points and sizes.

Command:

lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda       259:2    0  16G  0 disk 
├─sda 1   259:3    0  16G  0 part /
└─sda 2   259:4    0   1M  0 part 

This command will display a list of the partitions, helping to identify which one you want to expand.


2. Expanding the Partition with growpart:

The growpart is a tool that facilitates increasing the size of a partition within a disk. To use it, you need to specify the device and the partition number.

Example:

sudo growpart /dev/sda 1

This command will increase the first partition on the /dev/sda device.


3. Resizing the Filesystem:

After expanding the partition, the next step is to resize the filesystem to use the new available space.

  • For ext4 filesystems: Use resize2fs, which will automatically adjust the filesystem to the new partition size. Command:
  sudo resize2fs /dev/sda1

This command resizes the filesystem on the first partition of /dev/sda.

  • For XFS filesystems: Use xfs_growfs, which also adjusts the filesystem to the new partition size. Command:
  sudo xfs_growfs /mountpoint

Replace /mountpoint with the mount point of the XFS partition.


Conclusion:

Expanding a partition on Linux does not need to be a complex task. With the growpart, lsblk, resize2fs and xfs_growfs commands, you can easily increase the space of your partitions, ensuring that your system has the necessary space to operate efficiently. Always remember to back up your data before performing such operations to avoid unexpected data loss.

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp