Linux Hard Disk Format Command

Q. I’ve installed a new 250GB SATA hard disk on our office CentOS Linux server. How do I format a hard disk under Linux operating system from a shell prompt?

A.. There are total 4 steps involved for hard disk upgrade and installation procedure:

ADVERTISEMENTS

Step #1 : Partition the new disk using fdisk command

Following command will list all detected hard disks:
# fdisk -l | grep '^Disk'
Output:

Disk /dev/sda: 251.0 GB, 251000193024 bytes
Disk /dev/sdb: 251.0 GB, 251000193024 bytes

A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings.
To partition the disk – /dev/sdb, enter:
# fdisk /dev/sdb
The basic fdisk commands you need are:

  • m – print help
  • p – print the partition table
  • n – create a new partition
  • d – delete a partition
  • q – quit without saving changes
  • w – write the new partition table and exit

Step#2 : Format the new disk using mkfs.ext3 command

To format Linux partitions using ext2fs on the new disk:
# mkfs.ext3 /dev/sdb1

Step#3 : Mount the new disk using mount command

First create a mount point /disk1 and use mount command to mount /dev/sdb1, enter:
# mkdir /disk1
# mount /dev/sdb1 /disk1
# df -H

Step#4 : Update /etc/fstab file

Open /etc/fstab file, enter:
# vi /etc/fstab
Append as follows:

/dev/sdb1               /disk1           ext3    defaults        1 2

Save and close the file.

