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?

Nepumuk
  • 659
  • 7
  • 29

4 Answers4

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.

telcoM
  • 87,318
  • 3
  • 112
  • 232
  • 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; ...* – Edgar Magallon Apr 28 '23 at 09: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.`. – telcoM Apr 28 '23 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](https://github.com/tytso/e2fsprogs/blob/master/misc/mke2fs.c#L1343), where it happens for `mke2fs`. – Eduardo Trápani Apr 28 '23 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. – Edgar Magallon Apr 28 '23 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.

Peter Cordes
  • 6,328
  • 22
  • 41
Eduardo Trápani
  • 12,032
  • 1
  • 18
  • 35
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.

Bodo
  • 5,979
  • 16
  • 27
-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.