fdisk Command in Linux: Create Disk Partitions

The first thing you need to do after installing a new SSD or hard disk is to partition it. A drive needs to have at least one partition before you can format it and store files on it.
In Linux, there are several tools that you can use to create partitions, with fdisk being the most commonly used one.
To create a partition in Linux with fdisk, open the target disk with sudo fdisk /dev/sdX, create a partition table if needed, add a new partition with n, review the layout with p, and write the changes with w.
This guide covers the fdisk command in Linux. If you prefer a more visual interface or need advanced features, consider tools such as cfdisk, parted, or gdisk.
fdisk is a menu-driven command-line utility that allows you to create and manipulate partition tables on a storage device.
Be aware that fdisk is a dangerous tool and should be used with extreme caution. Only root or users with sudo
privileges can manipulate the partition tables.
Syntax
The general syntax for the fdisk command is:
fdisk [OPTIONS] DEVICEFor example, to open /dev/sdb:
sudo fdisk /dev/sdbList Partitions
To list the partition table of a device, invoke the fdisk command with the -l option, followed by the device name. For example, to list the /dev/sda partition table and partitions, you would run:
sudo fdisk -l /dev/sdaWhen no device is given as an argument, fdisk will print partition tables of all devices listed in the /proc/partitions file:
sudo fdisk -lDisk /dev/nvme0n1: 232.91 GiB, 250059350016 bytes, 488397168 sectors
Disk model: Samsung SSD 960 EVO 250GB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 6907D1B3-B3AB-7E43-AD20-0707A656A1B5
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System
/dev/nvme0n1p2 1050624 34605055 33554432 16G Linux swap
/dev/nvme0n1p3 34605056 488397134 453792079 216.4G Linux filesystem
Disk /dev/sda: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: WDC WD5000AAKS-0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0001cca3
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 976771071 976769024 465.8G 83 LinuxThe output above shows the current partition tables of all devices that are attached to your system. Generally, SATA device names follow the pattern /dev/sd[a-z], while NVMe device names follow /dev/nvme0n1 and their partitions are named /dev/nvme0n1p1, /dev/nvme0n1p2, and so on.
Create a Partition Table and Partitions
Before opening fdisk, identify the disk you want to partition. The safest way to start is to list only whole disks:
lsblk -d -o NAME,SIZE,MODELNAME SIZE MODEL
sda 465.8G WDC WD5000AAKS-0
sdb 298.9G External USB 3.0
nvme0n1 232.9G Samsung SSD 960 EVO 250GBIn this example, /dev/sdb is the external disk we want to partition. Use the whole disk path, such as /dev/sdb, not an existing partition path such as /dev/sdb1.
To start partitioning the drive, run fdisk with the device name. In this example we will work on /dev/sdb:
sudo fdisk /dev/sdbThe command prompt will change, and the fdisk dialogue where you can type in commands will open:
Welcome to fdisk (util-linux 2.41.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):w command. You can exit the fdisk dialogue without saving the changes using the q command.To get a list of all available commands enter m:
Command (m for help): m
If you are partitioning a new drive, create the partition table before creating partitions. Skip this step if the device already has a partition table and you want to keep it.
fdisk supports several partitioning schemes. MBR and GPT are the two most popular partition table standards, and they store partition information on a drive in different ways. GPT is the better choice for most modern systems. The main points to consider when choosing what partitioning standard to use are:
- Use MBR to boot the disk in legacy BIOS mode.
- Use GPT to boot the disk in UEFI mode.
- The MBR standard supports creating a disk partition up to 2 TiB. If you have a disk of 2 TiB or larger, use GPT.
- MBR has a limit of 4 primary partitions. If you need more partitions, one of the primary partitions can be set as an extended partition and hold additional logical partitions. With GPT, you can have up to 128 partitions. GPT does not support extended or logical partitions.
In this example, we will use a GPT partition table.
Enter g to create a new empty GPT partition table:
Command (m for help): gCreated a new GPT disklabel (GUID: 4649EE36-3013-214E-961C-51A9187A7503).The next step is to create the new partitions.
We will create two partitions. The first one with a size of 100 GiB and the second one will take the rest of the disk space.
Run the n command to create a new partition:
Command (m for help): nYou will be prompted to enter the partition number. Hit “Enter” to use the default value (1):
Partition number (1-128, default 1):Next, the command will ask you to specify the first sector. In most cases, use the default value so fdisk can align the partition correctly. Hit “Enter” to use the default value (2048):
First sector (2048-500118158, default 2048):On the next prompt, you will need to enter the last sector. You can use an absolute value for the last sector or a relative value to the start sector, using the + symbol followed by the partition size. The size can be specified in kibibytes (K), mebibytes (M), gibibytes (G), tebibytes (T), or pebibytes (P).
Enter +100G to set the partition size to 100 GiB:
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-500118158, default 500118158): +100GCreated a new partition 1 of type 'Linux filesystem' and of size 100 GiB.By default, the type of the new partition is set to “Linux filesystem”, which is fine for most Linux data partitions.
Change Partition Types
Some partitions need a different type. For example, an EFI System partition, swap partition, LVM physical volume, or RAID member should use the matching partition type so tools and installers can recognize it correctly.
To list the available fdisk partition types, enter l:
Command (m for help): lFor GPT disks, common partition types include Linux filesystem, Linux swap, EFI System, Linux LVM, and Linux RAID. For MBR disks, fdisk shows numeric IDs such as 83 Linux, 82 Linux swap / Solaris, and 8e Linux LVM.
For a regular data partition, skip this step and leave the type as Linux filesystem. If you are creating a swap partition instead, enter t, choose the partition number, and then enter the type name, alias, or code shown by l:
Command (m for help): t
Partition number (1,2, default 2): 1
Partition type or alias (type L to list all): swap
Changed type of partition 'Linux filesystem' to 'Linux swap'.Let us create the second partition that will take the rest of the disk space:
Command (m for help): nUse the default values for the partition number, first and last sectors. This will create a partition that will use all available space on the disk.
Partition number (2-128, default 2):
First sector (209717248-625142414, default 209717248):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (209717248-625142414, default 625142414):Once done creating partitions, use the p command to display the new partition table:
Command (m for help): pDisk /dev/sdb: 298.9 GiB, 320072933376 bytes, 625142448 sectors
Disk model: nal USB 3.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F8365250-AF58-F74E-B592-D56E3A5DEED1
Device Start End Sectors Size Type
/dev/sdb1 2048 209717247 209715200 100G Linux filesystem
/dev/sdb2 209717248 625142414 415425167 198.1G Linux filesystemSave the changes by running the w command:
Command (m for help): wThe command will write the table to the disk and exit the fdisk menu.
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.The kernel will read the device partition table without the need to reboot the system.
Deleting a Partition
To delete a partition, use the d command, select the partition number, and then write the changes with w. Deleting a partition removes its entry from the partition table and makes the data inaccessible, so make sure you have a backup.
Activating the Partitions
Now that the partitions have been created, the next step is to format the partitions and mount them to the system’s directory tree.
We will format both partitions to ext4. Formatting erases data on the target partition, so double-check the device names before running these commands:
sudo mkfs.ext4 -F /dev/sdb1
sudo mkfs.ext4 -F /dev/sdb2Creating filesystem with 51928145 4k blocks and 12984320 inodes
Filesystem UUID: 63a3457e-c3a1-43f4-a0e6-01a7dbe7dfed
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done In this example, we will mount the partitions to /mnt/audio and /mnt/video directories.
Create the mount points with mkdir
:
sudo mkdir -p /mnt/audio /mnt/videoMount the new partitions:
sudo mount /dev/sdb1 /mnt/audio
sudo mount /dev/sdb2 /mnt/videoPartitions will stay mounted until you unmount them or shutdown
the machine. To automatically mount a partition when your Linux system starts up, define the mount in the /etc/fstab file.
You can now use the new partitions to store files.
Resizing Partitions
fdisk cannot resize partitions. To resize a partition, use tools such as parted or gparted and then resize the filesystem with the appropriate filesystem tool (for example, resize2fs for ext4).
Quick Reference
For a printable quick reference, see the fdisk cheatsheet .
| Command | Description |
|---|---|
sudo fdisk -l | List partition tables for all detected disks |
sudo fdisk -l /dev/sdX | List the partition table for one disk |
sudo fdisk /dev/sdX | Open a disk in interactive fdisk mode |
m | Show help and available interactive commands |
p | Print the current in-memory partition table |
n | Create a new partition |
d | Delete a partition |
l | List available partition types |
t | Change a partition type |
g | Create a new GPT partition table |
o | Create a new MBR (DOS) partition table |
w | Write changes to disk and exit |
q | Quit without saving changes |
Troubleshooting
fdisk says the device is busy
Unmount any mounted partitions on the disk and try again. You can check mounts with lsblk and unmount with umount /dev/sdXN.
Changes do not appear after writing the table
The kernel may not have re-read the partition table. Run sudo partprobe /dev/sdX or reboot the system.
Permission denied
Make sure you are running fdisk with sudo or as root.
FAQ
What is the difference between MBR and GPT?
MBR is the legacy partitioning scheme with a 2 TiB disk size limit and up to four primary partitions. GPT is the modern standard that supports larger disks and many more partitions, and it is required for UEFI boot.
How do I convert MBR to GPT?
Back up the disk, then recreate the partition table as GPT and restore the data. For in-place conversion in some cases, use tools such as gdisk or sgdisk, but always verify compatibility and keep a backup.
Can I partition a disk without losing data?
It depends on the existing layout and free space. Partitioning can be destructive, so use reliable backups and test on non-critical disks before making changes.
What is the difference between fdisk and parted?fdisk is a simple, menu-driven tool that works well for common partitioning tasks. parted supports more advanced operations such as resizing and alignment checks.
Conclusion
fdisk covers most everyday partition work: listing disks, switching between MBR and GPT, adding or removing partitions, and changing types. Reach for parted or gparted when you need resizing or alignment work. For full option detail, run man fdisk.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page