Updated: 18 October 2026 · Applies to: fdisk from util-linux 2.41.5 on Debian 13 (Linux 6.12 kernel) and util-linux 2.40.2 on AlmaLinux 10.2 (the same commands work on Ubuntu 24.04 and 26.04 and Rocky Linux)
To create a partition with fdisk, run fdisk /dev/sdb as root, type g for a new GPT partition table (only on an empty disk), n for a new partition, press Enter for the number and first sector, type a size such as +20G (or press Enter to use the rest of the disk), and finish with w to write the table. Then format the partition with mkfs.ext4 /dev/sdb1 and mount it. fdisk keeps every change in memory until you type w, and q quits without saving.
Check the disk name with lsblk first: partitioning the wrong disk makes its data unreachable. The examples use /dev/sdb; in our lab the disk was a 2 GiB test disk on a real Linux kernel, renamed in the output.
Partition commands in Linux
lsblkandfdisk -llist disks and partitions (see how to list all disks and partitions).fdisk: interactive menu for MBR (DOS) and GPT tables, the subject of this article.sfdisk: the script version of fdisk;cfdisk: a full-screen menu.parted: single commands, also for resizing: see how to create disk partitions with parted and fdisk and the Linux parted command guide.gdisk: GPT only.mkfs.ext4andmkfs.xfsformat a partition.
1. List partitions
fdisk -l # all disks fdisk -l /dev/sdb # one disk fdisk -x /dev/sdb # more detail (partition UUIDs, type UUIDs)
A disk without a partition table shows only the size lines; one with a table adds Disklabel type: gpt (or dos) and one line per partition.
2. Create a partition with fdisk (GPT)
- Open the disk:
fdisk /dev/sdb. On an empty disk fdisk saysCreated a new DOS (MBR) disklabel: that table is only in memory. - Type
gto replace it with a GPT table. Use GPT on new disks; an MBR table is limited to 2 TiB and four primary partitions. Skip this step if the disk already has partitions you want to keep. - Type
n. Accept the partition number and the first sector with Enter (2048 here: fdisk aligns its default values to the disk). - For the last sector, type a size:
+1G,+500M, or Enter for all remaining space. - Type
pto check, thenwto write.
Our session, creating a 1 GiB partition and a second one with the rest of the disk (the p output is shortened):
# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.41.5).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0xcb0e575f.
Command (m for help): g
Created a new GPT disklabel (GUID: D424C5FD-B24C-40C9-ADEF-962C174AD7DC).
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-4194270, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-4194270, default 4192255): +1G
Created a new partition 1 of type 'Linux filesystem' and of size 1 GiB.
Command (m for help): n
Partition number (2-128, default 2):
First sector (2099200-4194270, default 2099200):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-4194270, default 4192255):
Created a new partition 2 of type 'Linux filesystem' and of size 1022 MiB.
Command (m for help): p
...
Device Start End Sectors Size Type
/dev/sdb1 2048 2099199 2097152 1G Linux filesystem
/dev/sdb2 2099200 4192255 2093056 1022M Linux filesystem
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
The kernel picked up the new table at once, and lsblk showed sdb1 and sdb2. If fdisk reports Device or resource busy instead, the disk is in use: see how to delete a partition with parted or fdisk, which covers that message and partprobe.
3. Format and mount the new partition
- Create a file system:
mkfs.ext4 -L data /dev/sdb1(ormkfs.xfs /dev/sdb1for XFS). For a swap partition usemkswap /dev/sdb2. - Mount it:
# mkdir -p /mnt/data # mount /dev/sdb1 /mnt/data # df -h /mnt/data Filesystem Size Used Avail Use% Mounted on /dev/sdb1 974M 280K 906M 1% /mnt/data
- To mount it at every boot, get the UUID with
blkid /dev/sdb1and add a line to/etc/fstab:UUID=your-uuid /mnt/data ext4 defaults 0 2
- Test the file before rebooting:
findmnt --verifyprintedSuccess, no errors or warnings detectedandmount -amounted the partition. With a wrong UUID,mount -asaidcan't find UUID=..., so fix that before you reboot.
More on file systems in how to create a new ext4 file system.
4. MBR partitions: primary, extended and logical
After o (new MBR table), n asks for the partition type. Up to four primary partitions fit; for more, make the fourth (or any) one extended and create logical partitions (5, 6 and so on) inside it. Lab session, shortened:
Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): e ... Command (m for help): n All space for primary partitions is in use. Adding logical partition 5 ... Command (m for help): a Partition number (1,2,5,6, default 6): 1 The bootable flag on partition 1 is enabled now.
On a disk over 2 TiB, fdisk warns: DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT). See also how to add a disk larger than 2TB.
5. Other fdisk commands
Type m inside fdisk for the full menu. The ones you need most:
pprint the table,Flist free space,idetails of one partition,vverify the table.tchange the type. fdisk 2.41 also accepts aliases, for exampleswapandlvm:Command (m for help): t Partition number (1,2, default 2): 2 Partition type or alias (type L to list all): lvm Changed type of partition 'Linux filesystem' to 'Linux LVM'.
ddelete a partition (details in the delete article linked above),eresize a partition.atoggle the bootable flag (MBR only),gnew GPT table,onew MBR table.OandIsave and load the layout as an sfdisk script file.xexpert menu,wwrite and exit,qquit without saving.
6. Fix "Partition table entries are not in disk order"
On MBR disks, deleting a logical partition and creating a new one can leave the numbers out of order. In our test, after deleting partition 5 the new partition became number 6, and fdisk printed Partition table entries are not in disk order. Fix it in the expert menu:
Command (m for help): x Expert command (m for help): f Partitions order fixed. Expert command (m for help): r Command (m for help): w
The partitions were renumbered by position. Update /etc/fstab if it uses device names such as /dev/sdb5; file system UUIDs do not change.
7. Create partitions from a script
# printf 'label: gpt\n,300M\n,\n' | sfdisk /dev/sdb ... Device Start End Sectors Size Type /dev/sdb1 2048 616447 614400 300M Linux filesystem /dev/sdb2 616448 2095103 1478656 722M Linux filesystem The partition table has been altered.
(1 GiB test disk.) Each line after the label is one partition: start, size; empty fields mean "default" or "the rest".
Common messages
The device contains 'ext4' signature and it will be removed by a write command.The disk (not a partition) holds an old file system. Writing a new table removes that signature, so make sure nothing on it is needed.fdisk -sstill prints a size, butfdisk --helpmarks it[DEPRECATED]and the fdisk manual points toblockdevinstead;lsblkalso shows sizes.- Old guides mention the DOS compatibility mode, cylinders and a reboot after every change. Current fdisk works in sectors, aligns partitions itself and tells the kernel about the new table when the disk is not in use.
Official documentation: fdisk manual and sfdisk manual.