谢谢你提供的详情。AutoFS 和 Udev 是研究解决我这个问题的正确方法。
此外,blkid
即使没有挂载,该命令也会正确显示块设备列表。以此推断,这是一个(容易出错的)基本脚本,用于处理不依赖 AutoFS 和 Udev 的挂载块设备(只是一个临时解决方案):
#!/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";
}