14

Using Mac OS X 10.4

I made a script a while ago for my Linux box in order to take archived data off of 300 floppies that automated the process. I would make an image of the floppy and copy the files directly off of the floppy. I managed to install Xcode on the machine (in order to install ddrescue)

The thing is on a Linux box I mounted each floppy to /media/floppy and unmounted it to ddrescue it and copied it directly to a usb drive.

I'm trying to port my script to the Mac, and it seems that its default behavior is to automatically mount each zip floppy to the /Volumes folder, which is fine, except it uses the volume's name as its mount point folder name. So if a floppy's volume name is: "Jimmy Bo Bobs" it will mount to /media/Jimmy /Bo /Bobs.

So my question is I need to get the volume name either consistent to one name, or adaptable to the volume's name.

So my initial question is can I some how mount a drive to a specific folder, Like I would normally do in linux?

 #Linux
 mount /dev/sd1 /media/floppy
 #Mac
 diskutil mount /dev/disk1s1 /media/floppy #Doesn't work

If it's not possible, is there an easy way to extract the volume's name so that I can then link the script like this?

 Volumename=Jimmy Bo Bobs
 do stuff to /Volume/$Volumename

I'm guessing if it's not possible I'll have to grep the mount command to the /dev/ pointer and then somehow parse that string which is what I want to avoid since it would require even more research.

6
  • Have You checked [-mountPoint path] option for diskutil ? Sep 30, 2014 at 8:47
  • The help file and man don't make a mention of it, will look through google...
    – Mallow
    Sep 30, 2014 at 8:51
  • here's my man: "mount [readOnly] [-mountPoint path] device Mount a single volume. If readOnly is specified, then the file system is mounted read-only, even if the volume's underlying file system and/or device and/or media supports writing; even the super-user may not write to it; this is the same as the rdonly option to mount (8). If a -mountPoint is specified, then that path, rather than the stan- dard path of /Volumes/VolumeName, will be used as the view into the volume file content; a directory at that path must already exist." Sep 30, 2014 at 8:52
  • Hmmm... I see the man online, and your man, and they don't match mine. I tried both sudo diskutil mount /dev/disk2s4 -mountPoint /Volumes/test and sudo diskutil mount -mountPoint /Volumes/test /dev/disk2s4 ... I suspect 10.4 doesn't have the -mountPoint feature.
    – Mallow
    Sep 30, 2014 at 8:56
  • Does /Volumes/test exist before running this command? Sep 30, 2014 at 9:02

3 Answers 3

10

Yes, you can mount a drive to a specific folder. 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
4
  • SUCCESS!!! mount -t hfs /dev/disk1s4 ~/mountpoint/
    – Mallow
    Oct 1, 2014 at 2:57
  • 1
    any way for this to happen automatically whenever I connect the same drive?
    – rmp251
    Sep 3, 2016 at 20:52
  • @rmp251, I don't think there's any way to automate this. That said, you may be able to create a script that you could run that would mount the drive with nothing more than a double-click. Assuming that you are mounting only one drive regularly, it should get the same device name every time you mount it. Sep 6, 2016 at 4:48
  • @rmp251 After you've mounted volumes, you can automate the mounts at login by dragging the mounted volumes into your Login Items within the Users & Groups / Accounts panel in System Preferences. Apr 5, 2019 at 0:01
4

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.

1

Script:

#!/bin/bash

# This is the name of the Drive as you'd see it in the finder
volname=<Volume Name>

# Mount point you want to mount it to.
mountPoint=/Users/<username>/extra


function remount() {
  sudo diskutil unmount "$vol"
  sudo diskutil mount -mountpoint "$mountPoint" "$vol"
  exit 0
}
vol=$(diskutil list | grep "$volname" | awk '{print $7}')
mount | grep "$vol" | grep "/Volumes/$volname" > /dev/null && remount

What I do is just add a cron that runs every minute. There is very little system resources for when there isn't anything to do so just run it every minute. If it finds it, it re-maps it to the proper location.

* * * * * <location of script> > /dev/null 2>&1

You must log in to answer this question.

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