Considering the output from the ls command:

$ ls -l /sbin/mkfs.ext4
lrwxrwxrwx 1 root root 6 Aug  4 00:10 /sbin/mkfs.ext4 -> mke2fs

$ type mkfs.ext4
mkfs.ext4 is hashed (/sbin/mkfs.ext4)

mkfs.ext4 is a symlink pointing to mke2fs command. Nothing strange, all good and fine. Therefore, running mkfs.ext4is the same as running mke2fs. Notice the curly bracket that I've added in the output of the commands below:

$ mke2fs
Usage: {mke2fs} [-c|-l filename] [-b block-size] [-C cluster-size]
$ mkfs.ext4
Usage: {mkfs.ext4} [-c|-l filename] [-b block-size] [-C cluster-size]

Obviously, mke2fs uses the name of the file to determine the appropriate filesystem type to make and even to customize its list of options:

$ ln -s /sbin/mke2fs mkmk

$ ls -l mkmk 
lrwxrwxrwx 1 direprobs direprobs 12 Aug  8 14:25 mkmk -> /sbin/mke2fs

$ ./mkmk
Usage: mkmk [-c|-l filename] [-b block-size] [-C cluster-size]

I manged to make an ext2 filesystem using mkmk, the symlink which I've made with ln. What does mkmk mean to mke2fs, it should be nothing!

How does mke2fs use filenames from which it's run to determine the filesystem type to make?


See the parse_fs_type function in mke2fs.c:

  • if a file system type is specified explicitly (using -t), use that
  • if the tool is running on the Hurd, use “ext2”;
  • if the program name is mke3fs, use “ext3”;
  • if the program name is mke4fs, use “ext4”;
  • if the program name starts with mkfs., use the suffix;
  • otherwise, use the default defined in /etc/mke2fs.conf, if any;
  • otherwise, use “ext2”, unless a journal is enabled by default, in which case use “ext3”.

The resulting text string is used to find a file system definition in /etc/mke2fs.conf (apart from “ext2” which is handled internally).

So your mkmk would end up using the ext2 file system type.

  • dear @Stephan , what "On the Hurd" means ? – Jonah Aug 8 '17 at 12:34
  • 1
    @youness it means if you’re using the Hurd, which is a kernel on which you can run the ext2 tools (but it only supports ext2). – Stephen Kitt Aug 8 '17 at 12:41
  • The -t option unconditionally sets the filesystem type, and with that option the only effect of any program name is to alter what name for the program is printed out in diagnostic messages as the program runs.
  • On the Hurd, ext2 is used as the filesystem type irrespective of the name that the program is invoked as, which again only affects diagnostic messages.
  • Otherwise the process' zeroth argument's base name is checked:
    • If invoked with mke3fs as the base name it will create an ext3 filesystem, with a journal as if -j had been specified.
    • If invoked with mke4fs as the base name it will create an ext4 filesystem.
    • If the basename begins with the 5 characters mkfs. it will use the remaining characters as the filesystem type, unconditionally. If the base name also happens to be mkfs.ext3 it creates a journal as if -j had been specified.
    • Otherwise, with any other name, it just acts as plain old mke2fs, taking the filesystem type from the configuration file and changing from ext2 to ext3 if the -j option is supplied.

Most of this can be found in the mke2fs and mke2fs.conf manuals. See the explanation of fs_type in the latter and the Description section of the former. The only part that is missing from the manuals is that an unrecognized name is effectively mke2fs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.