Using fdisk to List, Create, Delete, and Change Linux Disk Partitions
Learn how to use Linux fdisk safely to inspect partition tables, create and delete partitions, change partition types, and prepare storage for later formatting and mounting.
fdisk is an interactive, text-based Linux utility for viewing and modifying disk partition tables. A partition table is disk metadata that records where partitions begin and end, their identifiers, and attributes.
This guide covers inspecting a disk, creating and deleting partitions, changing partition types, reviewing pending edits, and safely writing or discarding changes. Partitioning is potentially destructive: verify the target disk, maintain backups, and avoid changing a disk that contains mounted or actively used data.
What fdisk Manages
A disk device is the path for an entire storage device, such as /dev/sda or /dev/nvme0n1. A partition is a defined region of that disk, represented by a path such as /dev/sda1 or /dev/nvme0n1p1. In normal use, start fdisk with the whole-disk device, not an existing partition path.
fdisk records partition boundaries in sectors. A sector is an addressable disk unit used to describe a partition's start and end. After a partition exists, a separate tool creates a filesystem such as ext4 or XFS inside it. Linux then makes that filesystem available with a mount operation.
Identify the Correct Disk First
Never choose a device only because its name looks familiar. Device letters can change when disks are added, removed, or detected in a different order. Compare the device's capacity, model, partition layout, filesystem information, and mount points with your expectations.
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTSThis non-destructive command shows disks and partitions in a tree. The TYPE column helps distinguish a whole disk from a partition, while FSTYPE and MOUNTPOINTS reveal existing usage.
sudo fdisk -lThis lists recognized disks and partition tables without opening an editing session. Use both commands when identifying an unfamiliar disk.
Start an fdisk Session
Use sudo because changing partition metadata normally requires administrator privileges. Replace the example device only after verifying it.
sudo fdisk /dev/sdXFor an NVMe whole disk, use the complete disk path:
sudo fdisk /dev/nvme0n1fdisk opens an interactive prompt. Type m to display its built-in help. Most edits are held in memory during the session. They do not become persistent until you explicitly use w.
Print and Interpret the Partition Table
Inside fdisk, use:
pThe output identifies the disk and displays its current or proposed partitions. Typical fields include:
- Device: The partition path, such as
/dev/sda1. - Boot flag: A boot-related marker where applicable. Its meaning depends on the partition-table format and firmware or bootloader design.
- Start: The first sector assigned to the partition.
- End: The last sector assigned to the partition.
- Sectors: The number of sectors in the partition.
- Size: A human-readable approximation of the partition capacity.
- Type: The identifier and descriptive name, such as a Linux filesystem or Linux swap type.
Free space appears as gaps between the disk's usable sectors and existing partition ranges. Accepting fdisk's sensible default boundaries usually preserves alignment. Alignment places partitions at efficient boundaries, which is particularly important for modern disks and solid-state storage.
Create a Partition
Before creating anything, use p and confirm that the selected disk contains the intended unallocated space. Then enter:
nfdisk may ask for a partition number, the first sector, and the last sector or desired size. On an MBR/DOS table, it may also ask whether to create a primary or extended partition. On GPT, the available questions and partition model differ.
- Enter an available partition number, or accept the suggested number.
- For the first sector, accept the default unless you have a specific layout requirement.
- For the last sector, accept the default to use the available range, or enter a size with a supported suffix such as
+20G. - Use
pto inspect the proposed table before writing.
For example, a new data partition might use the default first sector and a size of +100G, leaving later free space for another purpose. Creating the partition only creates boundaries and metadata; it does not create a filesystem.
Delete a Partition
Print the table first and identify the exact partition number. Then use:
dWhen prompted, enter the number of the partition to remove. Print the pending table again with p and verify that the intended entry, not a neighboring partition, has disappeared.
Deleting an entry removes its description from the partition table. It does not necessarily overwrite every byte formerly belonging to that partition immediately, so data may remain recoverable by specialized tools. However, once the deletion is written, the operating system no longer treats that region as the original partition, and its filesystem may become inaccessible.
If you are uncertain, use:
qThis exits without applying pending deletion or other edits.
Change a Partition Type
A partition type is metadata indicating intended use. It is distinct from a filesystem. The common Linux filesystem type is intended for ordinary Linux data partitions, while the Linux swap type identifies a partition intended for swap space.
To change a type, enter:
tSelect the target partition number when prompted. During the type-selection workflow, use:
lto display recognized type codes or names. Choose the identifier appropriate for the intended use, then print the pending table for review.
Changing a type code does not format the partition, create swap, convert ext4 to XFS, or migrate existing data. Use filesystem- or swap-specific tools afterward, and only after verifying the target path.
Save or Discard Changes
Review the proposed table with p. If it is correct, write it with:
wThis updates the partition table and exits fdisk. Writing a deletion or a changed boundary can make data inaccessible, so treat w as an operational change, not a harmless save command.
To abandon all unwritten edits:
qAfter writing, the kernel may need to reread the table. When appropriate and when the disk is not actively in use, request a reread with:
sudo partprobe /dev/sdXIf the kernel cannot reload the table because partitions are mounted, used by swap, or part of the running system, rebooting may be necessary. Do not force changes to an active system disk merely to avoid a reboot.
MBR/DOS and GPT Partition Tables
MBR/DOS is a legacy partition-table format. It traditionally supports primary partitions, an extended partition, and logical partitions inside that extended container. The number of directly recorded primary entries is limited, which led to the extended/logical workaround.
GPT, or GUID Partition Table, is the modern format commonly used with UEFI systems and large disks. GPT records partitions in its own partition-entry array and does not use the MBR primary, extended, and logical organization. It normally supports many partitions without the old extended-partition container model.
fdisk's prompts and available options vary with the util-linux version and the disk's partition-table type. Do not apply an MBR tutorial mechanically to a GPT disk, or assume that a displayed type name has identical boot implications in every environment.
Practical Workflow: Inspect a SATA or Virtual Disk
- List devices and mount points:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS. - Compare the intended disk's capacity and model information with the output.
- Open the verified whole disk, for example
sudo fdisk /dev/sda. - Print the table with
p. - Interpret partition numbers, sector ranges, sizes, and types.
- Exit with
qbecause this inspection made no changes.
Practical Workflow: Create a Linux Data Partition
- Confirm the disk has unallocated space and is not the wrong device.
- Open fdisk with administrator privileges.
- Use
nand answer the partition-number, first-sector, and last-sector or size prompts. - Use
pto review the proposed table, including the new partition path. - If anything is wrong, use
qand start again. If correct, usew. - Recheck the result with
sudo fdisk -lorlsblk. - Create a filesystem separately, only after verifying the device name:
sudo mkfs.ext4 /dev/sdX1Formatting can destroy existing data on the selected partition. After formatting, mount the filesystem with the appropriate mount workflow and optionally configure persistent mounting in /etc/fstab.
Practical Workflow: Delete or Cancel Safely
- Print the table and record the exact partition number.
- Use
dand select that number. - Print again with
pto verify the pending deletion. - Use
qto cancel without writing if there is any doubt. - Use
wonly after confirming that the partition is backed up and no required data depends on it.
Practical Workflow: Mark a Partition for Linux Swap
- Create or select the intended partition and verify its path.
- Use
tand select the partition number. - Use
lto display recognized types, then choose the Linux swap type. - Print the pending table and write it with
wafter review. - Create and enable swap as separate operations:
sudo mkswap /dev/sdX2 && sudo swapon /dev/sdX2Enabling swap does not happen automatically merely because fdisk assigned the Linux swap type. Persistent swap configuration is a separate administration task.
Practical Workflow: NVMe Devices
For an NVMe disk, the whole-device path includes a namespace number, such as /dev/nvme0n1. Its first partition is normally /dev/nvme0n1p1, not /dev/nvme0n11.
sudo fdisk /dev/nvme0n1Use the whole-disk path when starting fdisk. After creating a partition, check the resulting name with p, lsblk, or a non-destructive fdisk listing before formatting or mounting it.
Post-Partitioning Workflow
Partitioning is one stage in a storage workflow:
- Confirm the new partition layout.
- Verify the partition device name and intended purpose.
- Create an appropriate filesystem, or create a swap signature if it is swap space.
- Mount a filesystem or activate swap.
- Optionally configure persistent mounting or swap activation using the system's normal configuration methods.
Keep these stages separate. A partition can exist without containing a filesystem, and a filesystem can exist without being mounted. Always verify the device before using destructive commands such as mkfs.
Safety Rules
- Back up important data before changing any partition table.
- Confirm the disk by size, model, layout, and mount points, not by device letter alone.
- Do not edit mounted or actively used partitions when an unmounted maintenance or rescue environment is available.
- Be especially cautious with the system disk, active swap, RAID, LVM, encrypted volumes, removable media, and virtual-machine disks.
- Review the pending table with
pbefore usingw. - After completing the operation, inspect the result non-destructively with
lsblkorsudo fdisk -l.
Troubleshooting fdisk Operations
The wrong disk might be selected
If the displayed size, model, mounted partitions, or existing layout does not match your plan, use q immediately. Compare devices again with lsblk and sudo fdisk -l. Do not rely on a device letter because enumeration can change.
The new partition does not appear after writing
Recheck the table with sudo fdisk -l. If the disk is not actively in use, request a kernel reread with sudo partprobe /dev/sdX. If the kernel cannot safely reload the table, reboot and check again.
fdisk says that the disk or partition is busy
Identify mounted filesystems and active swap. Do not force changes to a running system disk. Unmount or deactivate storage only when operationally safe, or perform the change from a maintenance or rescue environment.
A created partition cannot be mounted
fdisk created only a partition boundary and metadata. It did not create a filesystem. Confirm the partition path, create the intended filesystem, and then mount that partition.
A type change did not convert the filesystem
A type code is metadata, not a conversion tool. Changing it does not alter the existing filesystem or its data. Use a planned filesystem migration or formatting procedure when conversion is actually required.
The expected MBR partition kind is unavailable
Check whether the disk uses GPT. Primary, extended, and logical terminology belongs to the traditional MBR model and may not appear for GPT disks.
Exam-Relevant Notes
- fdisk manages partition tables, not filesystems.
- Use the whole disk, such as
/dev/sdaor/dev/nvme0n1, when opening a normal fdisk session. pprints,ncreates,ddeletes,tchanges a type,qdiscards, andwwrites.- A partition type indicates intended use but does not format or convert the partition.
- MBR uses primary, extended, and logical concepts; GPT does not use that model.
- Partitioning changes can destroy access to data, especially when written to a disk with active or mounted storage.
Related Linux Storage Topics
For surrounding Linux administration skills, see Linux, showing the full path of shell commands, Bash, and determining file types.