How To Resize and Move Partitions in Linux
How To Resize and Move Partitions in Linux
(/linux/) (https://www.baeldung.com/linux/)
Administration
(https://www.baeldung.com/linux/category/administration)
Filesystems
(https://www.baeldung.com/linux/category/filesystems)
https://www.baeldung.com/linux/resize-partitions 1/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
1. Overview
In this tutorial, we’ll consider some of the actively maintained open-
source partitioning tools
(https://en.wikipedia.org/wiki/List_of_disk_partitioning_software)
currently available on Linux. We’ll compare them using the same initial
and target partitioning (/linux/rsync-clone-file-system-hierarchy#disk-
partitions-and-partitioning-tools).
2. Precautions
Although not always strictly necessary, let’s proceed to resize partitions
from a live distribution
(https://en.wikipedia.org/wiki/Linux_distribution#Installation-
free_distributions_(live_CD/USB)), ensuring that all partitions are
unmounted (/linux/mount-unmount-filesystems#umount), and that
swap (/linux/swap-space) is disabled. Before starting the live system,
let’s shut down the machine without suspending or hibernating.
For extra safety, let’s check the integrity of all file systems with fsck
(/linux/recover-lost-deleted-data#filesystem-analysis-and-
recovery) and make sure that we have a full backup.
If we have a server, not all VPS providers allow us to start a live
distribution and use its GUI via VNC
(https://en.wikipedia.org/wiki/Virtual_Network_Computing). Choosing a
provider with these capabilities will significantly help us when we need
to resize partitions or perform backups for disaster recovery
(/linux/system-image-create-restore). In this regard, Clonezilla
(/linux/system-image-create-restore#clonezilla) is convenient in a
server environment because it can use remote target folders for our
backups via ssh (/linux/secure-shell-ssh#accessing-host).
Optionally, we can also look at the disks’ health (/linux/storage-device-
check-health).
https://www.baeldung.com/linux/resize-partitions 2/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
(/wp-content/uploads/sites/2/2022/07/LinuxMint-Partitioning-During-
Installation.png)Our goal is to enlarge /dev/sda5 by about 3.7 GiB
(https://en.wikipedia.org/wiki/Gigabyte#Base_2_.28binary.29) (4.0 GB
(https://en.wikipedia.org/wiki/Gigabyte#Base_10_.28decimal.29)) and,
as a side effect, to move /dev/sda6 and /dev/sda7 to the right. We
maintain a certain tolerance in partition sizes, which means that slight
variations of a few hundred MB don’t matter:
(/wp-content/uploads/sites/2/2022/07/Target-Partitions.png)The
partitions’ UUIDs must remain the same for our Linux installation to
continue booting. Or, as a workaround in case of UUID changes, we can
manually update /etc/fstab (/linux/mount-unmount-filesystems#6-
the-etcfstab-file). If in doubt, we can see the list of all UUIDs with blkid
(https://linux.die.net/man/8/blkid).
Before trying the following partition tools, these are the preparatory
commands to be executed from a live distribution in our test machine to
disable swap and check file systems integrity:
https://www.baeldung.com/linux/resize-partitions 3/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
4. GUI Tools
We strongly suggest the following GUI tools because they help us
avoid mistakes. In addition, they hide the complexity of resizing and
moving partitions.
4.1. GParted
GParted (https://gparted.org/) is one of the most popular and well-
known tools for resizing and moving partitions. It offers an intuitive and
convenient GUI. The important thing is the correct order of operations:
first, we need to enlarge the extended partition
then we move /dev/sda7 and /dev/sda6 to the right
finally we enlarge /dev/sda5
When we apply the requested changes, GParted performs them in a
fully automated manner:
https://www.baeldung.com/linux/resize-partitions 4/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
(/wp-content/uploads/sites/2/2022/07/GParted-File-System-
Support.png)GParted can also show device and partitions information. It
allows us to check the integrity of a file system and format it. Moreover,
the menu that appears by right-clicking on a partition provides an option
to change the UUID.
https://www.baeldung.com/linux/resize-partitions 5/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
(/wp-content/uploads/sites/2/2022/07/KDE-Partition-Manager-File-
System-Support.png)Finally, it has a shredding feature to overwrite a
partition with random data or zeros. In this regard, we suggest looking at
various solutions to remove confidential data (/linux/wipe-free-space)
from a disk’s free space.
https://www.baeldung.com/linux/resize-partitions 6/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
5. Command-Line Tools
GParted and KDE Partition Manager use libparted
(https://en.wikipedia.org/wiki/GNU_Parted) for some tasks but
implement much other stuff themselves. Moreover, they use other
command-line tools under the hood, listed in their previously seen “File
System Support” tables. That’s why there isn’t an easy-to-use and
comprehensive command-line equivalent of GParted or KDE Partition
Manager.
Several well-known tools, such as parted
(https://www.gnu.org/software/parted/), fdisk (/linux/extend-logical-
extended-partitions-fdisk), cfdisk (https://linux.die.net/man/8/cfdisk),
and sfdisk (/linux/find-all-storage-devices#sfdisk), aren’t intuitive or
straightforward. Moreover, these essential command-line tools often
need to be used together with other dangerous utilities like dd
(/linux/dd-command) or resize2fs
(https://linux.die.net/man/8/resize2fs).
So, resizing and moving partitions from the command line is difficult
and error-prone. Let’s be cautious and do it only if it’s strictly
necessary.
Let’s remember to disable swap with swapoff -a. Then, let’s see below
how to do step-by-step the same tasks done with the graphical tools.
We’ll show how to perform them without explaining each command’s
option, for which we refer to the manual pages. Also, since the output
is particularly verbose, we’ll report only the essential information.
https://www.baeldung.com/linux/resize-partitions 7/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
# blkid /dev/sda*
/dev/sda: PTUUID="015d4fac" PTTYPE="dos"
/dev/sda1: UUID="8d24bfcf-e4e5-44a9-8d5b-5ffb69f94900"
TYPE="ext4" PARTUUID="015d4fac-01"
/dev/sda2: PTTYPE="dos" PARTUUID="015d4fac-02"
/dev/sda5: UUID="dae073ff-1825-4a92-94f0-2b00bbf3b101"
TYPE="ext4" PARTUUID="015d4fac-05"
/dev/sda6: UUID="37b42f4f-6aac-43a0-955d-3929a86388ec"
TYPE="ext4" PARTUUID="015d4fac-06"
/dev/sda7: UUID="463c1ec2-b3bf-4d7f-b173-12def5a0d8d3"
TYPE="swap" PARTUUID="015d4fac-07"
https://www.baeldung.com/linux/resize-partitions 8/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
# fdisk /dev/sda
[...]
Command (m for help): d
Partition number (1,2,5-7, default 7): 7
The last command is for a partition integrity check. It’s a good practice to
do this check after every change in the partition table.
# growpart /dev/sda 2
CHANGED: partition=2 start=1001470 old: size=31764482
end=32765952 new: size=40291809 end=41293279
# sfdisk -V /dev/sda
https://www.baeldung.com/linux/resize-partitions 9/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
# e2fsck -f -y -v /dev/sda6
[...]
231 files
# echo '+4G,' | sfdisk --move-data /dev/sda -N 6
# e2fsck -f -y -v /dev/sda6
[...]
231 files
# sfdisk -Vl /dev/sda
[...]
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 41293278 40291809 19.2G 5 Extended
/dev/sda5 1001472 21000191 19998720 9.5G 83 Linux
/dev/sda6 29390848 39153663 9762816 4.7G 83 Linux
Compared to the beginning, we can see that sda2 is larger, while sda6
has the same size but a different starting point.
https://www.baeldung.com/linux/resize-partitions 10/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
# e2fsck -f -y -v /dev/sda5
[...]
290850 files
# echo ',+4G' | sfdisk /dev/sda -N 5
[...]
New situation:
[...]
/dev/sda5 1001472 29388799 28387328 13.5G 83 Linux
[...]
# e2fsck -f -y -v /dev/sda5
[...]
290850 files
# resize2fs /dev/sda5
[...]
Resizing the filesystem on /dev/sda5 to 3548416 (4k) blocks.
[...]
# e2fsck -f -y -v /dev/sda5
[...]
290850 files
# sfdisk -Vl /dev/sda
[...]
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 41293278 40291809 19.2G 5 Extended
/dev/sda5 1001472 29388799 28387328 13.5G 83 Linux
/dev/sda6 29390848 39153663 9762816 4.7G 83 Linux
Remaining 2143742 unallocated 512-byte sectors.
https://www.baeldung.com/linux/resize-partitions 11/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
# fdisk /dev/sda
[...]
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 7
First sector (39155712-41293278, default 39155712):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (39155712-
41293278, default 41293278):
https://www.baeldung.com/linux/resize-partitions 12/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
# blkid /dev/sda*
/dev/sda: PTUUID="015d4fac" PTTYPE="dos"
/dev/sda1: UUID="8d24bfcf-e4e5-44a9-8d5b-5ffb69f94900"
TYPE="ext4" PARTUUID="015d4fac-01"
/dev/sda2: PTTYPE="dos" PARTUUID="015d4fac-02"
/dev/sda5: UUID="dae073ff-1825-4a92-94f0-2b00bbf3b101"
TYPE="ext4" PARTUUID="015d4fac-05"
/dev/sda6: UUID="37b42f4f-6aac-43a0-955d-3929a86388ec"
TYPE="ext4" PARTUUID="015d4fac-06"
/dev/sda7: UUID="463c1ec2-b3bf-4d7f-b173-12def5a0d8d3"
TYPE="swap" PARTUUID="015d4fac-07"
Finally, we reboot the system to verify that all the partitions and the
swap are working correctly.
6. Conclusion
In this article, we saw that the easiest way to resize and move partitions
is to use GParted or KDE Partition Manager from a live distribution.
However, GUI is not always available. We then explored how to perform
the same operations using only command-line tools.
In any case, the probability of making a small mistake that can make
our disk unusable is very high when we use the terminal. For this
reason, it’s always essential to have a complete backup to make possible
disaster recovery. For instance, just moving a comma in the sfdisk‘s
parameters is enough to get two completely different results.
https://www.baeldung.com/linux/resize-partitions 13/14
6/9/23, 7:20 How to Resize and Move Partitions in Linux | Baeldung on Linux
CATEGORIES
ADMINISTRATION (/LINUX/CATEGORY/ADMINISTRATION)
FILES (/LINUX/CATEGORY/FILES)
FILESYSTEMS (/LINUX/CATEGORY/FILESYSTEMS)
INSTALLATION (/LINUX/CATEGORY/INSTALLATION)
NETWORKING (/LINUX/CATEGORY/NETWORKING)
PROCESSES (/LINUX/CATEGORY/PROCESSES)
SCRIPTING (/LINUX/CATEGORY/SCRIPTING)
SEARCH (/LINUX/CATEGORY/SEARCH)
SECURITY (/LINUX/CATEGORY/SECURITY)
WEB (/LINUX/CATEGORY/WEB)
SERIES
LINUX ADMINISTRATION (/LINUX/LINUX-ADMINISTRATION-SERIES)
LINUX FILES (/LINUX/LINUX-FILES-SERIES)
LINUX PROCESSES (/LINUX/LINUX-PROCESSES-GUIDE)
ABOUT
ABOUT BAELDUNG (/ABOUT)
THE FULL ARCHIVE (HTTPS://WWW.BAELDUNG.COM/LINUX/FULL_ARCHIVE)
EDITORS (HTTPS://WWW.BAELDUNG.COM/EDITORS)
The
Baeldu
Logo
https://www.baeldung.com/linux/resize-partitions 14/14