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?
4 Answers
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.
-
1It seems that
mkfs.ext4
actually runsmke2fs
. If I run the man page:man mkfs.ext4
it shows me themke2fs
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 tomke2fs
. It might be a hard link in some other distributions, or a wrapper script. But if you removemkfs.ext4
leaving onlymke2fs
, thenmkfs -t ext4
stops working because it specifically looks formkfs.<value_of_-t_option>
.– telcoMApr 28 at 11:25 -
3@telcoM @EdgarMagallon that is common practice (see
xz
,mtools
orbusybox
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 formke2fs
. 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
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.
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
.
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