The above will list partitions from all the connected hard disks. When you have more than one disk on the system, the partitions list are ordered by the device’s /dev name. For example, /dev/sda, /dev/sdb, /dev/sdc and so on.

2. View Partitions of a Specific Hard Disk using fdisk -l /dev/sd{a}

To view all partitions of the /dev/sda hard disk, do the following.

# fdisk -l /dev/sda

View all fdisk Commands Using fdisk Command m

Use fdisk command m, to view all available fdisk commands as shown below.

# fdisk /dev/sda
The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

3. Delete a Hard Disk Partition Using fdisk Command d

Let us assume that you like to combine several partitions (for example, /dev/sda6, /dev/sda7 and /dev/sda8) into a single disk partition. To do this, you should first delete all those individual partitions, as shown below.

4. Create a New Disk Partition with Specific Size Using fdisk Command n

Once you’ve deleted all the existing partitions, you can create a new partition using all available space as shown below.

# fdisk /dev/sda
The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
First cylinder (2662-5283, default 2662):
Using default value 2662
Last cylinder, +cylinders or +size{K,M,G} (2662-3264, default 3264):
Using default value 3264

In the above example, fdisk n command is used to create new partition with the specific size. While creating a new partition, it expects following two inputs.

Starting cylinder number of the partition to be create (First cylinder).

Size of the partition (or) the last cylinder number (Last cylinder, +cylinders or +size ).

Please keep in mind that you should issue the fdisk write command (w) after any modifications.

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

After the partition is created, format it using the mkfs command as shown below.

# mkfs.ext3 /dev/sda7

5. View the Size of an existing Partition Using fdisk -s

As shown below, fdisk -s displays the size of the partition in blocks.

# fdisk -s /dev/sda7
4843566

The above output corresponds to about 4900MB.

6. Toggle the Boot Flag of a Partition Using fdisk Command a

Fdisk command displays the boot flag of each partition. When you want to disable or enable the boot flag on the corresponding partition, do the following.

If you don’t know why are you are doing this, you’ll mess-up your system.

7. Fix Partition Table Order Using fdisk Expert Command f

When you delete a logical partition, and recreate it again, you might see the “partition out of order” issue. i.e “Partition table entries are not in disk order” error message.

For example, when you delete three logical partitions (sda6, sda7 and sda8), and create a new partition, you might expect the new partition name to be sda6. But, the system might’ve created the new partition as sda7. This is because, after the partitions are deleted, sda9 partition has been moved as sda6 and the free space is moved to the end.

To fix this partition order issue, and assign sda6 to the newly created partition, execute the expert command f as shown below.

Thanks a lot!
After restoring a Windows installation to a new harddisk, i found that i had made a mistake with the partition-order, causing a non-boot. After reordering the partitions, it boots again (although i won’t use it, not my machine ;).

i had grub15 error so i read that using fdisk will adjust order of sda. so i did fdisk -l then fdisk /dev/sda then x f showed only two partitions and did w. now i am having problem that my home is not loading system in root emergency mode. i can see my data after using ctrl D and then home and then my data but i cant backup or copy my data to a usb drive plz tell what to do after doing fdisk -l i can see all partitions i.e. 6 partiions

Article was really good!!!
Just want to check few queries related to re sizing existing partition in USB drive.
I have installed the Ubuntu 14.0.1 on my USB drive and allocated 4 GB out of 16GB USB drive.
I have trying to re size the 4GB to 10 GB using gparted but again showing 4GB as used and 6 GB as unused.
How do I make 10 GB allocated to primary?

In the command you gave:
‘fdisk -s /dev/sda7’
‘4843566’
If the deprecated -s option displays partition size in number of 512 byte blocks, I think this should be about 2480MB, not 4900MB. I may be mistaken, and a minor nit-pick I know…

About The Geek Stuff

My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about Ramesh Natarajan and the blog.

Contact Us

Email Me :
Use this Contact Form to get in touch me with your comments, questions or suggestions about this site. You can also simply drop me a line to say hello!.