https://wiki.archlinux.org/api.php?action=feedcontributions&user=Samovar123&feedformat=atomArchWiki - User contributions [en]2024-03-29T15:08:22ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Udisks&diff=575183Udisks2019-06-11T16:36:36Z<p>Samovar123: Output gives serial number with underscore but if you will use ID_BLA_BLA.conf instead of ID-BLA-BLA.conf Udisks2 will ignore that config.</p>
<hr />
<div>[[Category:Hardware detection and troubleshooting]]<br />
[[fr:Gestion de volumes avec udisks]]<br />
[[it:Execute on USB insert]]<br />
[[ja:Udisks]]<br />
[[ru:Udisks]]<br />
[[zh-hans:Udisks]]<br />
{{Related articles start}}<br />
{{Related|udev}}<br />
{{Related|Mount}}<br />
{{Related|Polkit}}<br />
{{Related|File manager functionality}}<br />
{{Related articles end}}<br />
[http://www.freedesktop.org/wiki/Software/udisks/ udisks] provides a daemon ''udisksd'', that implements D-Bus interfaces used to query and manipulate storage devices, and a command-line tool ''udisksctl'', used to query and use the daemon.<br />
<br />
== Installation ==<br />
<br />
There are two versions of ''udisks'' called {{AUR|udisks}} and {{Pkg|udisks2}}. Development of '''udisks''' has ceased in favor of '''udisks2'''. [http://davidz25.blogspot.be/2012/03/simpler-faster-better.html]<br />
<br />
{{man|8|udisksd}} (for '''udisks2''') and {{ic|udisks-daemon}} (for '''udisks''') are started on-demand by [[D-Bus]], and should not be enabled explicitly. They can be controlled through the command-line with {{man|1|udisksctl}} and {{man|1|udisks|url=}}, respectively.<br />
<br />
== Configuration ==<br />
<br />
Actions a user can perform using udisks are restricted with [[Polkit]]. If the [[session|user session]] is not activated or present (for example, when controlling udisks from a [[systemd/User]] service), adjust Polkit rules accordingly.<br />
<br />
See [https://github.com/coldfix/udiskie/wiki/Permissions] for common udisks permissions for the {{ic|storage}} group, and [https://gist.github.com/grawity/3886114#file-udisks2-allow-mount-internal-js] for a more restrictive example. If you are using [[Dolphin]], you may see [https://gist.github.com/Scrumplex/8f528c1f63b5f4bfabe14b0804adaba7].<br />
<br />
== Usage ==<br />
<br />
To manually mount a removable drive, for example {{ic|/dev/sdc}}:<br />
<br />
$ udisksctl mount -b /dev/sdc1<br />
<br />
To unmount:<br />
<br />
$ udisksctl unmount -b /dev/sdc1<br />
<br />
See {{ic|udisksctl --help}} for more.<br />
<br />
== Tips and tricks ==<br />
<br />
=== Mount helpers ===<br />
<br />
The automatic mounting of devices is easily achieved with udisks wrappers. See also [[List of applications/Utilities#Mount tools]].<br />
<br />
{{Note|[[Desktop environment]]s, such as [[GNOME]] and [[KDE]] may also provide a udisk wrapper.}}<br />
<br />
* {{App|bashmount|A bash script to mount and manage removable media as a regular user with ''udisks2''.|https://github.com/jamielinux/bashmount|{{AUR|bashmount}}}}<br />
* {{App|udiskie| ''udisks2'' automounter with optional notifications, tray icon and support for password protected [[Dm-crypt/Device_encryption|LUKS devices]]. See the [https://github.com/coldfix/udiskie/wiki/Usage udiskie wiki] for details|https://github.com/coldfix/udiskie|{{Pkg|udiskie}}}}<br />
* {{App|udisksvm|GUI ''udisks2'' wrapper written in Python3 and using the Qt5 framework. It uses mouse clicks to mount, unmount removable devices or eject a CD/DVD. See the [https://github.com/berbae/udisksvm/blob/master/README README] file for details.|3=https://github.com/berbae/udisksvm|4={{AUR|udisksvm}}}}<br />
* {{App|udevil|Includes [http://igurublog.wordpress.com/downloads/script-devmon devmon], which is compatible to ''udisks'' and ''udisks2''.|https://github.com/IgnorantGuru/udevil|{{Pkg|udevil}}}}<br />
<br />
{{Note|''devmon'' only uses ''udisks'' or ''udisks2'' for mounting (in this order) if ''udevil'' or ''pmount'' miss the SUID permission. To remove this permission, run {{ic|chmod -s /usr/bin/''udevil''}} as root.}}<br />
<br />
==== udevadm monitor====<br />
<br />
You may use {{ic|udevadm monitor}} to monitor block events and mount drives when a new block device is created. Stale mount points are automatically removed by ''udisksd'', such that no special action is required on deletion.<br />
<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
<br />
pathtoname() {<br />
udevadm info -p /sys/"$1" | awk -v FS== '/DEVNAME/ {print $2}'<br />
}<br />
<br />
stdbuf -oL -- udevadm monitor --udev -s block | while read -r -- _ _ event devpath _; do<br />
if [ "$event" = add ]; then<br />
devname=$(pathtoname "$devpath")<br />
udisksctl mount --block-device "$devname" --no-user-interaction<br />
fi<br />
done<br />
</nowiki>}}<br />
<br />
=== Mount to /media (udisks2) ===<br />
<br />
By default, udisks2 mounts removable drives under the ACL controlled directory {{ic|/run/media/$USER/}}. If you wish to mount to {{ic|/media}} instead, use this rule:<br />
<br />
{{hc|/etc/udev/rules.d/99-udisks2.rules|<nowiki><br />
# UDISKS_FILESYSTEM_SHARED<br />
# ==1: mount filesystem to a shared directory (/media/VolumeName)<br />
# ==0: mount filesystem to a private directory (/run/media/$USER/VolumeName)<br />
# See udisks(8)<br />
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{UDISKS_FILESYSTEM_SHARED}="1"<br />
</nowiki>}}<br />
<br />
Since {{ic|/media}}, unlike {{ic|/run}}, is not mounted by default as a [[tmpfs]], you may also wish to create a [[Systemd#Temporary_files|tmpfiles.d]] snippet to clean stale mountpoints at every boot:<br />
<br />
{{hc|/etc/tmpfiles.d/media.conf|<br />
D /media 0755 root root 0 -<br />
}}<br />
<br />
=== Mount loop devices ===<br />
<br />
To easily mount ISO images, use the following command:<br />
<br />
$ udisksctl loop-setup -r -f ''image.iso''<br />
<br />
This will create a loop device and show the ISO image ready to mount. Once unmounted, the loop device will be terminated by [[udev]].<br />
<br />
{{Note|This mounts a read only image. To mount raw disk images, such as for [[QEMU]], remove the {{ic|-r}} flag, and release the image after use with {{ic|udisksctl loop-delete -b ''/dev/loop0''}}. Substitute {{ic|/dev/loop0}} with the name of the loop device.}}<br />
<br />
=== Hide selected partitions ===<br />
<br />
If you wish to prevent certain partitions or drives appearing on the desktop, you can create a udev rule, for example {{ic|/etc/udev/rules.d/10-local.rules}}:<br />
<br />
KERNEL=="sda1", ENV{UDISKS_PRESENTATION_HIDE}="1"<br />
KERNEL=="sda2", ENV{UDISKS_PRESENTATION_HIDE}="1"<br />
<br />
shows all partitions with the exception of {{ic|sda1}} and {{ic|sda2}} on your desktop. Note that if you are using {{Pkg|udisks2}}, the above will not work as {{ic|UDISKS_PRESENTATION_HIDE}} is no longer supported. Instead, use {{ic|UDISKS_IGNORE}} as follows:<br />
<br />
KERNEL=="sda1", ENV{UDISKS_IGNORE}="1"<br />
KERNEL=="sda2", ENV{UDISKS_IGNORE}="1"<br />
<br />
Because block device names can change between reboots, it is also possible to use UUIDs (as gathered from executing the {{ic|blkid /dev/sdX}} command) to hide partitions or whole devices:<br />
<br />
==== Example ====<br />
<br />
{{hc|# blkid /dev/sdX|2=<br />
/dev/sdX: LABEL="Filesystem Label" UUID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX" UUID_SUB="YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY" TYPE="btrfs"<br />
}}<br />
<br />
Then the following line can be used:<br />
<br />
SUBSYSTEM=="block", ENV{ID_FS_UUID}=="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX", ENV{UDISKS_IGNORE}="1"<br />
<br />
The above line is also useful to hide multi device btrfs filesystems, as all the devices from a single btrtfs filesystem will share the same UUID across the devices but will have different SUB_UUID for each individual device.<br />
<br />
=== Apply ATA settings (udisks2) ===<br />
<br />
At start-up and when a drive is connected, udisksd will apply configuration stored in the file {{ic|/etc/udisks2/''IDENTIFIER''.conf}} where ''IDENTIFIER'' is the value of the Drive:Id property for the drive. Currently ATA settings are supported. See {{man|8|udisks}} for available options. These settings have essentially the same effect as those of [[hdparm]], but they are persistent as long as the udisks daemon is autostarted.<br />
<br />
For example, to set standby timeout to 240 (20 minutes) for a drive, add the following:<br />
<br />
{{hc|1=/etc/udisks2/''DriveId''.conf|<br />
2=[ATA]<br />
StandbyTimeout=240<br />
}}<br />
<br />
To obtain the DriveId for your drive, use {{ic|1=$ udevadm info --query=all --name=/dev/''sdx'' {{!}} grep ID_SERIAL {{!}} sed "s/_/-/g"}}<br />
<br />
Alternatively, use a GUI utility to manage the configuration file, such as {{Pkg|gnome-disk-utility}}.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Hidden devices (udisks2) ===<br />
<br />
Udisks2 hides certain devices from the user by default. If this is undesired or otherwise problematic, copy {{ic|/usr/lib/udev/rules.d/80-udisks2.rules}} to {{ic|/etc/udev/rules.d/80-udisks2.rules}} and remove the following section in the copy:<br />
<br />
{{bc|<br />
# ------------------------------------------------------------------------<br />
# ------------------------------------------------------------------------<br />
# ------------------------------------------------------------------------<br />
# Devices which should not be display in the user interface<br />
[...]<br />
}}<br />
<br />
=== Devices do not remain unmounted (udisks) ===<br />
<br />
''udisks'' remounts devices after a given period, or ''polls'' those devices. This can cause unexpected behaviour, for example when formatting drives, sharing them in a [[virtual machine]], power saving, or removing a drive that was not detached with {{ic|--detach}} before. <br />
<br />
To disable polling for a given device, for example a CD/DVD device:<br />
<br />
# udisks --inhibit-polling /dev/sr''0''<br />
<br />
or for all devices:<br />
<br />
# udisks --inhibit-all-polling<br />
<br />
See {{man|8|udisks}} for more information.<br />
<br />
=== Broken standby timer (udisks2) ===<br />
<br />
The udisks daemon polls [[S.M.A.R.T.]] data from drives regularly. Hard drives with a longer standby timeout than the polling interval may fail to enter standby. Drives that are already spun down are usually not affected. There seems no way to disable polling or change the interval as for {{Pkg|udisks2}} by now. See [https://bugs.launchpad.net/ubuntu/+source/udisks2/+bug/1281588], [https://bugs.freedesktop.org/show_bug.cgi?id=26508].<br />
<br />
However, Standby timeout applied by udisks2 seems to be unaffected. To set standby timeout via udisks, see [[#Apply ATA settings (udisks2)]].<br />
<br />
Other possible workarounds could be setting the timeout below the polling interval (10 minutes) or forcing a manaul spindown using {{ic|hdparm -y /dev/''sdx''}}.<br />
<br />
== See also ==<br />
<br />
* [[Gentoo:udisks]]<br />
* [http://blog.fpmurphy.com/2011/08/introduction-to-udisks.html?output=pdf Introduction to udisks]</div>Samovar123https://wiki.archlinux.org/index.php?title=Udisks&diff=575099Udisks2019-06-11T03:16:33Z<p>Samovar123: </p>
<hr />
<div>[[Category:Hardware detection and troubleshooting]]<br />
[[fr:Gestion de volumes avec udisks]]<br />
[[it:Execute on USB insert]]<br />
[[ja:Udisks]]<br />
[[ru:Udisks]]<br />
[[zh-hans:Udisks]]<br />
{{Related articles start}}<br />
{{Related|udev}}<br />
{{Related|Mount}}<br />
{{Related|Polkit}}<br />
{{Related|File manager functionality}}<br />
{{Related articles end}}<br />
[http://www.freedesktop.org/wiki/Software/udisks/ udisks] provides a daemon ''udisksd'', that implements D-Bus interfaces used to query and manipulate storage devices, and a command-line tool ''udisksctl'', used to query and use the daemon.<br />
<br />
== Installation ==<br />
<br />
There are two versions of ''udisks'' called {{AUR|udisks}} and {{Pkg|udisks2}}. Development of '''udisks''' has ceased in favor of '''udisks2'''. [http://davidz25.blogspot.be/2012/03/simpler-faster-better.html]<br />
<br />
{{man|8|udisksd}} (for '''udisks2''') and {{ic|udisks-daemon}} (for '''udisks''') are started on-demand by [[D-Bus]], and should not be enabled explicitly. They can be controlled through the command-line with {{man|1|udisksctl}} and {{man|1|udisks|url=}}, respectively.<br />
<br />
== Configuration ==<br />
<br />
Actions a user can perform using udisks are restricted with [[Polkit]]. If the [[session|user session]] is not activated or present (for example, when controlling udisks from a [[systemd/User]] service), adjust Polkit rules accordingly.<br />
<br />
See [https://github.com/coldfix/udiskie/wiki/Permissions] for common udisks permissions for the {{ic|storage}} group, and [https://gist.github.com/grawity/3886114#file-udisks2-allow-mount-internal-js] for a more restrictive example. If you are using [[Dolphin]], you may see [https://gist.github.com/Scrumplex/8f528c1f63b5f4bfabe14b0804adaba7].<br />
<br />
== Usage ==<br />
<br />
To manually mount a removable drive, for example {{ic|/dev/sdc}}:<br />
<br />
$ udisksctl mount -b /dev/sdc1<br />
<br />
To unmount:<br />
<br />
$ udisksctl unmount -b /dev/sdc1<br />
<br />
See {{ic|udisksctl --help}} for more.<br />
<br />
== Tips and tricks ==<br />
<br />
=== Mount helpers ===<br />
<br />
The automatic mounting of devices is easily achieved with udisks wrappers. See also [[List of applications/Utilities#Mount tools]].<br />
<br />
{{Note|[[Desktop environment]]s, such as [[GNOME]] and [[KDE]] may also provide a udisk wrapper.}}<br />
<br />
* {{App|bashmount|A bash script to mount and manage removable media as a regular user with ''udisks2''.|https://github.com/jamielinux/bashmount|{{AUR|bashmount}}}}<br />
* {{App|udiskie| ''udisks2'' automounter with optional notifications, tray icon and support for password protected [[Dm-crypt/Device_encryption|LUKS devices]]. See the [https://github.com/coldfix/udiskie/wiki/Usage udiskie wiki] for details|https://github.com/coldfix/udiskie|{{Pkg|udiskie}}}}<br />
* {{App|udisksvm|GUI ''udisks2'' wrapper written in Python3 and using the Qt5 framework. It uses mouse clicks to mount, unmount removable devices or eject a CD/DVD. See the [https://github.com/berbae/udisksvm/blob/master/README README] file for details.|3=https://github.com/berbae/udisksvm|4={{AUR|udisksvm}}}}<br />
* {{App|udevil|Includes [http://igurublog.wordpress.com/downloads/script-devmon devmon], which is compatible to ''udisks'' and ''udisks2''.|https://github.com/IgnorantGuru/udevil|{{Pkg|udevil}}}}<br />
<br />
{{Note|''devmon'' only uses ''udisks'' or ''udisks2'' for mounting (in this order) if ''udevil'' or ''pmount'' miss the SUID permission. To remove this permission, run {{ic|chmod -s /usr/bin/''udevil''}} as root.}}<br />
<br />
==== udevadm monitor====<br />
<br />
You may use {{ic|udevadm monitor}} to monitor block events and mount drives when a new block device is created. Stale mount points are automatically removed by ''udisksd'', such that no special action is required on deletion.<br />
<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
<br />
pathtoname() {<br />
udevadm info -p /sys/"$1" | awk -v FS== '/DEVNAME/ {print $2}'<br />
}<br />
<br />
stdbuf -oL -- udevadm monitor --udev -s block | while read -r -- _ _ event devpath _; do<br />
if [ "$event" = add ]; then<br />
devname=$(pathtoname "$devpath")<br />
udisksctl mount --block-device "$devname" --no-user-interaction<br />
fi<br />
done<br />
</nowiki>}}<br />
<br />
=== Mount to /media (udisks2) ===<br />
<br />
By default, udisks2 mounts removable drives under the ACL controlled directory {{ic|/run/media/$USER/}}. If you wish to mount to {{ic|/media}} instead, use this rule:<br />
<br />
{{hc|/etc/udev/rules.d/99-udisks2.rules|<nowiki><br />
# UDISKS_FILESYSTEM_SHARED<br />
# ==1: mount filesystem to a shared directory (/media/VolumeName)<br />
# ==0: mount filesystem to a private directory (/run/media/$USER/VolumeName)<br />
# See udisks(8)<br />
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{UDISKS_FILESYSTEM_SHARED}="1"<br />
</nowiki>}}<br />
<br />
Since {{ic|/media}}, unlike {{ic|/run}}, is not mounted by default as a [[tmpfs]], you may also wish to create a [[Systemd#Temporary_files|tmpfiles.d]] snippet to clean stale mountpoints at every boot:<br />
<br />
{{hc|/etc/tmpfiles.d/media.conf|<br />
D /media 0755 root root 0 -<br />
}}<br />
<br />
=== Mount loop devices ===<br />
<br />
To easily mount ISO images, use the following command:<br />
<br />
$ udisksctl loop-setup -r -f ''image.iso''<br />
<br />
This will create a loop device and show the ISO image ready to mount. Once unmounted, the loop device will be terminated by [[udev]].<br />
<br />
{{Note|This mounts a read only image. To mount raw disk images, such as for [[QEMU]], remove the {{ic|-r}} flag, and release the image after use with {{ic|udisksctl loop-delete -b ''/dev/loop0''}}. Substitute {{ic|/dev/loop0}} with the name of the loop device.}}<br />
<br />
=== Hide selected partitions ===<br />
<br />
If you wish to prevent certain partitions or drives appearing on the desktop, you can create a udev rule, for example {{ic|/etc/udev/rules.d/10-local.rules}}:<br />
<br />
KERNEL=="sda1", ENV{UDISKS_PRESENTATION_HIDE}="1"<br />
KERNEL=="sda2", ENV{UDISKS_PRESENTATION_HIDE}="1"<br />
<br />
shows all partitions with the exception of {{ic|sda1}} and {{ic|sda2}} on your desktop. Note that if you are using {{Pkg|udisks2}}, the above will not work as {{ic|UDISKS_PRESENTATION_HIDE}} is no longer supported. Instead, use {{ic|UDISKS_IGNORE}} as follows:<br />
<br />
KERNEL=="sda1", ENV{UDISKS_IGNORE}="1"<br />
KERNEL=="sda2", ENV{UDISKS_IGNORE}="1"<br />
<br />
Because block device names can change between reboots, it is also possible to use UUIDs (as gathered from executing the {{ic|blkid /dev/sdX}} command) to hide partitions or whole devices:<br />
<br />
==== Example ====<br />
<br />
{{hc|# blkid /dev/sdX|2=<br />
/dev/sdX: LABEL="Filesystem Label" UUID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX" UUID_SUB="YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY" TYPE="btrfs"<br />
}}<br />
<br />
Then the following line can be used:<br />
<br />
SUBSYSTEM=="block", ENV{ID_FS_UUID}=="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX", ENV{UDISKS_IGNORE}="1"<br />
<br />
The above line is also useful to hide multi device btrfs filesystems, as all the devices from a single btrtfs filesystem will share the same UUID across the devices but will have different SUB_UUID for each individual device.<br />
<br />
=== Apply ATA settings (udisks2) ===<br />
<br />
At start-up and when a drive is connected, udisksd will apply configuration stored in the file {{ic|/etc/udisks2/''IDENTIFIER''.conf}} where ''IDENTIFIER'' is the value of the Drive:Id property for the drive. Currently ATA settings are supported. See {{man|8|udisks}} for available options. These settings have essentially the same effect as those of [[hdparm]], but they are persistent as long as the udisks daemon is autostarted.<br />
<br />
For example, to set standby timeout to 240 (20 minutes) for a drive, add the following:<br />
<br />
{{hc|1=/etc/udisks2/''DriveId''.conf|<br />
2=[ATA]<br />
StandbyTimeout=240<br />
}}<br />
<br />
To obtain the DriveId for your drive, use {{ic|1=$ clear; printf "Please type a drive name e.g. sda\nCtrl-C to exit\n\n"; while read -e "DRIVE"; do udevadm info --query=all --name=/dev/$DRIVE {{!}} grep ID_SERIAL= {{!}} sed "s/_/-/g; s/E: ID-SERIAL=//g"; done }}<br />
<br />
Alternatively, use a GUI utility to manage the configuration file, such as {{Pkg|gnome-disk-utility}}.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Hidden devices (udisks2) ===<br />
<br />
Udisks2 hides certain devices from the user by default. If this is undesired or otherwise problematic, copy {{ic|/usr/lib/udev/rules.d/80-udisks2.rules}} to {{ic|/etc/udev/rules.d/80-udisks2.rules}} and remove the following section in the copy:<br />
<br />
{{bc|<br />
# ------------------------------------------------------------------------<br />
# ------------------------------------------------------------------------<br />
# ------------------------------------------------------------------------<br />
# Devices which should not be display in the user interface<br />
[...]<br />
}}<br />
<br />
=== Devices do not remain unmounted (udisks) ===<br />
<br />
''udisks'' remounts devices after a given period, or ''polls'' those devices. This can cause unexpected behaviour, for example when formatting drives, sharing them in a [[virtual machine]], power saving, or removing a drive that was not detached with {{ic|--detach}} before. <br />
<br />
To disable polling for a given device, for example a CD/DVD device:<br />
<br />
# udisks --inhibit-polling /dev/sr''0''<br />
<br />
or for all devices:<br />
<br />
# udisks --inhibit-all-polling<br />
<br />
See {{man|8|udisks}} for more information.<br />
<br />
=== Broken standby timer (udisks2) ===<br />
<br />
The udisks daemon polls [[S.M.A.R.T.]] data from drives regularly. Hard drives with a longer standby timeout than the polling interval may fail to enter standby. Drives that are already spun down are usually not affected. There seems no way to disable polling or change the interval as for {{Pkg|udisks2}} by now. See [https://bugs.launchpad.net/ubuntu/+source/udisks2/+bug/1281588], [https://bugs.freedesktop.org/show_bug.cgi?id=26508].<br />
<br />
However, Standby timeout applied by udisks2 seems to be unaffected. To set standby timeout via udisks, see [[#Apply ATA settings (udisks2)]].<br />
<br />
Other possible workarounds could be setting the timeout below the polling interval (10 minutes) or forcing a manaul spindown using {{ic|hdparm -y /dev/''sdx''}}.<br />
<br />
== See also ==<br />
<br />
* [[Gentoo:udisks]]<br />
* [http://blog.fpmurphy.com/2011/08/introduction-to-udisks.html?output=pdf Introduction to udisks]</div>Samovar123