متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 228Network · Storage

How to mount network folders on demand with autofs

Fifty NFS shares in /etc/fstab slow down every boot, and when the NFS server is down, the client hangs. autofs mounts a share only when someone opens its path, and unmounts it again after some idle minutes. A wildcard map can even give every user their own home folder from the file server with one line. This how-to sets up an indirect map, a wildcard map for homes, and tests it.

  • 5 الدروس
  • 10 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

228.1

The quick answer

/etc/auto.master.d/data.autofs
/data  /etc/auto.data  --timeout=300
/etc/auto.data
projects  -rw,soft,vers=4.2  nfs01.example.com:/exports/projects
archive   -ro,vers=4.2       nfs01.example.com:/exports/archive
dnf install -y autofs nfs-utils
systemctl enable --now autofs
ls /data/projects
findmnt /data/projects

228.2

Step by step

  1. Install autofs and the NFS client (Debian/Ubuntu: autofs nfs-common).
  2. Master map (first file) — "everything under /data is managed by the map /etc/auto.data, unmount after 300 s idle". Do not create /data/projects yourself; autofs creates the folders.
  3. Map file (second file) — one line per share: key (folder name under /data), mount options, source. Check the exports first: showmount -e nfs01.example.com (NFSv3) or try a manual mount.
  4. Start and trigger — ls /data/projects mounts it; ls /data alone shows nothing until a key is used (add --browse in the master map to show all keys).
  5. Home folders with a wildcard:
/etc/auto.master.d/home.autofs
/home/remote  /etc/auto.home
/etc/auto.home
*  -rw,vers=4.2  nfs01.example.com:/exports/home/&

* matches any name, & is replaced by it: /home/remote/alice mounts …/home/alice.

  1. See the active maps — automount -m prints what autofs has loaded. After editing maps: systemctl reload autofs.
  2. Debug — journalctl -u autofs -f while you ls the path; stop the service and run automount -f -v in the foreground for verbose output.

228.3

Check that it worked

ls /data/projects lists the files; findmnt /data/projects shows nfs4 from nfs01.example.com:/exports/projects; after 5 idle minutes findmnt shows it unmounted again; ls /home/remote/alice mounts alice's home.

الأوامر في هذا الدرس

228.4

Common problems

ProblemCauseFix
No such file or directory on the keyMap not loaded, typo in the key, or master file not ending in .autofs.automount -m; systemctl reload autofs.
access denied by serverExport does not allow this client.Fix /etc/exports on the server (exportfs -v).
Folder exists but is emptyYou created it by hand under the autofs mount point.Remove your own folders; let autofs create them.
Hangs when the server is downHard mount.Use soft (careful with writes) and short timeouts; monitor the server.
Permission denied as root on NFSRoot squash on the server.Normal security; work as the owning user.
Mounts never go awaySomething keeps them busy (shell in the folder).lsof +f -- /data/projects; shorter --timeout.

228.5

Go further

1What is the advantage of autofs over fstab for NFS?

Shares are mounted only when used and unmounted when idle, so boots are fast and a down server does not block the system.

2What do * and & mean in an autofs map?

* matches any folder name that is opened, and & is replaced by that name in the source path.

كل الأوامر في هذا الفصل