Guest User

Untitled

a guest
Feb 6th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. # Automount of CIFS (smbfs) folders w/ systemd
  2. ## i.e. mounting your Windows shares on Linux at boot
  3.  
  4. First, let's see how to mount the remote directory. Assume that there is a shared folder over the network at `\\192.168.1.1\users\self\shared` which is accessible with user `myuser` and password `secret123`.
  5.  
  6. We could mount it manually in `/mnt/winshare` with:
  7.  
  8. # mount -t cifs //192.168.1.1/users/self/shared /mnt/winshare -o user=myuser,password=secret123
  9.  
  10. This should work on your Linux box, because systemd will basically call mount with the same arguments: `What` (`//192.168.1.1/users/self/shared`), `Where` (`/mnt/winshare`) and `Options` (`user=myuser,password=secret123`).
  11.  
  12. To configure systemd to automatically mount that network folder on boot, there are 2 files needed: `mnt-winshare.mount` and `mnt-winshare.automount`.
  13. The `.mount` unit file specifies how to mount a drive (`man systemd.mount` for details), while the `.automount` unit file specifies what to mount automatically on boot (`man systemd.automount`).
  14.  
  15. **Important!** Note that the name of the file **must** map to the actual filesystem mount target, that is `mnt-winshare.(auto)mount` refers to `/mnt/winshare`. E.g. to mount in `/home/user/myfolder` the file names must be `home-user-myfolder.(auto)mount`.
  16.  
  17. The content of the files is the following:
  18.  
  19. # cat /etc/systemd/system/mnt-winshare.mount
  20. [Unit]
  21. Description=Remote Win Mount
  22.  
  23. [Mount]
  24. What=//192.168.1.1/users/self/shared
  25. Where=/mnt/winshare
  26. Type=cifs
  27. Options=user=myuser,password=secret123
  28.  
  29. [Install]
  30. WantedBy=multi-user.target
  31.  
  32. and
  33.  
  34. # cat /etc/systemd/system/mnt-winshare.automount
  35. [Unit]
  36. Description=Automount Remote Win Mount
  37.  
  38. [Automount]
  39. Where=/mnt/winshare
  40.  
  41. [Install]
  42. WantedBy=multi-user.target
  43.  
  44. The former file goes in `/etc/systemd/system/mnt-winshare.mount` while the latter `/etc/systemd/system/mnt-winshare.automount`.
  45.  
  46. Then, reload the units to ensure everything is to its latest version:
  47.  
  48. # systemctl daemon-reload
  49.  
  50. At this point, we should be able to manually mount and unmount the remote folder using `systemctl`:
  51.  
  52. # systemctl start mnt-winshare.mount
  53. # systemctl stop mnt-winshare.mount
  54.  
  55. This will not, however, automatically mount the system at startup. To do so, just enable the automount
  56.  
  57. # systemctl enable mnt-winshare.automount
  58.  
  59. And this should be it!
Add Comment
Please, Sign In to add comment