gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:58:12 24 4
gpt4 key购买 nike

我正在尝试找出一种在安装特定远程文件系统(如 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"

那我可以用什么东西代替吗?谢谢

最佳答案

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

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

The Linux kernel emits events whenever devices are added, removed (e.g. a USB stick was plugged or unplugged) or have their attributes changed (e.g. the charge level of the battery changed). With pyudev.Monitor you can react on such events, for example to react on added or removed mountable filesystems:

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

关于linux - 挂载远程文件系统 - 挂载后和卸载前脚本 (linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23968130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com