fdisk Command in Linux
Overview
The fdisk command in Linux is a powerful disk management tool used by system administrators for creating and manipulating disk partition tables. With fdisk, you can create, delete, resize, and manage partitions on your hard disk effectively.
Syntax of fdisk Command in Linux
The basic syntax of the fdisk command in Linux is as follows:
Where:
- options: These are flags that modify the behavior of the fdisk command.
- device: This specifies the disk device that fdisk will operate on. It typically looks something like /dev/sda or /dev/hdb.
Options in fdisk Command in Linux
-
-l: Lists the partition tables for the specified devices and then exits.
For example -
Output:
This command lists out all the partitions on all the drives.
-
-u: When listing partition tables, show sizes in sectors instead of cylinders.
For example -
Output:
This command shows the disk's size in sectors rather than the default cylinders.
-
-s: Display the size of a partition.
For example -
Output:
This command will show the size of the /dev/sda1 partition in blocks.
Example Usages
-
Creating a new partition:
Output:
Explanation: Here, 'n' is used to create a new partition on the disk /dev/sda.
-
Deleting a partition:
Output:
Explanation: Here, 'd' is used to delete a partition on the disk /dev/sda.
Tips
-
Always backup important data before modifying disk partitions.
-
Use the 'p' command in fdisk to preview partition changes before saving them.
-
Use the 'm' command in fdisk for help if you get stuck.
Advanced Use Cases of fdisk Command in Linux
-
Viewing disk details in sectors:
Output:
Explanation: This command shows the disk's size and partition information in sectors rather than the default cylinders.
-
Verifying the partition table:
Output:
Explanation: Here, 'v' is used to verify if the partition table on the disk /dev/sda is correct.
Conclusion
-
The fdisk command in Linux is a powerful tool for managing disk partitions.
-
It provides various options for listing, creating, deleting, and modifying partitions.
-
Always backup important data before using fdisk to modify partitions.
-
For help while using fdisk, use the 'm' command.