Hack 66. Format a partition using mke2fsk

by Ramesh

After partitioning the disks, it is still not ready for usage, as we need to format the disk. At this stage, if you try to view the disk information, it will give the following error message indicating that no valid superblock is present.

  1. # tune2fs -l /dev/sda1
  2.  
  3. tune2fs 1.35 (28-Feb-2004)
  4. tune2fs: Bad magic number in super-block while trying to open /dev/sda1
  5.  
  6. Couldn't find valid filesystem superblock.

To format the disk, use mke2fs as shown below.

  1. # mke2fs /dev/sda1

You can also pass the following optional parameter to the mke2fs.

  • -m 0 : reserved-blocks-percentage – This indicates the percentage of the filesystem blocks reserved for the root user. Default is 5%. In the following example, it is set to 0.
  • -b 4096 : block-size specified in bytes. Valid values are 1024, 2048 and 4096 bytes per block.
  1. # mke2fs -m 0 -b 4096 /dev/sda1
  2.  
  3. mke2fs 1.35 (28-Feb-2004)
  4. Filesystem label=
  5. OS type: Linux
  6. Block size=4096 (log=2)
  7. Fragment size=4096 (log=2)
  8. 205344 inodes, 70069497 blocks
  9. 0 blocks (0.00%) reserved for the super user
  10. First data block=0
  11. Maximum filesystem blocks=71303168
  12. 2139 block groups
  13. 32768 blocks per group, 32768 fragments per group
  14. 96 inodes per group
  15. Superblock backups stored on blocks:
  16. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872
  17.  
  18. Writing inode tables: done
  19. Writing superblocks and filesystem accounting information: done
  20.  
  21. This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

The above command will create an ext2 filesystem. To create an ext3 file system do the following.

Create ext3 filesystem

  1. # mkfs.ext3 /dev/sda1
  2.  
  3. # mke2fs –j /dev/sda1