我正在尝试运行udiskie
andudisks2
来udisksctl
安装没有 root 权限的 SD 卡。系统是 Debian、仅限 CL、无头:
$ udiskie-mount /dev/mmcblk0p1 --verbose
DEBUG [2023-04-04 00:35:15,374] udiskie.config: Failed to read config file: [Errno 2] No such file or directory: '/home/pi/.config/udiskie/config.yml'
DEBUG [2023-04-04 00:35:15,386] udiskie.config: Failed to read config file: [Errno 2] No such file or directory: '/home/pi/.config/udiskie/config.json'
DEBUG [2023-04-04 00:35:15,411] udiskie.udisks2: Daemon version: 2.9.2
DEBUG [2023-04-04 00:35:15,412] udiskie.udisks2: Keyfile support: True
DEBUG [2023-04-04 00:35:15,683] udiskie.config: new rule: {symlinks=/dev/mapper/docker-*} -> {ignore}
DEBUG [2023-04-04 00:35:15,683] udiskie.config: new rule: {symlinks=/dev/disk/by-id/dm-name-docker-*} -> {ignore}
DEBUG [2023-04-04 00:35:15,684] udiskie.config: new rule: {is_loop, !is_ignored, loop_file=/*} -> {!ignore}
DEBUG [2023-04-04 00:35:15,684] udiskie.config: new rule: {!is_block} -> {ignore}
DEBUG [2023-04-04 00:35:15,685] udiskie.config: new rule: {!is_external, is_toplevel} -> {ignore}
DEBUG [2023-04-04 00:35:15,685] udiskie.config: new rule: {is_ignored} -> {ignore}
DEBUG [2023-04-04 00:35:15,693] udiskie.udisks2: found device owning "/dev/mmcblk0p1": "/org/freedesktop/UDisks2/block_devices/mmcblk0p1"
DEBUG [2023-04-04 00:35:15,696] udiskie.mount: mounting /org/freedesktop/UDisks2/block_devices/mmcblk0p1 with {'options': None}
ERROR [2023-04-04 00:35:15,757] udiskie.mount: failed to mount /org/freedesktop/UDisks2/block_devices/mmcblk0p1: GDBus.Error:org.freedesktop.UDisks2.Error.NotAuthorizedCanObtain: Not authorized to perform operation
DEBUG [2023-04-04 00:35:15,759] udiskie.mount: Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/udiskie/mount.py", line 27, in wrapper
return await fn(self, device, *args, **kwargs)
File "/usr/lib/python3/dist-packages/udiskie/mount.py", line 165, in mount
mount_path = await device.mount(**kwargs)
File "/usr/lib/python3/dist-packages/udiskie/dbus.py", line 183, in call
result = await proxy.call(method_name, signature, *args)
File "/usr/lib/python3/dist-packages/udiskie/dbus.py", line 49, in call
value = proxy.call_finish(result)
gi.repository.GLib.GError: g-io-error-quark: GDBus.Error:org.freedesktop.UDisks2.Error.NotAuthorizedCanObtain: Not authorized to perform operation (36)
根据他们的文档,我需要一些 polkit 的东西:https://github.com/coldfix/udiskie/wiki/Permissions
所以我创建了该文件:
$ cat /etc/polkit-1/rules.d/50-udiskie.rules
polkit.addRule(function(action, subject) {
var YES = polkit.Result.YES;
var permission = {
// required for udisks1:
"org.freedesktop.udisks.filesystem-mount": YES,
"org.freedesktop.udisks.luks-unlock": YES,
"org.freedesktop.udisks.drive-eject": YES,
"org.freedesktop.udisks.drive-detach": YES,
// required for udisks2:
"org.freedesktop.udisks2.filesystem-mount": YES,
"org.freedesktop.udisks2.encrypted-unlock": YES,
"org.freedesktop.udisks2.eject-media": YES,
"org.freedesktop.udisks2.power-off-drive": YES,
// required for udisks2 if using udiskie from another seat (e.g. systemd):
"org.freedesktop.udisks2.filesystem-mount-other-seat": YES,
"org.freedesktop.udisks2.filesystem-unmount-others": YES,
"org.freedesktop.udisks2.encrypted-unlock-other-seat": YES,
"org.freedesktop.udisks2.encrypted-unlock-system": YES,
"org.freedesktop.udisks2.eject-media-other-seat": YES,
"org.freedesktop.udisks2.power-off-drive-other-seat": YES
};
if (subject.isInGroup("plugdev")) {
return permission[action.id];
}
});
算我一个plugdev
:
$ groups
pi adm dialout cdrom sudo audio dip video plugdev staff systemd-journal bluetooth netdev pulse-access
为什么我会收到此NotAuthorizedCanObtain
错误,如何修复此错误?