HowTo: Formatting Linux Filesystem

How do I format Linux file system? Can you tell me command names to format and create a Linux file system?

Formatting Linux filesystem is an essential task for sysadmin and may required for many reasons such as installing a new disk on server. If you want to expand file system or you just add a new hard disk drive or create separate partitions for security and performance reasons. Whatever may be your reason(s) all file system creating involves creations of superblock, inode and other filesystem metadata structure. Fortunately, Linux comes with mkfs command to format filesystem. It is used to build a Linux file system on a device, usually a hard disk partition. General syntax of mkfs is as follows:
mkfs -t filetype /dev/DEVICE
mkfs.ext3 /dev/DEVICE
mkfs.ext4 /dev/DEVICE
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements None
Est. reading time 5m
[/donotprint] Where,
  • -t filetype : File system type, it can be ext3, ext2, etc4, vfat etc
  • /dev/DEVICE : Your device name i.e. partition /dev/hda1 or /dev/sda1 etc.

An example

Suppose you would like to format /dev/hda5 with ext3 file system.

Warning: The first task is to allocate disk space for Linux. You will need to set up a partitioning scheme for your hard disk using a program called fdisk command.

Step #1 Create the new filesystem with following command (first login in as a root user)

# mkfs.ext3 /dev/sda5
Sample outputs:

mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
30120 inodes, 120456 blocks
6022 blocks (5.00%) reserved for the super user
First data block=1
15 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
     8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Step # 2: Create mount point directory for the file system

# mkdir /datadisk1

Step # 3: Mount the new file system

# mount /dev/sda5 /datadisk1

Step # 4: Finally make sure file system /dev/hda5 automatically mounted at /datadisk1 mount point after system reboots. You need to add partition to /etc/fstab file. Use text editor such as vi to add following entry

# vi /etc/fstab

Add/append following entry to file:
/dev/sda5 /datadisk1 ext3 defaults 0 2


  • /dev/sda5 : File system or parition name
  • /datadisk1 : Mount point
  • ext3 : File system type
  • defaults : Mount options (Read man page of mount command for all options)
  • 0 : Indicates whether you need to include or exclude this filesystem from dump command backup. Zero means this filesystem does not required dump.
  • 2 : It is used by the fsck program to determine the order in which filesystem checks are done at reboot time. The root (/) filesystem should be specified with a #1, and otherfilesystems should have a # 2 value.

Save file and exit to shell prompt. For more information see mkfs(8) page.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 12 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig 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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep 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
12 comments… add one
  • Juan Francisco Giordana Jun 11, 2007 @ 2:11

    Correction: At the beginning of the post you use /dev/hda5 and at the end /dev/sda5.

    • Rajesh Pal Dec 17, 2014 @ 7:20

      this error occur while format ……………
      give perfect answer

      root@gracious-desktop:~# /dev/sdc1 /datadisk1 ext3 defaults 0 2
      bash: /dev/sdc1: Permission denied

  • 🐧 nixCraft Jun 11, 2007 @ 7:53

    Thanks for the heads up. The post bas been updated.

  • Gagan Brahmi Sep 11, 2007 @ 16:09


    I don’t want to make this post look wrong, but there can be another command for creating a ext3 file system.

    The following is the same:-

    mke2fs -j /dev/sda5

  • daniel Aug 29, 2009 @ 19:48

    “mke2fs -j /dev/sda5” is correct. (id for etx3=83)
    I want to know how to creat a qnx filesystem, id=50

  • ss Nov 15, 2009 @ 11:19

    i cant understand the format watever u write in dis……………..

  • TGB Sep 28, 2011 @ 7:42

    root@s1 [~]# mkfs.ext3 /dev/sdb1
    mke2fs 1.39 (29-May-2006)
    mkfs.ext3: No such device or address while trying to determine filesystem size


  • abdulsalamkp Dec 7, 2012 @ 9:18

    its very helpful comments. :)

  • Thijs Jan 21, 2013 @ 21:48


  • drcreazy Feb 17, 2014 @ 8:47

    Please add info or link to article how to make partitions.

    In case if you try make file system on whole device:
    sudo mkfs.ext4 /dev/sdb
    You get “/dev/sdb is entire device, not just one partition!” message.

    In this case you need make at least one partition:
    sudo fdisk /dev/sdb

  • sagar Feb 1, 2015 @ 16:57

    During load file system using mkfs i got a error
    Anyone have solution of that error…….

  • aref ghobadi Aug 22, 2015 @ 5:46

    thanks a lot

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum