시작 시 systemd를 사용하여 삼바 공유 마운트

시작 시 systemd를 사용하여 삼바 공유 마운트

부팅 시 마운트하고 싶은 Samba 공유가 있습니다. 당장 필요한 것은 아니지만 처음 액세스할 때 사용할 수 있기를 바랍니다. 나는 /etc/fstab의 .mount 파일과 항목 및 특수 systemd 옵션을 사용해 보았습니다. 문제는 .mount 장치가 네트워크 작동 및 실행 중인 확인자에 의존하도록 강제하더라도 DNS 확인자가 파일 서버 호스트를 확인할 수 없다는 것입니다. 나중에 대상에 종속되게 만들거나 약간의 지연을 추가할 수 있다는 것을 알고 있지만 systemd를 이해하고 이를 올바른 방식으로 수행하는 데 관심이 있습니다.

[Unit]
Description=Hardware file share
Requires=network-online.target
After=network-online.target systemd-resolved.service
Wants=network-online.target systemd-resolved.service

[Mount]
What=//files.example.com/hardware
Where=/media/hardware
Type=cifs
Options=rw,uid=jpkotta,gid=users,credentials=/etc/samba/private/files.cred,iocharset=utf8,file_mode=0644,dir_mode=0755
TimeoutSec=30

[Install]
WantedBy=multi-user.target

(편집된) 로그는 다음과 같습니다.

Jun 27 12:01:28 shannon systemd[1]: Starting Network Service...
Jun 27 12:01:28 shannon systemd[1]: Started Periodic Command Scheduler.
Jun 27 12:01:28 shannon systemd[1]: Started Entropy Harvesting Daemon.
Jun 27 12:01:28 shannon systemd[1]: Started CUPS Scheduler.
Jun 27 12:01:28 shannon systemd[1]: Starting Login Service...
Jun 27 12:01:28 shannon systemd[1]: Starting Save/Restore Sound Card State...
Jun 27 12:01:28 shannon systemd[1]: Starting Avahi mDNS/DNS-SD Stack...
Jun 27 12:01:28 shannon systemd[1]: Starting Virtual console mouse server...
Jun 27 12:01:28 shannon systemd-logind[417]: New seat seat0.
Jun 27 12:01:28 shannon systemd[1]: Started Login Service.
Jun 27 12:01:28 shannon systemd-logind[417]: Watching system buttons on /dev/input/event4 (Power Button)
Jun 27 12:01:28 shannon systemd-logind[417]: Watching system buttons on /dev/input/event3 (Power Button)
Jun 27 12:01:28 shannon crond[414]: (CRON) INFO (Syslog will be used instead of sendmail.)
Jun 27 12:01:28 shannon crond[414]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 59% if used.)
Jun 27 12:01:28 shannon avahi-daemon[419]: Found user 'avahi' (UID 84) and group 'avahi' (GID 84).
Jun 27 12:01:28 shannon avahi-daemon[419]: Successfully dropped root privileges.
Jun 27 12:01:28 shannon avahi-daemon[419]: avahi-daemon 0.6.32 starting up.
Jun 27 12:01:28 shannon avahi-daemon[419]: WARNING: No NSS support for mDNS detected, consider installing nss-mdns!
Jun 27 12:01:28 shannon systemd[1]: Started Avahi mDNS/DNS-SD Stack.
Jun 27 12:01:28 shannon avahi-daemon[419]: Successfully called chroot().
Jun 27 12:01:28 shannon avahi-daemon[419]: Successfully dropped remaining capabilities.
Jun 27 12:01:28 shannon avahi-daemon[419]: No service file found in /etc/avahi/services.
Jun 27 12:01:28 shannon avahi-daemon[419]: Network interface enumeration completed.
Jun 27 12:01:28 shannon systemd[1]: Started Make remote CUPS printers available locally.
Jun 27 12:01:28 shannon avahi-daemon[419]: Server startup complete. Host name is shannon.local. Local service cookie is 740728414.
Jun 27 12:01:28 shannon /usr/bin/gpm[429]: *** info [daemon/startup.c(136)]:
Jun 27 12:01:28 shannon systemd[1]: Started Virtual console mouse server.
Jun 27 12:01:28 shannon /usr/bin/gpm[429]: Started gpm successfully. Entered daemon mode.
Jun 27 12:01:28 shannon systemd[1]: Started Save/Restore Sound Card State.
Jun 27 12:01:28 shannon crond[414]: (CRON) INFO (running with inotify support)
Jun 27 12:01:28 shannon systemd-networkd[413]: Enumeration completed
Jun 27 12:01:28 shannon systemd[1]: Started Network Service.
Jun 27 12:01:28 shannon systemd-networkd[413]: enp4s0: Renamed to eth0
Jun 27 12:01:28 shannon systemd-networkd[413]: eth0: Renamed to enp4s0
Jun 27 12:01:28 shannon systemd[1]: Reached target Network.
Jun 27 12:01:28 shannon systemd-networkd[413]: enp4s0: IPv6 enabled for interface: Success
Jun 27 12:01:28 shannon kernel: IPv6: ADDRCONF(NETDEV_UP): enp4s0: link is not ready
Jun 27 12:01:28 shannon haveged[415]: haveged: ver: 1.9.1; arch: x86; vend: GenuineIntel; build: (gcc 4.9.2 ITV); collect: 128K
Jun 27 12:01:28 shannon haveged[415]: haveged: cpu: (L4 VC); data: 32K (L2 L4 V); inst: 32K (L2 L4 V); idx: 21/40; sz: 31910/59039
Jun 27 12:01:28 shannon haveged[415]: haveged: tot tests(BA8): A:1/1 B:1/1 continuous tests(B):  last entropy estimate 7.99984
Jun 27 12:01:28 shannon haveged[415]: haveged: fills: 0, generated: 0
Jun 27 12:01:28 shannon systemd[1]: Started OpenSSH Daemon.
Jun 27 12:01:28 shannon systemd[1]: Started A file transfer program to keep remote files in sync.
Jun 27 12:01:28 shannon systemd[1]: Starting Samba NetBIOS name server...
Jun 27 12:01:28 shannon /usr/bin/gpm[429]: *** info [mice.c(1990)]:
Jun 27 12:01:28 shannon /usr/bin/gpm[429]: imps2: Auto-detected intellimouse PS/2
Jun 27 12:01:28 shannon systemd[1]: Starting Network Time Service...
Jun 27 12:01:28 shannon systemd[1]: Reached target Network is Online.
Jun 27 12:01:29 shannon rsyncd[440]: rsyncd version 3.1.2 starting, listening on port 873
Jun 27 12:01:29 shannon systemd[1]: Starting Permit User Sessions...
Jun 27 12:01:29 shannon systemd[1]: Started Pacserve.
Jun 27 12:01:29 shannon systemd[1]: Starting Network Name Resolution...
Jun 27 12:01:29 shannon systemd[1]: Started Permit User Sessions.
Jun 27 12:01:29 shannon systemd[1]: Started Getty on tty1.
Jun 27 12:01:29 shannon systemd[1]: Reached target Login Prompts.
Jun 27 12:01:29 shannon systemd[1]: Started SLiM Simple Login Manager.
Jun 27 12:01:30 shannon systemd-resolved[461]: Positive Trust Anchors:
Jun 27 12:01:30 shannon systemd-resolved[461]: . IN DS 19036 8 2 49aac11d7b6f6446702e54a1607371607a1a41855200fd2ce1cdde32f24e8fb5
Jun 27 12:01:30 shannon systemd-resolved[461]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.arpa 22.172.in-addr.arpa 23.172.in-addr.arpa 24.172.in-addr.arpa 25.172.in-addr.arpa 26.172.in-addr.arpa 27.172.in-addr.arpa 28.172.in-addr.arpa 29.172.in-addr.arpa 30.172.in-addr.arpa 31.172.in-addr.arpa 168.192.in-addr.arpa corp home internal intranet lan local private test
Jun 27 12:01:30 shannon systemd-resolved[461]: Using system hostname 'shannon'.
Jun 27 12:01:30 shannon systemd-resolved[461]: Switching to system DNS server 10.0.0.22.
Jun 27 12:01:30 shannon systemd[1]: Started Network Name Resolution.
Jun 27 12:01:30 shannon systemd[1]: Mounting Hardware file share...
Jun 27 12:01:30 shannon mount[467]: mount error: could not resolve address for files.packetdigital.com: Unknown error
Jun 27 12:01:30 shannon systemd[1]: media-hardware.mount: Mount process exited, code=exited status=1
Jun 27 12:01:30 shannon systemd[1]: Failed to mount Hardware file share.
Jun 27 12:01:30 shannon systemd[1]: media-hardware.mount: Unit entered failed state.
Jun 27 12:01:30 shannon sshd[431]: Server listening on 0.0.0.0 port 22.
Jun 27 12:01:30 shannon sshd[431]: Server listening on :: port 22.
Jun 27 12:01:30 shannon ntpd[443]: ntpd [email protected] Sat Jun  4 14:58:28 UTC 2016 (1): Starting
Jun 27 12:01:30 shannon ntpd[443]: Command line: /usr/bin/ntpd -g -u ntp:ntp
Jun 27 12:01:30 shannon systemd[1]: Started Network Time Service.
Jun 27 12:01:30 shannon ntpd[472]: proto: precision = 0.087 usec (-23)
Jun 27 12:01:30 shannon ntpd[472]: Listen and drop on 0 v6wildcard [::]:123
Jun 27 12:01:30 shannon ntpd[472]: Listen and drop on 1 v4wildcard 0.0.0.0:123
Jun 27 12:01:30 shannon ntpd[472]: Listen normally on 2 lo 127.0.0.1:123
Jun 27 12:01:30 shannon ntpd[472]: Listen normally on 3 lo [::1]:123
Jun 27 12:01:30 shannon ntpd[472]: Listening on routing socket on fd #20 for interface updates
Jun 27 12:01:30 shannon dbus[412]: [system] Activating via systemd: service name='org.freedesktop.ColorManager' unit='colord.service'
Jun 27 12:01:30 shannon systemd[1]: Starting Manage, Install and Generate Color Profiles...
Jun 27 12:01:31 shannon dbus[412]: [system] Successfully activated service 'org.freedesktop.ColorManager'
Jun 27 12:01:31 shannon systemd[1]: Started Manage, Install and Generate Color Profiles.
Jun 27 12:01:31 shannon kernel: tg3 0000:04:00.0 enp4s0: Link is up at 1000 Mbps, full duplex
Jun 27 12:01:31 shannon kernel: tg3 0000:04:00.0 enp4s0: Flow control is on for TX and on for RX
Jun 27 12:01:31 shannon kernel: IPv6: ADDRCONF(NETDEV_CHANGE): enp4s0: link becomes ready
Jun 27 12:01:31 shannon systemd-networkd[413]: enp4s0: Gained carrier
Jun 27 12:01:31 shannon colord[474]: (colord:474): Cd-WARNING **: failed to get session [pid 416]: No such device or address
Jun 27 12:01:31 shannon colord[474]: /usr/lib/colord/colord-sane: error while loading shared libraries: libsane.so.1: cannot open shared object file: No such file or directory
Jun 27 12:01:32 shannon slim[466]: /usr/bin/fvwm - FVWM
Jun 27 12:01:32 shannon avahi-daemon[419]: Joining mDNS multicast group on interface enp4s0.IPv6 with address fe80::21d:9ff:fe26:b135.
Jun 27 12:01:32 shannon systemd-networkd[413]: enp4s0: Gained IPv6LL
Jun 27 12:01:32 shannon avahi-daemon[419]: New relevant interface enp4s0.IPv6 for mDNS.
Jun 27 12:01:32 shannon avahi-daemon[419]: Registering new address record for fe80::21d:9ff:fe26:b135 on enp4s0.*.
Jun 27 12:01:33 shannon systemd-networkd[413]: enp4s0: DHCPv4 address 10.0.1.87/16 via 10.0.0.22
Jun 27 12:01:33 shannon dbus[412]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service'
Jun 27 12:01:33 shannon avahi-daemon[419]: Joining mDNS multicast group on interface enp4s0.IPv4 with address 10.0.1.87.
Jun 27 12:01:33 shannon avahi-daemon[419]: New relevant interface enp4s0.IPv4 for mDNS.
Jun 27 12:01:33 shannon avahi-daemon[419]: Registering new address record for 10.0.1.87 on enp4s0.IPv4.
Jun 27 12:01:33 shannon systemd[1]: Starting Hostname Service...
Jun 27 12:01:33 shannon dbus[412]: [system] Successfully activated service 'org.freedesktop.hostname1'
Jun 27 12:01:33 shannon systemd[1]: Started Hostname Service.
Jun 27 12:01:34 shannon ntpd[472]: Listen normally on 4 enp4s0 10.0.1.87:123
Jun 27 12:01:34 shannon ntpd[472]: Listen normally on 5 enp4s0 [fe80::21d:9ff:fe26:b135%2]:123
Jun 27 12:01:34 shannon ntpd[472]: new interface(s) found: waking up resolver

