Linux Hard Disk Format Command

Posted on in Categories , , , last updated March 10, 2008

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:

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

73 comment

    1. 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.
  1. 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.

  2. 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..

  3. 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.

  4. 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.

    1. 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

  5. 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

  6. 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

  7. 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…..

  8. 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?

  9. 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

  10. 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?

Leave a Comment