Apple - Is there a way to mount a disk directly to a specific folder?
"So my initial question is can I some how mount a drive to a specific folder, Like I would normally do in linux?"
Absolutely. The caveat is that the user who is mounting the volume must be the mount-point owner. You do NOT need to be root or use sudo to mount a disk.
The first thing is to identify your raw device. diskutil list
will do that nicely.
For example, if I have a FAT32 USB stick that I want to mount in my home dir, I list my devices and see that my raw device is /dev/disk5s1. As a normal user, I can mount it in my home directory by:
mkdir ~/mount
mount -r -t msdos /dev/disk5s1 ~/mount
If you then cd ~/mount ; ls
, you'll see the contents of the USB stick.
In this example, I mounted it read-only, but you can mount your device any way you like.
When you're done with the device, don't forget to unmount it, e.g.:
diskutil unmount ~/mount
This is described in comments, but it ought to be put into an answer. In MacOS 10.11.6 (and probably later versions), you can use
diskutil mount -mountPoint ~/mount /dev/disk5s1
Unlike using mount
, it's not necessary to specify the filesystem type, at least for hfs
type disks (all that I have tried).
I found that I had to sudo
to root to do this either using mount
as in @TraneFranks' answer, or with diskutil mount
as above, even though I own the mount point directory. I don't understand why sudo
is needed. Using diskutil mount
without -mountPoint
, the disk is mounted in a default location in /Volumes, and I don't need to be root. However, I recommend keeping in mind that sudo
might be needed, because the error message without it is mysterious.