About Linux FAQ

Browse More FAQs:

How to: Formatting Linux Filesystem

Posted by Vivek Gite [Last updated: November 29, 2007]

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

A. Formatting linux filesystem required for many reasons. If you want to expand file system or you just added 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
OR
mkfs.ext3 /dev/DEVICE

Where,

  • -t filetype : File system type, it can be ext3, ext2, 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.

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

# mkfs.ext3 /dev/sda5

Output:

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

Where,

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

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Discussion on This FAQ

  1. Juan Francisco Giordana Says:

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

  2. nixcraft Says:

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

  3. Gagan Brahmi Says:

    Hi,

    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

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

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

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , , , , , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.