In this article, you'll learn how to resize a partition and filesystem on GNU/Linux using the CLI tools parted
and resize2fs
Note that we'll only be covering EXPANSION / GROWING, and not shrinking, since it's much more difficult to shrink a partition than to grow it.
What you'll need:
parted
(available in most package managers)We have virtual servers starting from just US$0.99/mo, and dedicated servers starting from as low as US$50/mo
Unlike other hosts, we don't ask for any personal details - only a name (can be an alias / username), and an e-mail address so we can send you your server details and renewal invoices.
We also accept several different cryptocurrencies with our own in-house payment processor - no third parties involved in processing your payments.
At the time of writing, we currently accept: Bitcoin (BTC), Litecoin (LTC), Monero (XMR), Dogecoin (DOGE), HIVE, and HBD
parted
For Debian-based distros such as Ubuntu, Debian, Linux Mint, etc. - you can install parted
from apt:
sudo apt update
sudo apt install -y parted
For Redhat-based distros (Fedora, Redhat, CentOS, Oracle, Amazon Linux, etc.), you can use either dnf
(for modern distros) or yum
(for older distros):
# for modern distros
sudo dnf install -y parted
# for older distros, or if you get an error saying dnf isn't installed
sudo yum install -y parted
For Arch Linux, you can use pacman
:
sudo pacman -Sy parted
Run the following command to get information about all disks and partitions on your system:
sudo fdisk -l
Look through the output to find the disk (e.g. /dev/sda
) that you want to resize, as well as the partition you want to resize.
You might also be able to find the disk /dev/ path by running df -h /
(if you want to resize a different partition instead of the rootfs /
- then replace /
with the mountpoint of the partition you want to resize)
parted
Once you've located the disk you want to resize a partition on (e.g. /dev/sda
), open it using parted:
sudo parted /dev/sda
Now use the print
command within parted, which will print information about that disk, and the partitions on the disk, so you can figure out how much space you have available to expand the partition into, and the partition number of the partition you want to resize:
print
Finally, use resizepart [partition_number]
with the number of the partition you want to resize, to actually resize the partition:
resizepart 1
You may be warned that the disk is in use, this is generally okay, so enter yes
When asked to enter the End:
- if the partition is at the end of the disk, you can enter the size of the disk outputted by print
, but take off 0.2GB for safety, e.g. if it was 48.5GB - you'd enter 48.3G.
If the partition is between two partitions, then you'll want to enter an end location at least 100mb before the "Start" of the following partition. For example, if you're resizing partition 1 (start: 1020MB, end: 20GB), and partition 2 starts at 41.2GB - then you could set the End
of part 1 to 41GB
(~200mb before part 2).
The command you'd run to grow a filesystem, depends on what filesystem the partition is actually formatted with.
Most Linux systems use the filesystem ext4
(or an older version such as ext3
- which uses the same command to resize anyway), though either yourself or the installer for your distro may have formatted some/all of the partitions with an alternative filesystem such as XFS, or Btrfs.
To discover the filesystem used by each partition on your system, use the following command:
lsblk -f
To grow an ext2
, ext3
or ext4
filesystem, use the command (where /dev/sda1
is the partition device to resize):
sudo resize2fs /dev/sda1
To grow an xfs
filesystem, use the command (where /
is the MOUNTPOINT of the XFS formatted device):
sudo xfs_growfs /
To grow a btrfs
filesystem, use the command (where /
is the MOUNTPOINT of the Btrfs formatted device):
sudo btrfs filesystem resize max /
Finally, check the filesystem was resized by running df -h
to list the size, used space, and avail space on all mounts:
df -h
We have virtual servers starting from just US$0.99/mo, and dedicated servers starting from as low as US$50/mo
Unlike other hosts, we don't ask for any personal details - only a name (can be an alias / username), and an e-mail address so we can send you your server details and renewal invoices.
We also accept several different cryptocurrencies with our own in-house payment processor - no third parties involved in processing your payments.
At the time of writing, we currently accept: Bitcoin (BTC), Litecoin (LTC), Monero (XMR), Dogecoin (DOGE), HIVE, and HBD