CoreOS mounting CIFS on reboot

coreos

I am able to mount a drive Windows share drive on CoreOS, using https://github.com/xynova/docker-cifs-build

I have created a service inside

$ sudo vim /etc/systemd/system/mount.service

[Unit]
Description=Mount Share service
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutStartSec=0
ExecStart=/opt/bin/mount.cifs //192.168.10.4/Apps/pegasus/operaII/Data/C /ccc/smb -o domain=server-apps.continental.local,username=usernam,password=password,uid=0,gid=0

[Install]
WantedBy=multi-user.target

On reboot, I get this

Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "00-eno1.network" is unmasked
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 /run/systemd/network/00-eno1.network is not null or empty, refusing to unmask
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Writing drop-in unit "20-cloudinit.conf" to filesystem
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Writing file to "/run/systemd/system/etcd.service.d/20-cloudinit.conf"
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Wrote file to "/run/systemd/system/etcd.service.d/20-cloudinit.conf"
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Wrote drop-in unit "20-cloudinit.conf"
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "etcd.service" is unmasked
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "etcd2.service" is unmasked
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "fleet.service" is unmasked
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "locksmithd.service" is unmasked
Mar 08 10:21:24 araweelo kernel: CIFS VFS: Error connecting to socket. Aborting operation.
Mar 08 10:21:24 araweelo kernel: CIFS VFS: cifs_mount failed w/return code = -101
Mar 08 10:21:24 araweelo systemd[1]: Reloading.
Mar 08 10:21:24 araweelo mount.cifs[719]: mount error(101): Network is unreachable
Mar 08 10:21:24 araweelo mount.cifs[719]: Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Mar 08 10:21:24 araweelo systemd[1]: mount.service: Main process exited, code=exited, status=32/n/a
Mar 08 10:21:24 araweelo systemd[1]: Failed to start Mount Share service.
-- Subject: Unit mount.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mount.service has failed.
-- 
-- The result is failed.
Mar 08 10:21:24 araweelo systemd[1]: mount.service: Unit entered failed state.
Mar 08 10:21:24 araweelo systemd[1]: mount.service: Failed with result 'exit-code'.
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Restarting systemd-networkd
Mar 08 10:21:24 araweelo systemd[1]: Starting Garbage Collection for rkt...
-- Subject: Unit rkt-gc.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit rkt-gc.service has begun starting up.
Mar 08 10:21:24 araweelo systemd[1]: Reached target Multi-User System.
-- Subject: Unit multi-user.target has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit multi-user.target has finished starting up.
-- 
-- The start-up result is done.
Mar 08 10:21:24 araweelo systemd[1]: Started Garbage Collection for rkt.
-- Subject: Unit rkt-gc.service has finished start-up

I am able to manually run the service

$ sudo systemctl start mount.service
Warning: mount.service changed on disk. Run 'systemctl daemon-reload' to reload units.
khine@araweelo ~ $ sudo systemctl daemon-reload
khine@araweelo ~ $ df -h
Filesystem                                  Size  Used Avail Use% Mounted on
devtmpfs                                    3.4G     0  3.4G   0% /dev
tmpfs                                       3.5G     0  3.5G   0% /dev/shm
tmpfs                                       3.5G  428K  3.5G   1% /run
tmpfs                                       3.5G     0  3.5G   0% /sys/fs/cgroup
/dev/sda9                                   114G  4.7G  104G   5% /
/dev/sda4                                   985M  492M  442M  53% /usr
tmpfs                                       3.5G     0  3.5G   0% /tmp
tmpfs                                       3.5G     0  3.5G   0% /media
/dev/sda1                                   128M   61M   68M  48% /boot
/dev/sda6                                   108M   52K   99M   1% /usr/share/oem
//192.168.10.4/Apps/pegasus/operaII/Data/C  558G  236G  323G  43% /ccc/smb

from the logs i see Network is not reachable, how do i run the mount after the network has re-initialised, if this is the issue?

Best Answer

On CoreOS the network can be setup:

  • via Cloud Init
  • via static configuration by systemd

https://coreos.com/os/docs/latest/network-config-with-networkd.html

In your service, you might then want to change the After=network.target by Wants=network-online.target therefore your service will only kick in after a successful network configuration. If setting network via cloud-init, it should also answer the same dependancy.

Related Topic