11

Is there a difference between sudo mkfs -t ext4 /dev/sdb and sudo mkfs.ext4 /dev/sdb?
Or is the latter just an alias of the former?

0

4 Answers 4

16

mkfs -t ext4 /dev/sdb first runs the generic [/usr]/sbin/mkfs command, which is a wrapper that will select the correct filesystem-specific mkfs binary (in this case, the [/usr]/sbin/mkfs.ext4) according to the value of the -t option, and will pass the rest of the command line to it.

mkfs.ext4 /dev/sdb simply skips the wrapper and calls the filesystem-specific binary directly.

From the mkfs(8) man page:

In actuality, mkfs is simply a front-end for the various filesystem builders (mkfs.fstype) available under Linux. The filesystem-specific builder is searched for via your PATH environment setting only. Please see the filesystem-specific builder manual pages for further details.

4
  • 1
    It seems that mkfs.ext4 actually runs mke2fs. If I run the man page: man mkfs.ext4 it shows me the mke2fs man page and says: If mke2fs is run as mkfs.XXX (i.e., mkfs.ext2, mkfs.ext3, or mkfs.ext4) the option -t XXX is implied; ... Apr 28 at 9:58
  • 1
    @EdgarMagallon You're correct. At least on my system, mkfs.ext4 is a symbolic link to mke2fs. It might be a hard link in some other distributions, or a wrapper script. But if you remove mkfs.ext4 leaving only mke2fs, then mkfs -t ext4 stops working because it specifically looks for mkfs.<value_of_-t_option>.
    – telcoM
    Apr 28 at 11:25
  • 3
    @telcoM @EdgarMagallon that is common practice (see xz, mtools or busybox for example). The program finds out the name it's been called by and sets the internal behaviour accordingly. See these source lines, where it happens for mke2fs. Apr 28 at 12:51
  • telcoM Oh, that's true, in my case it is a hard link (I hadn't noticed that). @EduardoTrápani that makes sense now, I was thinking that mke2fs was another different tool. Apr 28 at 20:39
10

Since mkfs -t xyz just runs mkfs.xyz you are running two programs instead of one.

Anyway, mkfs should no longer be used. From the manpage:

The mkfs frontend is deprecated in favour of filesystem specific mkfs.<type> utils.

3

Citing the documentation man mkfs:

In actuality, mkfs is simply a front-end for the various file system builders (mkfs.fstype) available under Linux. ...

So I expect that mkfs -t ext4 will call mkfs.ext4.

-3

The mkfs.ext4 command is a specific command for creating ext4 filesystems, and it is essentially equivalent to mkfs -t ext4. It is provided as a convenience to make it easier to create ext4 filesystems without having to specify the -t option each time.

1
  • 1
    actually mkfs -t ext4 is the one that's supposedly convenient
    – user253751
    Apr 28 at 17:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .