Mac: Mount ejected flash drive without reinserting
May 20, 2013 7:55 AM   Subscribe

I have a nifty little USB thumbdrive that I want to use to make backups of various documents; it will live on the powered hub in my office, as I'll only need to use it in the office. It's something of a pain to unplug and re-insert every day, or every time I need to leave the desk with my laptop. After ejecting, the drive is no loger visible using diskutil on the command line, tho I can see it in the system profiler. Is there a way to have the system recognize the device and mount it whenever the Macbook wakes from sleep? I've got sleepwatcher installed, but I'm not certain how to get the system to recognize the USB device without unplugging it and plugging it back in. Shutting down and restarting the mac every time I want to leave my desk with it is not a viable option, either. I'm running 10.7.5 on a Core i7 15" MBP.
posted by Slap*Happy to Computers & Internet (10 answers total) 1 user marked this as a favorite
 
If the USB stick is visible in the Profiler, the Mac has recognized the drive - it's just not mounted into the file system.

You can mount an attached but ejected drive without reinserting it by going into Applications -> Utilities -> Disk Utility, selecting the greyed-out drive from the menu on the left-hand side, and clicking the "Mount" button up top. You can also do this on the command line with diskinfo mountDisk /dev/diskX where X is the device ID of the USB drive.

You can write an Applescript script that will mount the drive after an action. An example of automatically mounting a drive for the purposes of backup is discussed here.
posted by eschatfische at 8:16 AM on May 20, 2013


Response by poster: No, it's invisible to diskutil, GUI and command line, but not the system profiler. It's weird.
posted by Slap*Happy at 9:10 AM on May 20, 2013


Escchatfische's answer sounds good. (on preview: oh, unless it doesn't work.) If you'd like an alternative workaround that's slightly easier but still not as elegant as what you're asking for, you could add a switched USB hub and flick it off/on whenever you want to do a backup. (This is sort of what I do - Carbon Copy Cloner is set to backup when the drive reappears. Flick the drive on, backup starts. Backup finishes, flick the drive off. I like it.)
posted by all-caps relapse at 9:12 AM on May 20, 2013


Evidently I'm still sleepy, as I must have missed the part where you said it's already plugged into a powered hub. :\
posted by all-caps relapse at 9:14 AM on May 20, 2013


Best answer: It is an ugly hack, but unloading and reloading the USB storage kernel extension will cause all USB storage to be re-recognized even if ejected instead of unmounted. The command line (in 10.8, tested on my machine) is:

sudo kextunload /System/Library/Extensions/IOUSBMassStorageClass.kext ; sudo kextload /System/Library/Extensions/IOUSBMassStorageClass.kext
posted by procrastination at 9:40 AM on May 20, 2013 [1 favorite]


Response by poster: procrastination: That works... thanks! Now I just need a way to get it to work with a sleepwatcher script.
posted by Slap*Happy at 9:55 AM on May 20, 2013


So, yeah, unlike USB hard drives and other devices, when a USB drive is unmounted from Finder, enough of the mount information is removed to make a clean remount not possible.

The first solution, which I just confirmed works, is to use the command-line version of Disk Utilities to unmount and remount the USB drive. After plugging in the USB drive:

1. Open Terminal.app to get to the command line
2. Run 'mount' to get a list of all mounted drive volumes. Look for the USB volume and note its device identifier (e.g. /dev/disk2s1). As long as the drive remains plugged in, this shouldn't change.
3. To unmount the drive, run: diskutil unmountDisk diskid (e.g. 'diskutil unmountDisk /dev/disk2s1')
3. To remount the drive: diskutil mountDisk diskid

Alternatively, if doing all this from the command-line is too daunting, there is apparently an app available that will allow you do it from a user-friendly interface: Mountain, though I haven't tried it out.

---
Solution gleaned from StackExchange.
posted by insert.witticism.here at 9:56 AM on May 20, 2013 [1 favorite]


ejecting and unmounting are two separate things. ejecting removes the device from OS X's device tree. it still shows up in System Profiler because it pings the actual hardware to figure out what's there or not; OS X (as do most other OSes; you can do this same thing on Linux or Windows) keeps a separate list of what hardware it knows/cares about internally. (this is somewhat simplified and maybe a little incorrect but it'll work for this question at least.) unmounting just disconnects the filesystem from the system. so, you want to just unmount.

if you're doing the copying and stuff with a shell script or an AppleScript, do up a bit in it to do "diskutil unmountDisk /dev/diskX" where diskX is whatever the flash drive is. if you're never removing it from the hub, the device name it gets should not change unless you reboot or it actually does get removed from the hub/computer (the hub gets turned off). if you're handy with command line utilities you could do up something more to have it figure out what device to use automatically too. if you just unmount, the drive will still be in the device tree and you can re-mount it fairly easily ("diskutil mountDisk" or through Disk Utility).

(on preview: you can use mount/umount too but the "OS X way" is to use diskutil. basically the same process though.)
posted by mrg at 9:57 AM on May 20, 2013


Response by poster: mrg: Sadly, unplugging the hub and then putting the Mac to sleep (or vice versa) effectively ejects the thumbdrive, even if you've unmounted it already using diskutil. I have a USB HDD that doesn't seem to have a problem mounting itself after waking - googling around, this issue is oddly restricted to flash thumbdrives.

As I only have the two USB drives, Procrastination's solution seems to be the answer.
posted by Slap*Happy at 10:28 AM on May 20, 2013


You could use Control Plane to detect when you wake from sleep at your office, and reload the kernel extension automatically.
posted by neckro23 at 10:43 AM on May 20, 2013 [1 favorite]


« Older How can I handle unnecessary guilt from coworkers?   |   Hurricane/cyclones : history, effects Newer »
This thread is closed to new comments.