Linux Hard Disk Format Command

by Vivek Gite · 23 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:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 23 comments… read them below or add one }

1 aniket 03.11.08 at 1:53 pm

yah thats good for understand………

2 aniket 03.11.08 at 1:55 pm

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

3 vivek 03.11.08 at 2:20 pm

Aniket,

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

4 ankur 03.27.08 at 5:36 am

How do I format a harddisk using linux system call

5 lakshmikanthan 07.09.08 at 1:54 pm

hi,

thank you fro valuable information

6 dragon 08.01.08 at 7:52 am

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

7 Nagarajan 01.06.09 at 3:11 pm

Hi,

Thank you very much this valuable information.

Regards,
Nagarajan.S.G

8 Iyyappan 01.29.09 at 8:16 am

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

9 shyam kumar 02.24.09 at 5:50 am

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.

10 HyPerCuBe 03.12.09 at 3:56 pm

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

11 Sathish 04.16.09 at 10:47 am

Hi,

Thank you very much this valuable information. Very useful this

Thanks
B. Sathish.

12 Prasoon 05.11.09 at 6:18 pm

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

13 mjisri 05.20.09 at 4:06 am

Thank you.
nice and clear.

14 LinuxUser 07.14.09 at 8:10 am

Excellent and easy. Thanx

15 Charanjit Singh Cheema 07.18.09 at 7:20 am

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

Regards
Charanjit Singh Cheema

16 Carlo 08.16.09 at 11:14 am

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

17 antonio 08.21.09 at 10:23 pm

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

18 Jam 09.01.09 at 10:00 am

Yes. Very useful. Thanks.

19 anburaja 09.09.09 at 12:11 pm

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

20 anburaja 09.09.09 at 12:13 pm

god bless you

21 Lion 09.21.09 at 7:42 pm

Very simple and useful, thanks :)

22 Chris 11.06.09 at 2:08 am

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

23 Sanjay 01.15.10 at 10:59 am

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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All