首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >装载远程文件系统-装载后脚本和卸载前脚本(linux)

装载远程文件系统-装载后脚本和卸载前脚本(linux)
EN

Stack Overflow用户
提问于 2014-05-31 16:44:02
回答 1查看 604关注 0票数 0

我正在尝试找出一种方法,以便在挂载特定的远程文件系统(如cifs或nfs )以及将要卸载它时运行脚本。我的fstab中有条目,所以在我的桌面上会自动创建挂载图标。但是我需要在挂载某个特定的远程文件系统时挂载覆盖文件系统,并在卸载远程文件系统之前将其卸载。在udev监视器中,我看到了添加/删除通知,但属性非常无用:

代码语言:javascript
复制
~$ udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[41113.912505] add      /devices/virtual/bdi/cifs-2 (bdi)
UDEV  [41113.913868] add      /devices/virtual/bdi/cifs-2 (bdi)
^

~$ udevadm info -a -p /devices/virtual/bdi/cifs-2

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/virtual/bdi/cifs-2':
    KERNEL=="cifs-2"
    SUBSYSTEM=="bdi"
    DRIVER==""
    ATTR{min_ratio}=="0"
    ATTR{stable_pages_required}=="0"
    ATTR{read_ahead_kb}=="1024"
    ATTR{max_ratio}=="100"

那有什么我可以用的吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2014-05-31 17:50:18

您没有提到编程语言,所以我将继续使用pyudev,它是udev的python包装器。

它提供了一种简单的方法来监视udev发出的事件并对其做出反应。以下是他们的文档中的示例:

每当添加、移除设备(例如,插入或拔出U盘)或更改其属性(例如,电池充电水平更改)时,Linux内核都会发出事件。使用pyudev.Monitor,您可以对此类事件做出反应,例如,对添加或删除的可挂载文件系统做出反应:

代码语言:javascript
复制
>>> monitor = pyudev.Monitor.from_netlink(context)
>>> monitor.filter_by('block')
>>> for device in iter(monitor.poll, None):
...     if 'ID_FS_TYPE' in device:
...         print('{0} partition {1}'.format(action, device.get('ID_FS_LABEL')))
...
add partition MULTIBOOT
remove partition MULTIBOOT
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23968130

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档