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

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)

  1. Open the disk: fdisk /dev/sdb. On an empty disk fdisk says Created a new DOS (MBR) disklabel: that table is only in memory.
  2. Type g to 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.
  3. Type n. Accept the partition number and the first sector with Enter (2048 here: fdisk aligns its default values to the disk).
  4. For the last sector, type a size: +1G, +500M, or Enter for all remaining space.
  5. Type p to check, then w to 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

  1. Create a file system: mkfs.ext4 -L data /dev/sdb1 (or mkfs.xfs /dev/sdb1 for XFS). For a swap partition use mkswap /dev/sdb2.
  2. 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
  3. To mount it at every boot, get the UUID with blkid /dev/sdb1 and add a line to /etc/fstab:
    UUID=your-uuid  /mnt/data  ext4  defaults  0  2
  4. Test the file before rebooting: findmnt --verify printed Success, no errors or warnings detected and mount -a mounted the partition. With a wrong UUID, mount -a said can'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:

  • p print the table, F list free space, i details of one partition, v verify the table.
  • t change the type. fdisk 2.41 also accepts aliases, for example swap and lvm:
    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'.
  • d delete a partition (details in the delete article linked above), e resize a partition.
  • a toggle the bootable flag (MBR only), g new GPT table, o new MBR table.
  • O and I save and load the layout as an sfdisk script file.
  • x expert menu, w write and exit, q quit 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 -s still prints a size, but fdisk --help marks it [DEPRECATED] and the fdisk manual points to blockdev instead; lsblk also 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.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket