如何在 Debian Linux 中检查驱动器是否存在

发布于 2024-11-13 11:06:40 字数 367 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场信仰旅途 2024-11-20 11:06:40

blkid 显示块设备列表。

blkid shows a list of block devices.

我的鱼塘能养鲲 2024-11-20 11:06:40

感谢您提供信息。 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";
}

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";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文