Skip to content

[Linux] Using `gparted` Or `parted` To Resize Disk Partition

Last Updated on 2024-08-09 by Clay

Recently, due to work requirements and the fact that some Steam games run more smoothly on Windows, I seriously considered reallocating 200GB of disk space for Windows on my Linux laptop. However, since I initially allocated the entire 1TB SSD to Linux, I now have to resize the partitions.

My SSD is an NVMe (Non-Volatile Memory Express) solid-state drive, which, like traditional SATA SSDs or HDDs, supports partition resizing. In Linux, we can use tools like gparted or parted to reallocate space.

However, it’s crucial to remember that, even though the process itself is safe, you should still back up your important data! Accidents can happen at any step. Additionally, if you plan to shrink a partition, the remaining space must be large enough to hold all existing data, or you might encounter problems.

This article is a step-by-step guide on how I reallocated space using the gparted and parted tools. gparted can be considered the graphical interface version of parted, encapsulating parted's functionality for disk management.

Before reallocating, don't forget to unmount the disk with umount. The disk should not be mounted during the process.


Reallocating Disk Space Using gparted

First, we can install the gparted tool.

sudo apt update
sudo apt install gparted


Next, we launch the gparted tool:

sudo gparted


Output:

Select the disk you want to reallocate. You’ll see the total size, used space, and remaining space.

Next, right-click on the disk you want to reallocate and select Resize/Move. Below, I’ll use /dev/sda as an example.


If you want to adjust the size of the current partition, enter the desired target size in the New size (MiB) field, and the Free space following (MiB) will automatically update with the remaining space.

Once you’ve made your selections, click Resize/Move at the bottom right to finalize the configuration.


Finally, check to see if the line "Shrink /dev/sda1 from 931.51 GiB to 400.00 GiB" appears. This describes the operation we’re about to perform. Next, click the green checkmark button above to execute the operation.

In my testing, exFAT does not support such resizing, but formats like ext4 work without issues.


Reallocating Disk Space Using parted

Of course, if we’re working on a server without a graphical interface, we can only manage partitions using command-line tools. Start by using the following command to select the disk you want to reallocate (assuming it’s /dev/sda; remember, it’s the disk, not the partition):

sudo parted /dev/sda


Output:

GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)


You can start by using the print command to check the status of the disk’s partitions. This will display all current partitions on the disk, including their numbers, sizes, types, and other details.

(parted) print


Output:

Model: Seagate One Touch w/PW (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 1000GB 1000GB ext4


Next, let’s proceed to shrink a partition! In this example, my partition is Number 1, which corresponds to /dev/sda1. We can use the resizepart command in the format resizepart <partition number> <end position>:

(parted) resizepart 1 400GB
Warning: Shrinking a partition can cause data loss, are you sure you want to continue?
Yes/No? yes
(parted) print


Output:

Model: Seagate One Touch w/PW (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 400GB 400GB ext4


By the way, if you want to immediately create a new partition from the unallocated free space, you can use the following command:

(parted) mkpart primary ext4 <START> <END>
  • primary is the partition type (can be primary or logical)
  • ext4 is the file system type (can be ext4, ntfs, exfat, etc.)
  • <START> is the start position of the new partition (e.g., 400GB)
  • <END> is the end position of the new partition (e.g., 900GB)

Once you’ve confirmed that everything is correct, you can exit the program, and all changes will be saved.

(parted) quit


Output:

Information: You may need to update /etc/fstab.

References


Read More

Tags:

Leave a Reply