In This Article
What is fdisk?
In simple words, fdisk refers to the external command-line utility of MS-DOS that configures the hard drives of the computers. Technically, it is the manipulator of the partition table on Linux and also writes the Master Boot Record (MBR).
- Typically, fdisk is a command-line utility used for partitioning the hard disks on computer systems as well as for writing the Master Boot Record.
- This specific utility is available in different operating systems including MS-DOS 3.3x, IBM OS/2, DR FlexOS, and several other earlier versions of Windows.
- It is also used by different ports and was also a part of FreeBSD, NetBSD, OpenBSD, and others as well as macOS.
- Using the fdisk utility offers some specific benefits such as data protection by hiding the partitions, use in old computer systems, and use as a boot manager as well.
- The limitations of fdisk include the inability to move an application from one partition to another without uninstalling and reinstalling it or deleting a partition without data loss.
Ideally, the command-line utility fdisk facilitates disk partitioning and has been an integral part of the Disk Operating System (DOS).
Initially, fdisk was available in different operating systems such as:
- MS-DOS 3.3x
- IBM OS/2
- DR FlexOS
- Windows 95
- Windows 98
- Windows ME
The DOS fdisk utility was however available with the original Windows 95 operating system and could only create File Allocation Table or FAT partitions, especially the FAT12 and FAT16 types of it. The later type, FAT32, came with the Windows 95B versions and higher.
In addition to that, it was also a part of a few specific ports of the following open-source and free Unix-like operating systems:
- DragonFly BSD
This inclusion offered additional compatibility.
The most significant advantage of using the fdisk utility is that it allows hiding the partitions from other users. This ensures that your data is protected.
Moreover, you can use it as a boot manager as well. This will allow you to use more than one operating system most easily.
And, most importantly, if you are using an old computer system, there will be no need to upgrade the Basic Input Output System (BIOS).
However, there are a few limitations to fdisk. One of the most notable drawbacks of it is that it does not allow moving an application from one partition to the other, or from one drive letter to the other, without uninstalling and reinstalling.
Another notable downside of it in this respect is that you will not be able to delete a partition without losing all the data stored in it.
This means that you will have to repeat the whole fdisk process from the beginning and reformat the partition.
Ideally, it is also required to create a number of partitions if you want to make the best use of the full capacity of the hard drive.
The added capabilities of DOS fdisk make it a competent partitioning tool just like the other third-party programs.
It will help you to set up the partition in an ideal manner and it will let more than one operating system to exist on one single system.
However, fdisk shows two DOS partitions only, such as:
- The primary partition
- The extended partition
The extended partition is, however, further divided into different logical volumes, each of which acts as an individual partition.
The minimum size of a partition is 1 MB, following the principle of creating partitions by the fdisk in DOS 4.0 or later on numbers of megabytes. The sizes of these partitions are typically restricted to 2 GB.
In comparison, the DOS versions before 4.0 supported a maximum partition size of 32 MB.
This is a huge number of bytes. It can be calculated as:
= 2048 GB
= 2,097,152 MB
= 2,147,483,648 KB
= 2,199,023,255,552 bytes.
What is fdisk Used for?
The tool allows changing the partitioning of the hard drive on different types of operating systems apart from the common ones already mentioned above, such as:
- Windows NT
- BeOS and lots more
In summary, when you use the fdisk utility, you can do a lot of things, such as:
- Create or delete the primary DOS partition
- Activate or deactivate the primary DOS partition
- Delete non-DOS partitions
- Create or delete logical drives
- Create or delete an extended DOS partition
- Change fixed disk
- Create or delete one FAT12 partition
- Change the active partition
- Display partition data
- Write or repair the Master Boot Record
fdisk in Linux
In all Linux distributions, you will find fdisk already pre-installed as it is the standard package of the Linux kernel. This tool allows resizing, viewing, deleting, copying, changing, and moving partitions on the hard drive by using different commands.
You can create as many as four new primary partitions along with many logical partitions, depending on the size of the hard disk in the system.
Typically, using the fdisk command in Linux will help you to manipulate the hard disk in a lot of different ways such as:
- It will help you in reorganizing the old archives.
- It will allow moving or copying data to the new hard drives.
- It will facilitate creating more space or organizing the existing space to accommodate new partitions.
All these can be done by using a few specific commands on Linux.
To use fdisk on Linux, the syntax is very simple, which is fdisk <options> <disk>.
You will be provided with a lot of different options that are necessary to use with the fdisk command in Linux. Take a look at these options:
- -b: This option denotes the physical and logical size of the sector.
- -B: This option does not allow erasing boot bits while creating a new label.
- -L: This option colors the outputs.
- -l: This option displays the partitions of the disks.
- -o / –output <lists>: This option displays the specified columns.
- -t: This option helps in recognizing only the specific partition table.
- -u: This option displays the ‘cylinders’ or ‘sectors’ units.
- -s: This option shows the size of the device in 512-byte sectors.
- -w: This option will wipe off the signatures.
- -W: This option will also wipe the signatures, but from the new partition.
- -C: This option denotes the number of cylinders.
- -H: This option stipulates the number of heads.
- -S: This option tells the number of sectors present in each track.
- -h: This option will open the help document regarding fdisk.
- -V: This option shows the version of the fdisk being used.
A few common commands to use fdisk in Linux are as follows:
- To view partitions of all the disks – sudo fdisk – l.
- To view partitions of a particular disk – sudo fdisk – l /dev/<name>.
- To enter command mode to tinker with a specific disk name, say, /dev/sda, – sudo fdisk /dev/sda.
- To see all the commands in the command mode – Press ‘m’ while in the command mode.
- To view a partition table or print it – Press the letter ‘p’ while in the command mode.
- To delete a partition of a particular disk – Type the letter ‘d’ and enter the partition number you want to delete when prompted.
- To create a new partition on a particular disk – Press the letter ‘n’ and the partition number in the command mode.
- To format a partition created say, 5, – sudo mkfs. ext5 /dev/sda5.
- To check the size of a particular partition, say, 2, – sudo fdisk -s /dev/sda2.
- To disable the boot flag (*) of a partition – Press the letter ‘a’ in command mode and enter the partition number when prompted.
- To fix the partition table order – Press the letter ‘x’ in the command mode, enter the expert command ‘f’ to fix the order and then the letter ‘w’ to save and exit.
If you are stuck anywhere at any point during the process, you should use the manual of the tool. In such times, instead of using the traditional fdisk command, sudo fdisk–help, you should run ‘man fdisk.’
fdisk Command in DOS
The fdisk command in DOS will allow you to create new partitions or delete an existing partition on a hard drive.
The commonly used command line parameter is FDISK [/STATUS] /X, where the status displays the information of the partition and ‘x’ will ignore Logical Block Addressing (LBA) or extended disk support.
In addition to that, there are also a few other undocumented or secret fdisk switches to use such as:
- FDISK /MBR – This is the command for rewriting the Master Boot Record (MBR).
- FDISK /CMBR – This command recreates the MBR or a specific disk. It is similar to the above with the only difference that it can be used on other drives.
- FDISK 1/PRI:100 – This command creates a 100 MB DOS partition on the hard drive 1.
- FDISK 1/EXT:500 – This command creates a 500 MB extended DOS partition on hard drive 1.
- FDISK 1/LOG:250 – This command creates a 250 MB logical drive on the hard disk drive.
- FDISK /PARTN – This command saves the partition to the PARTSAV.FIL file.
- FDISK /Q – This command will disable fdisk from booting the computer automatically after exiting from fdisk.
- FDISK /STATUS – This command will show the current status of the hard drives.
- FDISK /ACTOK – This command will not allow fdisk to check the integrity of the disk and allow creating drives much faster.
- FDISK /FPRMT – This command will force fdisk to use FAT32 support by getting the prompt for it on drives less than 540 MB since fdisk does not use FAT32 by default on any drive less than 540 MB.
You can use an additional command and follow these steps for using an fdisk script file from an external file. This will also allow creating and deleting partitions faster.
To do this, first you will have to create a file with the help of the DOS edit command and then do the following:
Edit fdisk.scr – This is the edit screen. You will need to enter the commands to run in fdisk here, and display the information of the partition.
Here are the additional steps to follow:
- Make your selection
- Press Enter
- Press Ctrl+P
- Press Ctrl+M
This will act as a carriage return. Just make sure that all the input commands are on one line to run fdisk.
When the script file is created, type fdisk < fdisk.scr to execute the file.
fdisk Vs gdisk
- Ideally, the fdisk utility is used for MBR partitioning, while, in comparison, the gdisk utility is its equivalent for Globally Unique Identifier or GUID Partition Table (GPT) partitions.
- The fdisk utility will show the disk label, but in comparison, the gdisk utility will show the partition table type.
So, coming to the end of the article, you now must have a fair idea about fdisk, how it works and how to use it to your advantage.
It is a very useful utility to configure the hard drive in your computer.
However, before you go ahead with the process, make sure that you take a backup of everything in your system first.