I was looking for a way to mount the EFI partition on macOS when I realized there was actually two commands to mount a partition:
diskutil mount. What is the difference between them? I couldn't find anything about their differences online.
mount() is actually a system call, that means it's a C function offered by the system library (
libSystem) to tell the system to mount a disk drive. It will talk to the operating system kernel and instruct it what to mount, where to mount it, as well as how to mount it.
The command line tool
mount is just simple binary around this function call. It parses your arguments and then feeds those into the system
mount() call, check the result of the operation and print an appropriate error message if it cannot parse your arguments or the mount operation failed for some reason. The presence of that tool is required by the POSIX standard and as macOS is a POSIX compliant system, it has to offer that command.
This command is also found on pretty much every UNIX system as well as on every Linux system, as that's how a user with shell access instructs the system to perform a mount call without having to write C code first and compile that code to a binary using a C compiler. Also that way you can perform mount operation from within shell scripts.
diskutil is another command provided by Apple for macOS and it's the command line version of the "Disk Utility" application. The UI version looks like this:
Of course, this application is also able to mount drives, so it also has a mount function which you can trigger by
diskutil mount (in the UI application you select a disk and then either choose the mount icon from the toolbar in the upper right corner or open the context menu and select "Mount").
As you can see on the man page of
diskutil, the mount call has far less options available (
readOnly and an optional
-mountPoint), which limits the ways how a volume can be mounted but usually the missing options are not required. Further some options are not required as
diskutil will automatically figure out the correct settings for you (whereas
mount is rather dumb and often requires you to specify additional settings to make it work correctly).
diskutil allows admin users (and sometimes even normal users) to mount volumes that otherwise require root privileges, that's why you typically have to use
mount but not with
diskutil (it won't allow malicious operations to begin with and as you cannot set any dangerous options, nothing can break either). For convenience and security reasons,
diskutil will always mount volumes to
/Volumes and to a directory named like the disk volume; you can mount a volume elsewhere with the
mountPoint option but then you do require root privileges (as that's potentially a dangerous operation).
mount requires to specify the mount source as disk device (something like
diskutil also allows you to specify a volume by its UUID (every volume has such a unique ID which looks like this
3717b1fa-e76b-11ec-9b88-7e3148d68d41), and even by volume name (e.g. "Macintosh HD"; if multiple volumes have that name, it picks the first one it finds).
So unless you have to use
mount for some reason (e.g. as you require a certain option) or want to write a portable shell script, you would usually always use
diskutil mount on macOS for mounting volumes. It's easier to use, provides better error messages, and won't require you to become root first. Only fall back to
mount if whatever you are trying to do is not possible with