답변1

이것 때문에 반나절을 낭비했지만 간단히 말해서 .mount파일은 단지 마운트 정의일 뿐이지만 서비스(예: 자동 시작)처럼 사용하려면 파일 .automount도 필요합니다. 이것은 실제로 중복되지만 내 경험으로는 이를 수행할 수 있는 다른 방법이 없습니다. 예:

/etc/systemd/system/finance.mount:

[Mount]
What=//smb.ad.foobar.com/finance
Where=/finance
Options=credentials=/etc/fstab.password,noperm,vers=2.1,_netdev
Type=cifs

/etc/systemd/system/finance.automount:

[Unit]
Requires=remote-fs-pre.target
After=remote-fs-pre.target

[Install]
WantedBy=remote-fs.target

다음 명령을 사용하여 자동으로 시작되도록 할 수 있습니다.

systemctl enable finance.automount

중요한 팁:지시문Where~ 해야 하다유닛의 파일명을 맞춰보세요!

추가 자료:

systemd를 사용하여 CIFS 디렉토리를 마운트하는 방법은 무엇입니까?
시스템 탑재에 실패했습니다. 여기서 = 설정이 장치 이름과 일치하지 않습니다.
마운트 시스템
systemd.automount

답변2

결국 자동 마운트를 사용하여 처음 액세스할 때까지 공유가 마운트되지 않았습니다. 설치에 필요한 시간은 일반적으로 눈에 띄지 않기 때문에 유휴 시간 초과 후에 제거하기로 선택했습니다. 의 관련 옵션은 다음과 같습니다 /etc/fstab.x-systemd.automount

//files.example.com/software /media/software cifs x-systemd.automount,x-systemd.idle-timeout=1min,rw,uid=jpkotta,gid=users,credentials=/etc/samba/private/files.cred,iocharset=utf8,file_mode=0644,dir_mode=0755 0 0

참고: 저는 를 사용하는 것을 선호 fstab하지만 분명히 이는 시스템 단위 파일을 사용하여 수행할 수도 있습니다. 실제로 이것을 사용하면 fstab런타임에 임시 시스템 단위가 계속 생성됩니다. systemctl cat media-software.mount예를 들어 및 를 사용하여 볼 수 있습니다 systemctl cat media-software.automount.

답변3

나에게 해결책은 systemd-networkd-wait-online.service.

이렇게 상태를 확인할 수 있습니다

 systemctl status systemd-networkd-wait-online.service

이렇게 활성화해 보세요

 systemctl enable systemd-networkd-wait-online.service

관련 정보