Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Mount and unmount FireWire drives via shell script Storage Devices
I run a couple of different backups to FireWire drives during the night, but I don't want to see the FireWire drives during the day, since they clutter my desktop and slow down Open/Save dialogs. So I created the following two scripts to automatically mount and unmount all FireWire drives, then scheduled them to run at the right times: The mount script, which I named mntfw:
#!/bin/bash
system_profiler SPFireWireDataType | grep "BSD Name: disk.$" | \
sed "s/^.*: //" | (while read i; do /usr/sbin/diskutil mountDisk $i; done)
The unmount script, which I named nofw:
#!/bin/bash
system_profiler SPFireWireDataType | grep "BSD Name: disk.$" | \
sed "s/^.*: //" | (while read i; do /usr/sbin/diskutil unmountDisk $i; done)
Save these somewhere (make sure to use Unix line endings), then mark them as executable with chmod a+x mntfw nofw, and you can easily run them from the Terminal.

[robg adds: These worked as described when I tested them.]
    •    
  • Currently 2.71 / 5
  You rated: 5 / 5 (7 votes cast)
 
[32,003 views]  

Mount and unmount FireWire drives via shell script | 9 comments | Create New Account
Click here to return to the 'Mount and unmount FireWire drives via shell script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Mount and unmount FireWire drives via shell script
Authored by: FOOOD on Jul 12, '07 09:25:03AM

This great, really handy. I have exactly the same problem & this works a treat.

How would we do this with external USB drives? Any chance of posting the code for that?



[ Reply to This | # ]
Mount and unmount FireWire drives via shell script
Authored by: hamarkus on Jul 12, '07 11:31:23AM

Googling 'SPFireWireDataType' quickly brings up 'SPUSBDataType'. Just replace the former with the latter and you should be good to go.



[ Reply to This | # ]
Mount and unmount FireWire drives via shell script
Authored by: FOOOD on Jul 13, '07 12:31:34AM

Thanks a lot, that works.



[ Reply to This | # ]
Mount and unmount FireWire drives via shell script
Authored by: leono on Jul 13, '07 06:49:10AM

If you're going to schedule these via cron, you'll probably need to stick "/usr/sbin/" in front of system_profiler. It doesn't seem to be in the path when cron runs.



[ Reply to This | # ]
Mount and unmount FireWire drives via shell script
Authored by: randyharris on Jul 13, '07 09:56:04PM

Can somebody help me change this a little bit, I would like to specify one of my FW drives to mount and unmount, not all of them.

Thanks much



[ Reply to This | # ]
Mount and unmount FireWire drives via shell script
Authored by: hints_hinterton on Feb 08, '08 10:16:44PM

It's been awhile but these modifications worked for me to specify the drive:

mount
#!/bin/bash
system_profiler SPFireWireDataType | grep -A4 "<yourdrivename>" | \
grep "BSD Name: disk" | sed -e "s/^.*: //" | \
(while read i; do /usr/sbin/diskutil mountDisk $i; done)

unmount
#!/bin/bash
system_profiler SPFireWireDataType | grep -B1 "Mount Point: \/Volumes\<yourdrivename>" | \
grep "BSD Name: disk" | sed -e "s/^.*: //" | \
(while read i; do /usr/sbin/diskutil unmountDisk $i; done)



[ Reply to This | # ]
Control mounting via FSTAB
Authored by: alset on Jul 16, '07 08:49:22AM
I wrote this as a reminder to myself when I learned how to configure FSTAB to prevent my backup drives from mounting on each login. I figured it would be relevant here.

Editing fstab research and success.

Disambiguation:

The Universally Unique ID is a 16 character alphanumeric string identifying a disk, hereafter seen as FFFF.
vi requires pressing "i" to enter Input Mode, "esc" to return to Command Mode
vi uses additional controls to write files: :w = write; :q = quit vi; :q! = quit without saving


Steps:
1. Obtain UUID of device
2. Write and save fstab file in /etc/
3. Reboot.


Step 1: obtaining the UUID
There are two methods I have learned to obtain the UUID of a device:

1. Connect the device while monitoring the System Logs in Console.
2a. From the command line, run diskutil list to get the slice number of the volume (disk#s#)
2b. From the command line, run diskutil info deviceid.


Step 2: Creating the fstab file
Create the fstab file in /private/etc/ using vi with root privileges (can't save w/out root)

sudo vi /private/etc/fstab

enter the following:

UUID=FFFF /mount-point device-type options


Disambiguation:

The mount-point is the location where the drive should appear (I chose /Volumes).
The device-type will be hfs for Mac drives, other for windrives, etc.
The options field is comma separated; rw = Read / Write; noauto = No auto-mount

So, the final text entry was:
UUID=FFFF /Volumes hfs rw,noauto

A real world example might look like this:
UUID=138AAB6E-3D84-3754-8FBF-ECC91BB9940F none hfs rw,noauto 0 0


Step 3: Reboot and test.


Further Notes:

When formatting the order of the string in the fstab file I combined examples found in two sources:
1. fstab man page
2. Comments following this hint: http://www.macosxhints.com/article.php?story=20030227194830916

After rebooting the drive does not auto mount, but can be seen in Disk Utility. Disconnecting the FW cable and reconnecting shows the volume become unavailable in Disk Utility and then available, again without mounting.

It has been my experience that SuperDuper! will find the drive and mount them for scheduled backup without issue. I have not tested this hint with Carbon Copy Cloner or other backup apps. YMMV.

---
standing on the shoulders of giants

[ Reply to This | # ]

Control mounting via FSTAB
Authored by: agnaL on Dec 11, '07 01:04:03AM

It seems that using /etc/fstab to mount firewire drives using UUIDs does not work anymore in Leopard (10.5). I used it on Tiger to mount external firewire drives at boot time, but now on Leopard it's broken (or not supported anymore).

One workaround could be to install the above shell script as a startup item. I'm going to give this a shot.

Is system_profiler able to display info for USB drives too?



[ Reply to This | # ]
Control mounting via FSTAB
Authored by: agnaL on Jan 04, '08 03:10:54PM

Yes the script is also able to mount USB drives. Just replace
SPFireWireDataType with SPUSBDataType.

There is one drawback to using this script over the previously working /etc/fstab entry on OSX 10.4 Tiger: On OSX 10.5 Leopard the Finder seems to unmount these drives during logout.

Does anyone know a way to prevent the Finder from ejecting the drives?



[ Reply to This | # ]