Guide to Disk Partitioning and Management with Linux fdisk
Learn step by step how to partition, format and mount disks with the Linux fdisk command. Technical knowledge base guide.
Contents
Introduction
fdisk, the most basic and powerful command used to manage disk partition tables in Linux systems. It is one of the line tools. This guide explains the step-by-step process from preparing a disk from scratch to editing existing partitions.
Listing and Identifying Disks
Identifying the correct disk before taking action is critical to prevent data loss. You can use the following commands to view existing disks and partitions:
lsblk -f
sudo fdisk -lWarning: Choosing the wrong disk may cause all data to be deleted. Always check the model and size information with lsblk.Disk Partitioning Procedures
- Open the Disk: Enter interactive mode with the
sudo fdisk /dev/sdXcommand. - Create a Partition Table: On a new disk, first select the table type:
g(GPT) oro(MBR). - Create New Partition: Press
n. UseEnterto accept the default values. - Size Specification: Enter the partition size using expressions such as
+10Gor+100G. - Save Changes: Review the table with
pand exit by typingw.
Partition Types Change
Use the t command to change the partition type. For example, to mark a partition as LVM or Swap, select the appropriate code listed with l.
Formatting and Mounting (Mount)
After the partition is created, the file system must be created and mounted:
sudo mkfs.ext4 /dev/sdX1
sudo mkdir -p /mnt/data
sudo mount /dev/sdX1 /mnt/dataSecurity and Tips
During the operations, you can verify the partition table with the v command, and exit without making any changes with q. If a disk is in use, be sure to unmount it first with the umount command. The partprobe command causes the kernel to re-read the partition table and helps the system immediately recognize the change.