Task: Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backup, enter
# e2label /dev/sdb1 /backup
You can use label name insted of partition name to mount disk using /etc/fstab:
LABEL=/backup /disk1 ext3 defaults 1 2

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
73 comments… add one
  • aniket Mar 11, 2008 @ 13:53

    yah thats good for understand………

  • aniket Mar 11, 2008 @ 13:55

    i have 48TB storage server in raid 5, how do i format this server?

    • punam sen Dec 3, 2010 @ 18:27

      to format the corresponding hdd you need a RAM(Random Access Memory) 1 YB(yota byte)
      1YB=1024 ZB
      1ZB=1024 XB
      1XB=1024 PB
      1PB=1024 TB

      • HAHA May 3, 2013 @ 19:42

        That’s retarded.

      • Anand Oct 5, 2013 @ 16:47

        LOL, I’ve got 1 UB (UnniByte) RAM on my Server

        1UB=1024YB
        1YB=1024 ZB
        1ZB=1024 XB
        1XB=1024 PB
        1PB=1024 TB

        Is it possible to format my 1.4 MB floppy now?

      • as pon FB May 3, 2014 @ 9:01

        I have 90’90 power of per zylions! So what? You’ve only got a pint of milk!!! does your processor register ????

  • 🐧 nixCraft Mar 11, 2008 @ 14:20

    Aniket,

    Use LVM directly or read this tutorial which explains how to create partition larger than 2TB

  • ankur Mar 27, 2008 @ 5:36

    How do I format a harddisk using linux system call

  • lakshmikanthan Jul 9, 2008 @ 13:54

    hi,

    thank you fro valuable information

  • dragon Aug 1, 2008 @ 7:52

    how to format a disk by cpp programe?is there any sample code ?

  • Nagarajan Jan 6, 2009 @ 15:11

    Hi,

    Thank you very much this valuable information.

    Regards,
    Nagarajan.S.G

  • Iyyappan Jan 29, 2009 @ 8:16

    /dev/sdb1 /disk1 ext3 defaults 1 2

    The above line what is mean by defaults and what is 1 2 ?

    can u explain those two things !

    • bjaanes Nov 4, 2011 @ 21:48

      This is directly from the arch linux (amazing) documentation:

      1. The first number is “dump”: used by the dump utility to decide when to make a backup. Dump checks the entry and uses the number to decide if a file system should be backed up. Possible entries are 0 and 1. If 0, dump will ignore the file system; if 1, dump will make a backup. Most users will not have dump installed, so they should put 0 for the entry.
      2. The second number is “pass”: used by fsck to decide which order filesystems are to be checked. Possible entries are 0, 1 and 2. The root file system should have the highest priority 1 – all other file systems you want to have checked should have a 2. File systems with a value 0 will not be checked by the fsck utility.
      • Pgt Aug 22, 2012 @ 0:55

        Thanks bjaanes

  • shyam kumar Feb 24, 2009 @ 5:50

    IN my system both WINDOWS-XP and LINUX , I’ve installed. after that
    I want to format the linux OS from my system.
    so please send to me tricks or method on Email addr., so i can remove LUNUX OS from my system.
    BY both method (i)Text command and
    (ii)without Text command.

    • Greatkanth Mar 22, 2011 @ 10:07

      Hey man I also have same problem .did u got any methods to remove . please help man

  • HyPerCuBe Mar 12, 2009 @ 15:56

    verrrrrrrrry useful i’ve searched for 2 days for this thanks

  • Sathish Apr 16, 2009 @ 10:47

    Hi,

    Thank you very much this valuable information. Very useful this

    Thanks
    B. Sathish.

  • Prasoon May 11, 2009 @ 18:18

    I have installed CentOS ..
    now i want my disk to be fully formatted like a new one. with no files on it..

    i remember doing it by booting in DOS mode in Win98..
    Please tell how can i do it..

  • mjisri May 20, 2009 @ 4:06

    Thank you.
    nice and clear.

  • LinuxUser Jul 14, 2009 @ 8:10

    Excellent and easy. Thanx

  • Charanjit Singh Cheema Jul 18, 2009 @ 7:20

    Nice information and esp. the link that you posted for Anikat. Information really useful pal. Thanks a ton..

    Regards
    Charanjit Singh Cheema

  • Carlo Aug 16, 2009 @ 11:14

    Thank you, this is the kind of fast reference that one is always looking for

  • antonio Aug 21, 2009 @ 22:23

    Well, this saved me an hour of banging my head against the wall… well written! thanks!

  • Jam Sep 1, 2009 @ 10:00

    Yes. Very useful. Thanks.

  • anburaja Sep 9, 2009 @ 12:11

    help me to see the out put of the php programe, i have php 2007 developer

  • anburaja Sep 9, 2009 @ 12:13

    god bless you

  • Lion Sep 21, 2009 @ 19:42

    Very simple and useful, thanks :)

  • Chris Nov 6, 2009 @ 2:08

    Great. Searched for a long time to find this, very well done. Thanks!

  • Sanjay Jan 15, 2010 @ 10:59

    Can any one tell me what the mean by 1,2 in default and when i create a raid partition is there any change in default charcter or it is sama as ” default” .

  • manikandan Apr 14, 2010 @ 6:50

    IN my Laptop both WINDOWS-XP and LINUX, i’ve safe the problem in windows hal.dll file is corrupted.
    so please send to me tricks or method on Email addr.

  • Rick May 1, 2010 @ 13:48

    Good Recipe for what I did in UNIX for years with the simple format command.
    You boiled it down to an excellent example…

  • Sigie May 1, 2010 @ 14:14

    very helpfull , thanks.

  • aaron May 14, 2010 @ 17:29

    very first command (fdisk /dev/sdb) failed. message is “Unable to open /dev/sdb”. any suggestions?

  • Abdelmannan May 23, 2010 @ 12:07

    Hello all,

    Is there any software to bound two NIC to use on ip address for both NICs.

    Thanks

  • Pankaj, Lucknow Jun 7, 2010 @ 11:26

    Thank you very much these are very good and easy way commands to understand for the people.

  • mumunendra kumar Jul 26, 2010 @ 16:42

    how to format linex form my system plz reply solution at my email

  • vahid Aug 26, 2010 @ 3:02

    thanks alot ,,,,, that was really usefull

  • sandeep choudhary Aug 27, 2010 @ 13:52

    how many formatting for window and linux
    plz sand ams on my email address

  • raj Sep 30, 2010 @ 18:46

    I deleted the panel in ubuntu by mistake.. how can i get the default panels?

  • sathishkumar Oct 14, 2010 @ 14:53

    The above steps are so good and easy to format

    Thank u Very much for your Formating steps.

  • linux Dec 18, 2010 @ 16:12

    a very nice article. thank you for sharing.

  • kunal Dec 30, 2010 @ 10:10

    how do installed linux …. with command ???? tell me all command…????

  • bapi Jan 30, 2011 @ 5:04

    IN my system both WINDOWS-XP and LINUX , I’ve installed. after that
    I want to format the linux OS from my system.
    so please send to me tricks or method on Email addr., so i can remove LUNUX OS from my system.
    BY both method (i)Text command and
    (ii)without Text command.

  • Guy Feb 6, 2011 @ 1:04

    Good article.
    Note: this works on centos 5.5 … fyi.

  • tmel173 Jun 1, 2011 @ 16:09

    This is beautiful!!! There are some who care out there..

  • Narendra Jun 10, 2011 @ 4:28

    IN my system both WINDOWS-XP and LINUX , I’ve installed. after that
    I want to format the linux OS from my system.
    so please send to me tricks or method on Email addr., so i can remove LUNUX OS from my system.
    BY both method
    (i)Text command and
    (ii)without Text command.

    • Aravind Sep 12, 2011 @ 8:39

      Hi Naren…I need to format my linux suse10.3 from my system.Will you please help me how to do.i am very new to this linux.If u have any tricks means please send me that files also.Aravind
      Thank you

  • paco Jul 31, 2011 @ 15:42

    Good tuto, thank you

  • retheesh Oct 4, 2011 @ 15:31

    very good solution thanks…

  • Ashok Dec 13, 2011 @ 2:39

    Very Good solution.

    Thanks

  • Zero Feb 11, 2012 @ 12:58

    just wanted to let you know you just saved my life, cheers mate

  • BINU RAJAN Mar 22, 2012 @ 17:49

    Vivek Gite U R GREAT
    MY HDD WAS DETCTED BUT WAS NOT BOOTING AND WAS ALSO DENYING FRESH INSTALLATION OF WINDOWS AND WAS RETURNING SOME STOP ERROR …. BUT AFTER FORMATING ONE OF MY PARTITION IN SLAX NOW EVERYTHING IS BACK TO NORMAL AND IT ALSO SAVED MY TONNES OF DATA

  • brandon Apr 20, 2012 @ 19:11

    I am using VMWare version 8 to run backtrack 5 and I added another hard drive to it. How do I format the drive to place a rainbow table on the said drive?

    • Sia Gi May 15, 2012 @ 20:48

      Very good and concise tutorial, thank you.

  • Vicky Jul 2, 2012 @ 12:50

    HI,

    I have a FS created with the below cmd and started using fine.

    mkfs.ext3 /dev/sdb1
    (/dev/sdb1 been allocated from SAN with 1 TB capacity)

    Now, I have resized the disk /dev/sdb1 to 2 TB from the SAN. After this my filesystem doesn’t show the resized capacity of 2 TB :(, it still shows as 1 TB. What has to be done to get the FS space resized without data loss ?

    Please help with this.

    Thank you.
    Cheers,
    Vicky

  • Vimal Jul 30, 2012 @ 18:24

    Very clear & complete. Keep it up..!

  • Ahphu Aug 18, 2012 @ 4:57

    hi
    I have 640GB. how to format this hard disk for Linux operating system?
    Please help me solution…..

  • Nickiest Feb 12, 2013 @ 9:08

    I think you make a wrong typing in mkfs. In the line is hdb not sdb. ok?

  • Tejas Sakhare Apr 29, 2013 @ 5:50

    I have 1.60GB. how to format this hard disk of Linux OS System. I have try but disk not detected for formatting. I want to OS Windows
    Please help me solution…..

  • lalji Jun 8, 2013 @ 10:32

    thank to much sir

  • Paola L. Aug 8, 2014 @ 8:48

    Written in a clear and simple!!
    Thank you :)

  • sarah Sep 9, 2014 @ 6:12

    I am extremely techie challenged :( I do not know what kind of linux I have on my laptop. All I want to do is format my USB drive but I receive an error message.

    Sorry, could not display all the contents of “THE GALILEO”: Error when getting information for file ‘/media/sarah/THE GALILEO/FOUND.000’: Input/output error

    Easy way to correct and format?

  • Wellington Torrejais da Silva Sep 16, 2014 @ 19:42

    Thanks!!!

  • Chhen Korn Jun 15, 2015 @ 8:03

    could you tell me about how install linux in pc step by step?

  • Shankito Aug 5, 2015 @ 21:00

    U ttract from teh very stupid peeple.

    Canopener u tell me hot to format my hippocampus with using dd from commander lion?

    I tired “# dd if=/dev/zero of=/dev/hippo1”

    but a large aminal dieded instead.

    God blast you and tanks

  • Toek Sarin Jan 20, 2016 @ 10:11

    thank you so much for share this Document and when I saw it make me clear for do my assignment.

    Thank you

  • Adriano Mar 12, 2016 @ 6:13

    Simple and clear. thank you!

  • Jorge Gonzalez Sep 6, 2016 @ 15:13

    Excellent thank you so much.

  • David Nov 20, 2016 @ 9:20

    I have some read errors that are causing the log tree to fail to recover. The HD seems to function but I have been unsuccessful at repairing or reinstalling Opensuse OS. I keep finding commands to try but when I try them I get “command not found”. Finally I thought I would reformat but I can’t even get the fdisk commands described here to work either. What do I do?

  • senju Dec 1, 2016 @ 2:54

    where should i go ? because im looking the step by step reformat of ebondo?linux?

  • Luis Quissak Dec 29, 2016 @ 11:52

    Very useful, thanks!!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.