How to Format in Linux

How to Format in Linux
Page content

Most of the novice users are also experimenting with Linux and love the Linux operating system over Windows.

Apart from knowing how to use the user interface and other important applications on Linux, you must also know how to do Linux formatting. Formatting in Linux is often done using the fsck, fdisk, and mkfs commands. The technique can be utilized ether to format a drive before system installation or to format a secondary drive. When you format a hard drive, no data will be preserved on it. You will lose everything saved in it so it is recommended to create a backup for your important files.

If you are formatting your drive for expanding its size or dividing it into newer sections, then you may have to use creation of an inode, superblock, and other file system metadata structure for all file system creations. The mkfs command in Linux is used to create a Linux file system on a hard disk partition. The basic syntax followed is:

mkfs -t filetype /dev/DEVICE

OR

mkfs.ext3 /dev/DEVICE

Where,

  • -t filetype : Is a File system kind, it can be ext3, ext2, vfat, etc
  • /dev/DEVICE : The name of your device i.e. partition /dev/hda1 or /dev/sda1 etc.

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

Step 1 : make a new file system using the following commands:

# mkfs.ext3 /dev/sda5

Output:

mke2fs 1.35

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 fragment per group

2008 inodes per group

Superblock backups stored on the blocks:

8193, 24577, 40961, 57345, 73729

Writing inode tables: done

Creating journal (4096 blocks): done

Writing file system and superblocks accounting information: done

This file system will be checked automatically after every

180 days or 38 mounts, whichever comes first. Use tune2fs -c or -i to override.

Step 2: Make a mount point directory for the filesystem

# mkdir /datadisk1

Step 3: Mount the new filesystem

# mount /dev/sda5 /datadisk1

Step 4: Lastly ensure file system /dev/hda5 mounted automatically at /datadisk1 mount point after the system reboots. You require to add a partition to /etc/fstab file. Use a text editor such as vi to add the following entry

# vi /etc/fstab

Add/append following entry to file:

/dev/sda5 /datadisk1 ext3 defaults 0 2

Where,

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

Save the file and exit to the shell prompt.