Just to add another way (using fdisk
command) to create a partition out of unallocated space. fdisk
is available across several Linux distros, at least Centos, Ubuntu and Debian have this command.
IMPORTANT NOTE: before executing the following commands, make sure you identify the disk you want to work with, in my case it is /dev/sda
but yours could be different. Using the wrong disk can break your disk and data.
First, check where there is the unallocated space on your disk.
sudo parted /dev/sda unit s print free
The output is shown in the picture below, where we can see that there is a 2GB (aprox.) unallocated space. The unallocated space corresponds to the line which has "Free Space" under the file system column.

Then, run fdisk in interactive mode.
sudo fdisk /dev/sda
Afterfdisk
is running, go through the following steps:
- Type
n
for creating a new partition.
- Type
p
for a primary partition (this is my case, yours can be a different one).
- Type the value of the first sector of your partition (you can get this value from the "Start" column of the
sudo parted /dev/sda unit s print free
command, i.e. from the previous picture). In my case this would be the value 308582400
(the trailing s
is not needed)
- Type the value of the final sector of your partition (analogous to the previous step, you can get this value from the "End" column of the
sudo parted /dev/sda unit s print free
command, i.e. from the previous picture). In my case this would be the value 312581807
(again, the trailing s
is not needed)
- Type
w
to write the changes to disk
After this, you will have to reboot your system or run the sudo partprobe
command to make the partition changes available for the kernel.
You can end at this point and you will have your partition created. In the case that you want to tag your partition because it will have a specific use, e.g. a swap partition, you can follow the steps below before typing the w
letter into fdisk
command (i.e. before writing changes to disk, i.e. this means that the steps below substitute to the previous step "Type w
to write...").
- Type
t
for tagging the newly created partition
- Type the number of the partition to be tagged, the one that we just created, in my case it would be
3
(fdisk
command will inform you the number assigned to the newly created partition)
- Type the partition type (
82
in my case for a swap partition, but you can type L
to list all the types and select the type that suits you)
- Type
w
to write the changes to disk
Below is a screenshot that shows all the previous steps executed and the output.
The final result, after creating the new partition is shown below. You can see yours by executing the following command
sudo fdisk -l /dev/sda

parted
command for creating a partition (orfdisk
for that matter)?