Posted by & filed under Linux.

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";
}

Thomas Hunter II

Thomas is passionate about technology and building products. A web design business created while attending college slowly evolved into a brick and mortar on Main St. of his small Midwestern hometown. His desire for fame and fortune led to the co-founding of a Y Combinator startup and a life in California.

Tags:

Hey there! I'm currently writing a book on Microservices which I expect to release in early 2017. If you're interested in getting updates please signup here. More info about the Book
  • Are you crazy? :)
    PHP? why not shell script?

    • PHP was my go to language at the time. Personally, I can’t stand writing bash.