Linux fdisk Command: Inspect and Edit Disk Partitions
fdisk is a tool for viewing or editing a disk's partition table. It is useful for checking partition sizes and starting positions, but writing changes to the wrong disk can result in data loss.
What is the fdisk command?
fdisk -l is a read-only list view. In interactive editing, you create changes with several commands and must enter w to write them to the disk, while q exits without saving. It can handle GPT and DOS/MBR partition tables, but actual usable features depend on the util-linux version.
Basic syntax
fdisk [option] [disk device]
Installed implementations and options may vary by distribution. Use man fdisk to check the documentation on your current system.
Examples
Viewing the disk and partition list
Check the partition tables of all devices in read-only mode.
sudo fdisk -l
Viewing only the target disk
Insert the actual disk name identified by lsblk to narrow the scope.
sudo fdisk -l /dev/sdb
Device comparison before change
Check the model, capacity, and mount relationships again.
lsblk -o NAME,SIZE,MODEL,TYPE,MOUNTPOINTS
Distinguishing Between Viewing and Changing Partitions
fdisk -l only views the partition table and does not make any changes. Replace the device path in the following commands according to your actual system, but do not confuse the path of the entire disk with that of a partition.
sudo fdisk -l /dev/sdb
Part of the sample output (size and partition names vary depending on the environment):
Disk /dev/sdb: 20 GiB Device Start End Sectors Size Type /dev/sdb1 2048 41943039 41940992 20G Linux filesystem
In interactive fdisk /dev/sdb, you can view the current table with p and exit without saving with q. w writes any changes to the disk, which can make recovery difficult. Before writing, check the device size again with lsblk and prepare a backup of the partition table and data.
Main Options and Format
| Options/Format | Description |
|---|---|
-l |
List the partition table and exit. |
-x |
Display extended partition information and additional fields. |
-o column_list |
Select columns for list output. |
-t type |
Specify the partition table type. |
w / q |
In interactive mode, write changes and exit / exit without writing changes. |
Precautions when using
Before editing partitions, create a recoverable backup and do not confuse the whole disk device with the partition device. Changing the partition boundaries of a file system in use is particularly risky. After the change, the kernel may not be able to immediately reread the new table, and a reboot may be required. Never use the example /dev/sdb for editing without verifying the actual target.
Frequently Asked Questions
If you press q in fdisk, are the changes saved?
No. In interactive mode, q exits without writing to the disk, while w writes the changed partition table.
Official Documentation
You can check the exact behavior of the options and implementation differences in the official fdisk documentation.









