如何在 Debian Linux 中检查驱动器是否存在
我有一个 Debian Linux 服务器,连接了两个 eSATA 驱动器(NTFS,bleh)。它们目前安装良好,并具有正确的 fstab 条目设置(使用 UUID,而不是 /dev 位置)。
我得出的结论是,我需要添加“noauto”安装选项,以便在服务器启动时不会安装它们(以防止服务器在它们不存在时挂起。我确实计划将它们放在一个偶尔出差)。
但是,我应该如何设置一个初始化脚本来在系统启动后安装它们?我可以执行 mount /mount/location
,但我更愿意在执行此操作之前检查它们是否存在(以防止引发错误)。另外,我是否只需将此脚本放入 /etc/init.d/
目录中即可正常工作? (我对 Debian 还很陌生)
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 setup (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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
感谢您提供信息。 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";
}
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
blkid
显示块设备列表。blkid
shows a list of block devices.