Lesson 47: fdisk Command
In this lesson, you'll learn how to use the fdisk command to view, create, delete, and manage disk partitions in Linux.
fdisk (stands for "fixed disk or format disk") is the most commonly used command-line-based disk manipulation utility for Linux/Unix systems.
With the help of the fdisk command, you can view, create, resize, delete, change, copy, and move partitions on a hard drive using its own user-friendly text-based menu-driven interface.
This tool is very useful in terms of creating space for new partitions, organizing space for new drives, reorganizing old drives, and copying or moving data to new disks.
It allows you to create a maximum of four new primary partitions and several logical (extended) partitions, based on the size of the hard disk you have in your system.
Let's discuss 10 basic fdisk commands to manage a partition table in Linux-based systems.
You must be a root user to run the fdisk command, otherwise you will get a "command not found" error.
Caution: Don't create, delete, or modify partitions unless you know what you are doing!
fdisk Command Syntax
# fdisk [OPTIONS] DEVICE
fdisk Interactive Commands
| Command | Description |
|---|---|
m |
Print the help menu with all available commands |
p |
Print the current partition table |
n |
Add a new partition |
d |
Delete a partition |
l |
List known partition types |
t |
Change a partition's system ID |
a |
Toggle a bootable flag |
w |
Write the table to disk and exit |
q |
Quit without saving changes |
x |
Enter extra functionality (experts only) |
1. View All Disk Partitions
The following basic command lists all existing disk partitions on your system. The -l argument (stands for listing all partitions) is used with the fdisk command to view all available partitions on Linux.
The partitions are displayed by their device names, for example: /dev/sda, /dev/sdb, or /dev/sdc.
[root@TecMint ~]# fdisk -l
Disk /dev/sda: 637.8 GB, 637802643456 bytes
255 heads, 63 sectors/track, 77541 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2624 20972857+ 83 Linux
/dev/sda3 2625 4582 15727635 83 Linux
/dev/sda4 4583 77541 586043167+ 5 Extended
/dev/sda5 4583 5887 10482381 83 Linux
/dev/sda6 5888 7192 10482381 83 Linux
/dev/sda7 7193 7845 5245191 83 Linux
/dev/sda8 7846 8367 4192933+ 82 Linux swap / Solaris
/dev/sda9 8368 77541 555640123+ 8e Linux LVM