Formatting a hard disk is necessary if you are attaching a new hard disk on your computer. Disk formatting creates the files system in the hard disk so that the common files types can be recognized and Operating system can be installed. You can also format a hard disk if you completely want to remove data from any old hard disk. In Linux operating system, hard drives are represented as “hdx” and “sdx”. The ‘x’ here denotes the sequence of the hard drivers attached in your computer. The ‘hd’ in the abbreviation is used for IDE or ATA type hard disks and ‘sd’ is to represent SATA or SCSI hard drivers. In some cases you can also find number at the end of these representation which can be used to refer to different partition on the hard disk.

As discussed earlier, disk formatting can be done on old hard drives as well.

If you are formatting an old hard disk, you must take the backup of the data as the formatting will remove everything from the hard disk.

Here are some steps to format a hard disk in Linux operating system.

Metod 1:  By using FDISK command:


First of all you would need to run fdisk command to remove any of the previous partition from an old hard drive and create new partition. The “w” command in the console will make all the changes permanent, so make sure that you use this command before quitting the command console.

You can also use “Ctrl” + “c” command simultaneously to leave the console unchanged.


Now us the “fdisk /dev/hdb” command to replace the “hbd” with the letters for your drive.  Now use “p” command to enlist all the partition on the hard drive and it will also show the size of particular hard disk.


One you have the list of existing partions you can manage them accordingly. Use “d” command and pres “Enter” to delete any existing partion. This step will prompt you to delete selected partition. You can select the desired number of partition which you want to delete and you can also repeate the same step in case of multiple partitions.


Now you are ready to create new partition as all the existing partitions are deleted. Type ‘n’ and hit ‘enter’ to create new partition and then use ‘p’ command to create the primary partition. It will prompt to number you partition; select 1 as the partition number. Now it will ask for the first and last cylinder of the hard disk which is default, so just hit “enter” twice.


Now you can use “p” command in the in the command prompt to check the partition table and you must also see the newly created partition here.


At this point, you would need to create the file system for the newly created partition. You need to enter the Hex code value of the file system. Use the Hex code ‘83’ for the standard Linux ext2 file system.

Create a new file system:

Now you need to use “mkfs” command to create a new file system. Type the command “mkfs -t ext2 /dev/hdb1” at the command prompt.

If you have any other file system except “ext2” then you must specify the “ext2” in the above command.

Finalize formatting

Now the last step is to perform a check on the hard drive and enter it on fstab so that the drive is mounted at every restart of computer.

Type the command “fsck -f -y /dev/hdb1” at the command prompt. Your drive is now ready and formatted after the fsck run.