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