大网数据广告活动
服务器运维问答

Automount USB drives with systemd

· 52CE 我爱测

We're updating our servers from a very out-of-date distro to a modern Debian Jessie based system, including lightdm / xfce, and of course systemd (and udisks2). One sticking point is automounting USB drives. We used to accomplish…

问题原文

原帖链接 · Mike Blackwell · CC BY-SA 3.0

We're updating our servers from a very out-of-date distro to a modern Debian Jessie based system, including lightdm / xfce, and of course systemd (and udisks2). One sticking point is automounting USB drives. We used to accomplish this with some udev rules. The old rules almost still work - the mount point gets created and the drive is mounted fine, but after a few seconds systemd is doing something that breaks the mount, so subsequent access attempts result in "Transport endpoint is not connected" errors.

Manually mounting the drive via the command line works fine. So does letting a file manager (thunar and thunar-volman, which in turn uses udisks2). But those are not viable options - these systems mostly run headless, so thunar isn't normally running. We need to be able to plug in disk drives for unattended cron-based backups.

I thought that modifying the udev script to spawn a detached job which waits a few seconds before performing the mount might do the trick, but systemd seems to go out of its way to prevent this - it somehow still waits for the detached job to finish before continuing.

Perhaps having the udev script tickle udisks2 somehow is the right approach? I'm at a lose, so any advice greatly appreciated.

社区高分解答

原帖链接 · infinite-etcetera · CC BY-SA 3.0

there is a new, succinct systemd auto-mount option which can be used with fstab which allows you to use all the standardized mount permission options, and it looks like this:

  x-systemd.automount

an example of it in an fstab line:

  /dev/sdd1   /mnt/hitachi-one     auto     noauto,x-systemd.automount     0 2

the noauto option will mean it will not attempt to be mounted at boot, as with older software autofs.

after adding a new x-systemd.automount line to fstab you then need to run:

  sudo systemctl daemon-reload

and then both, or one, of the following:

  sudo systemctl restart remote-fs.target
  sudo systemctl restart local-fs.target

for more infomation about it:

https://wiki.archlinux.org/index.php/Fstab#Automount_with_systemd

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。