How to check for a drive's existence in Debian Linux
I have a Debian Linux server with two eSATA drives attached to it (NTFS, bleh). They are currently mounted fine and have proper fstab entries s开发者_如何转开发etup (using UUID, not /dev locations).
I've come to the conclusion that I need to add 'noauto' mount options so that they aren't mounted when the server boots (to prevent the server from hanging when they aren't present. I do plan on taking them on an occasional excursion).
However, how should I setup an init script to mount them once the system has booted? I could do a mount /mount/location
, but I would prefer to check for their existence before doing that (to prevent an error from being thrown). Also, do I just need to throw this script into the /etc/init.d/
directory for it to work? (I'm fairly new to Debian)
blkid
shows a list of block devices.
Thanks for the information. AutoFS and Udev are the proper things to research to come up with a solution to this problem of mine.
Also, the blkid
command does properly show a list of block devices even if they are not mounted. Extrapolating on this, here's an (error prone) rudimentary script for handling mounting block devices which doesn't rely on AutoFS and Udev (just a temporary solution):
#!/usr/bin/env php
<?php
define('DRIVE1', '7E088E5B088E11F7');
define('DRIVE2', '4A841A75841A63AB');
$devices = `/sbin/blkid`;
if (strpos($devices, DRIVE1) !== FALSE) {
$output = `mount /storage/drive1`;
$output = trim($output);
echo "Mounting /storage/drive1... $output\n";
} else {
echo "Not Mounting: /storage/drive1\n";
}
if (strpos($devices, DRIVE2) !== FALSE) {
$output = `mount /storage/drive2`;
$output = trim($output);
echo "Mounting /storage/drive2... $output\n";
} else {
echo "Not Mounting: /storage/drive2\n";
}
精彩评论