Linux Hard Disk Format Command

by Vivek Gite on March 10, 2008 · 47 comments

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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 47 comments… read them below or add one }

1 aniket March 11, 2008

yah thats good for understand………

Reply

2 aniket March 11, 2008

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

Reply

3 punam sen December 3, 2010

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

Reply

4 vivek March 11, 2008

Aniket,

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

Reply

5 ankur March 27, 2008

How do I format a harddisk using linux system call

Reply

6 lakshmikanthan July 9, 2008

hi,

thank you fro valuable information

Reply

7 dragon August 1, 2008

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

Reply

8 Nagarajan January 6, 2009

Hi,

Thank you very much this valuable information.

Regards,
Nagarajan.S.G

Reply

9 Iyyappan January 29, 2009

/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 !

Reply

10 bjaanes November 4, 2011

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.

Reply

11 shyam kumar February 24, 2009

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.

Reply

12 Greatkanth March 22, 2011

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

Reply

13 HyPerCuBe March 12, 2009

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

Reply

14 Sathish April 16, 2009

Hi,

Thank you very much this valuable information. Very useful this

Thanks
B. Sathish.

Reply

15 Prasoon May 11, 2009

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

Reply

16 mjisri May 20, 2009

Thank you.
nice and clear.

Reply

17 LinuxUser July 14, 2009

Excellent and easy. Thanx

Reply

18 Charanjit Singh Cheema July 18, 2009

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

Regards
Charanjit Singh Cheema

Reply

19 Carlo August 16, 2009

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

Reply

20 antonio August 21, 2009

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

Reply

21 Jam September 1, 2009

Yes. Very useful. Thanks.

Reply

22 anburaja September 9, 2009

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

Reply

23 anburaja September 9, 2009

god bless you

Reply

24 Lion September 21, 2009

Very simple and useful, thanks :)

Reply

25 Chris November 6, 2009

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

Reply

26 Sanjay January 15, 2010

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

Reply

27 manikandan April 14, 2010

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.

Reply

28 Rick May 1, 2010

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

Reply

29 Sigie May 1, 2010

very helpfull , thanks.

Reply

30 aaron May 14, 2010

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

Reply

31 Abdelmannan May 23, 2010

Hello all,

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

Thanks

Reply

32 Vivek Gite May 23, 2010
33 Pankaj, Lucknow June 7, 2010

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

Reply

34 mumunendra kumar July 26, 2010

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

Reply

35 vahid August 26, 2010

thanks alot ,,,,, that was really usefull

Reply

36 sandeep choudhary August 27, 2010

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

Reply

37 raj September 30, 2010

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

Reply

38 sathishkumar October 14, 2010

The above steps are so good and easy to format

Thank u Very much for your Formating steps.

Reply

39 linux December 18, 2010

a very nice article. thank you for sharing.

Reply

40 kunal December 30, 2010

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

Reply

41 bapi January 30, 2011

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.

Reply

42 Guy February 6, 2011

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

Reply

43 Narendra June 10, 2011

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.

Reply

44 Aravind September 12, 2011

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

Reply

45 paco July 31, 2011

Good tuto, thank you

Reply

46 retheesh October 4, 2011

very good solution thanks…

Reply

47 Ashok December 13, 2011

Very Good solution.

Thanks

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 11 + 12 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the simple math so we know that you are a human and not a script.




Previous post:

Next post: