OpenRC / openrc

The OpenRC init system
BSD 2-Clause "Simplified" License
1.48k stars 247 forks source link

/etc/init.d/netmount is not compatible with Alpine (cifs fstab mount) #552

Open GrumpyMeow opened 2 years ago

GrumpyMeow commented 2 years ago

I'm migrating my LXC containers to Alpine as they are super light-weight. I ran into trouble with mounting cifs/samba shares during boot. I've defined the shares in the /etc/fstab file and also added the "_netdev" parameter. I guess this setup is not very common as i noticed there are multiple issues when running this script in Alpine in a LXC container. My current solution was to strip the script /etc/init.d/netmount down to:

depend() {
    need networking
}

start() {
   mount /mnt/.....
}

stop() {
  umount /mnt/....
}

For instance the command umount -a -O _netdev is not available in the Alpine version of umount.

vapier commented 2 years ago

the -O _netdev code path is only run if the earlier unmount failed, so you prob want to look into that

since our mountinfo command supports --netdev, i'm not sure why we still need the -O _netdev fallback. not that i see a big deal with relying on this option since util-linux has supported it forever.

GrumpyMeow commented 2 years ago

Thank you for your reply.

I'll try to pinpoint the exact origin of the problems and post it on this thread.

I suspect it has got something to do with that I try to do the binding in a LXC containers (in Proxmox). Maybe some services are not available in the container...

dermotbradley commented 2 years ago

For instance the command umount -a -O _netdev is not available in the Alpine version of umount.

As a side-note, I raised a "crude" fix for this several months ago: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/35149

A more correct fix was written by another Alpine dev (https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/35484) but not yet applied in Alpine Edge as he was waiting for upstream Busybox to accept the fix: http://lists.busybox.net/pipermail/busybox/2022-June/089769.html

sbochnak commented 1 year ago

Hi, I have had very similar situation: a container in proxmox, in which I wanted to mount a cifs share at a boot time. Architecturally sound solution seemed to use etc/fstab entry and netmount service from openrc - as described here and in couple of fora. And it did not work.

The solution:

  1. make netmount launch AFTER network service by doing one of the two:

    either edit /etc/init.d/netmount to comment out line keyword -docker -jail -lxc -prefix -systemd-nspawn -vserver

Explanation: This line EXCLUDES netmount from any openrc dependencies (launch sequencing), making netmount being started before net is started. (see openrun-rc(8) man page.

or edit /etc/rc.conf rc_sys variable from "lxc" to "".

I have tested script edit and it works. The disadvantage is I went against openrc recommendations. Editing rc.conf would be in line with recommendations, but its potential scope of influence is broader, and I had not time to check.

  1. make netmount dependent on "net" by uncommenting/adding the following line in /etc/conf.d/netmount

rc_need=net

Explanation: This should work regardless of the actual networking service used in Alpine openrc (default, dhcpcd). More on that in "Sources" section below.

  1. add entry to /etc/fstab like this: //server/Music /mnt/music cifs user=samba-user,pass=secret,_netdev 0 0

Note: fstab line can be improved e.g. by moving user and pass to credential file. More on that in "Sources" section below.

  1. At Proxmox UI:

    • make container privileged in Proxmox (unmark checkbox at creation) and/or
    • add options | features mount CIFS. Otherwise mount -t cifs will not work for no apparent reason.
  2. Install additional packages needed in Alpine (nano, cifs-utils, util-linux, see source below).

  3. reboot - and check if the folder is mounted and ready for use.

Good luck in further works.

stan

Sources (thanks!): https://www.hiroom2.com/2017/08/21/alpinelinux-3-6-cifs-utils-en/ https://techoverflow.net/2021/07/06/how-to-automount-cifs-smb-on-alpine-linux/ https://wiki.gentoo.org/wiki/OpenRC#Logging https://manpages.debian.org/testing/openrc/openrc-run.8.en.html https://wiki.gentoo.org/wiki/Dhcpcd https://forum.proxmox.com/threads/container-options-features-cifs.96915/

roehrijn commented 1 year ago

@sbochnak @GrumpyMeow I had similar issue and solved it by removing the -lxc param from the keyword call. See also my recent post on servervault.com