我正在尝试找出一种方法,以便在挂载特定的远程文件系统(如cifs或nfs )以及将要卸载它时运行脚本。我的fstab中有条目,所以在我的桌面上会自动创建挂载图标。但是我需要在挂载某个特定的远程文件系统时挂载覆盖文件系统,并在卸载远程文件系统之前将其卸载。在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"那有什么我可以用的吗?谢谢
发布于 2014-05-31 17:50:18
您没有提到编程语言,所以我将继续使用pyudev,它是udev的python包装器。
它提供了一种简单的方法来监视udev发出的事件并对其做出反应。以下是他们的文档中的示例:
每当添加、移除设备(例如,插入或拔出U盘)或更改其属性(例如,电池充电水平更改)时,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 MULTIBOOThttps://stackoverflow.com/questions/23968130
复制相似问题