Auto Mount External Drives in Debian

Here’s an old script I came up with for delaying the mounting external drives (they were eSATA) to persistent locations on my Debian based server, regardless of the order in which the OS detects the drives. It uses the blkid identifiers of the drives, instead of the /dev drive locations (which can change each boot). You can runĀ sudo blkid to get a list of the blkid of mounted drives (e.g. manually mount it, get the id, edit the script).

This script requires PHP, and can be setup as an rc.d script. fstab will need to be aware of the disks. Since the mounting is done in a side process, the system won’t hang when it tries to mount the drives and they aren’t present.

There are better methods (read; less hacky) for automatically mounting devices. If you know them, please mention how in the comments below.

#!/usr/bin/env php
<?php
define('CHELSEY',       '30AC5B8EAC5B4E8A'); # Put blkid here
define('DELTA',         '4A841A75821A63AB'); # Put blkid here
$devices = `/sbin/blkid`;

if (strpos($devices, DELTA) !== FALSE) {
    $output = `mount /storage/delta`;
    $output = trim($output);
    echo "Mounting /storage/delta... $output\n";
} else {
    echo "Not Mounting: /storage/delta\n";
}

if (strpos($devices, CHELSEY) !== FALSE) {
    $output = `mount /storage/chelsey`;
    $output = trim($output);
    echo "Mounting /storage/chelsey... $output\n";
} else {
    echo "Not Mounting: /storage/chelsey\n";
}

2 Responses to “Auto Mount External Drives in Debian”

  1. Are you crazy? :)
    PHP? why not shell script?

    Reply

Comment

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>