Howtos - Automount a USB MSD

Contents

Overview

ClarkConnect 4.x uses devfs (as opposed to the successor, udev). As such, Autofs should be used to automatically mount USB mass storage devices attached to your ClarkConnect server.

The following "How-to" describes how to detect your device and configure Autofs to automatically mount (and unmount during periods of inactivity) the file-system.

Device Detection

Device detection is not currently available through webconfig. Since you're going to be editing files for autofs at the command line, the easiest way to determine the device assignment of your USB drive is to use the script provide below.

  • Plug your USB mass storage device into your ClarkConnext server.
  • Copy the script below to a temporary file on your ClarkConnect server...for example: /tmp/find_devices.php.


#!/usr/webconfig/bin/php -q
<?
///////////////////////////////////////////////////////////////////////////////
//
// Copyright 2008 Point Clark Networks
//
///////////////////////////////////////////////////////////////////////////////
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
///////////////////////////////////////////////////////////////////////////////

require_once("/var/webconfig/api/StorageDevice.class.php");

$sd = new StorageDevice();
$devices = $sd->GetDevices(false);
if (count($devices) > 0) {
        echo "The following devices were found:\n";
} else {
        echo "No devices were found.\n";
        exit;
}
foreach ($devices as $dev => $device) {
        echo "\t$dev\t" . $device['vendor'] . ' ' . $device['model'] . "\n";
}
?>
  • Make the file executable:
chmod 755 /tmp/find_devices.php
  • Run the script
/tmp/find_devices.php


You will get an output something like the following:

The following devices were found:
        /dev/scd0       Iomega RRD2
  • The example above shows a USB Iomega REV drive (just a 'fancy' USB MSD) was found at /dev/scd0.

Device Format (Optional)

Most USB devices will, by default, have a file system intended for use with Microsoft Windows computers. You can format the device and create an ext3 file system for use with Linux by doing the following:

mkfs.ext3 /dev/scd0


Where /dev/scd0 would differ, depending on the output you got from the device.

Warning 
  Running the above command will permanently delete all data on your USB drive.  
 


Install AutoFS

Run the following commands to install autofs (it may already be installed, in which case, the following commands are harmless).

apt-get update
apt-get install autofs

Create an AutoFS Configuration

Edit the file:

/etc/auto.master


using an editor of your choice (vi, nano, SCP etc.).

Add the following line:

/var/autofs/usb      /etc/auto.mymount        --timeout=30


You can change the timeout value to whatever you want. The 30 in the above example indicates the device will automatically be un-mounted after 30 seconds of inactivity. The device will automatically be mounted again when next accessed.

Save the file and exit the editor.

Next, create the file /etc/auto.mymount, and change the default file permissions.

touch /etc/auto.mymount
chmod 640 /etc/auto.mymount


Add the following line, changing the label IomegaRRD2 to something appropriate to your device (i.e. SeagateUSB) and the text /dev/scd0 to the value you obtained when running the device location script.

IomegaRRD2      -fstype=auto    :/dev/scd0


Once you have completed editing and saved the file, restart AutoFS:

/etc/rc.d/autofs restart

Creating a Convenient Mount Point

It us usually convenient to create a sym link back to the mount point where AutoFS mounts the device. This allows the link to exist permanently, even when the device is not plugged in. Run the following command:

ln -s /mnt/usb /var/autofs/usb/IomegaRRD2


Note, the path /var/autofs/usb and the device nickname (IomegaRRD2) may differ, depending on what path you used in the creation of the /etc/auto.master file and the nickname you gave your device in the file /etc/auto.mymount.

Testing

If all goes well, you should be able to change directory (cd) to the sym-linked mount point and do an 'ls' to see the contents of the file system.

cd /mnt/usb
ls -l
[root@clarkconnect usb]# ls -l
total 16
drwx------  2 root root 16384 Feb  4 11:57 lost+found

Links

Retrieved from "http://wiki.clarkconnect.com/docs/Howtos_-_Automount_a_USB_MSD"

This page has been accessed 3,089 times. This page was last modified on 4 February 2008, at 17:59.