繁体   English   中英

挂载远程fs-挂载后和卸载前脚本(Linux)

[英]Mounting remote fs - post mount and pre unmount scripts (linux)

我正在尝试找出一种方法,用于在挂载诸如cifs或nfs的特定远程fs以及即将被挂载时运行脚本。 我的fstab中有条目,因此会在桌面上自动创建安装图标。 但是我需要在安装某些特定的远程fs时安装覆盖fs,并在卸载远程fs之前先将其卸载。 使用udev监视器,我可以看到添加/删除通知,但是属性几乎没有用:

~$ 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"

那有什么我可以代替的吗? 谢谢

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

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

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

>>> 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM