/etc/fstab and cifs mount

You have a problem with Salix? Post here and we'll do what we can to help.
Post Reply
inukaze
Posts: 30
Joined: 24. Nov 2024, 18:42

/etc/fstab and cifs mount

Post by inukaze »

Hi there again on my job i need to access to shared folder, but samba wont wanna work, because of that i put the follow line on my /etc/fstab :

Code: Select all

//10.48.1.220/Tecnologia /media/Tecnologia cifs credentials=/etc/samba/credencial,_netdev,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777	0 0
the folder /media/Tecnologia, already exist, i and have permissions 0777 with chmod.
the credentials file have my username, password and domain
the "_netdev" is supose to wait for network device already start and have an ip (does not work i need)

i am using NetworkManager, because with Static IP, or with DHCP, i never get IP from DHCP, ironically, but with Network Manager works fine.
Someone knows if exist an network manager can be started in the system startup without wait reach the graphical system ?

I notice, the network manager wait my user session start to start network manager and get ip, why?

when is based on dhcp server, dhcp server assing the ip based on mac address, and for ethernet device and machine assign one ip address and the machine ever use the same, except when the user needs to make some network test.


For me the logical order should be something like this :
01 - start the network manager in system startup, before read the fstab file
02 - if the network is working try to mount the network shares inside the fstab file

Because actually for me looks like :
01 - try the network start ( if Network manager, just ignore it )
02 - meanwhile make the mounts inside on the fstab file, no matter if exist a network mount point just fail, because the network is not active
03 - reach the graphical system, and wait the user session start
04 - when the user session start ( on my case xfce desktop ) , startup the network device via NetworkManager

well , I have an idea for how to do a very forced search for this, for example:

Create a custom script to test the intranet connection
If it receives a "1", mount the shared folder

Edit the /etc/sudoers file
Assign execute permission without password for any user to my custom script

Although for that I would need to at least make Network Manager initiate the connection via DHCP as soon as the graphical environment starts, before any user logs in.
inukaze
Posts: 30
Joined: 24. Nov 2024, 18:42

My Solution for /etc/fstab and cifs mount

Post by inukaze »

Somehow i solved it through a few forced workarounds :

already i had create /media/cifs/Tecnologia like the local mount point for my remote mount point on local machine.

1 - i edit the /etc/sudoers file and at the end of file i add the follow line :

Code: Select all

#Permitirle y/o acceder al usuario "jquintero"
#Ejecutar el/los siguientes, comandos sin preguntar clave
#
# Ejemplo de sintaxis : 
# user_name ALL=(ALL) NOPASSWD:/usr/bin/apt update, /usr/bin/apt upgrade
#
jquintero ALL=(ALL) NOPASSWD:/bin/mount, /sbin/mount, /sbin/mount.cifs, /etc/samba/credencial, /usr/local/bin/carpcomp
i check on my /etc/sudoers file the follow things :

Code: Select all

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL:ALL) ALL

## Same thing without a password
# %wheel ALL=(ALL:ALL) NOPASSWD: ALL

## Uncomment to allow members of group sudo to execute any command
%sudo	ALL=(ALL:ALL) ALL
my user is member of groups wheel and/or sudo, on slackware the common is sudo groups does not exist, just wheel group

Code: Select all

gpasswd -a jquintero -g wheel

Code: Select all

gpasswd -a jquintero -g sudo
2 - i edit the file /etc/fstab and at the end i add the follow line :

Code: Select all

//10.48.1.220/Tecnologia /media/cifs/Tecnologia cifs credentials=/home/jquintero/.credencial,vers=default,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777	0		0
i create a file on /home/jquintero/.credencial with content similar to :
username=jquintero
password=the_already_set_password
domain=realm

after i use the follow commands

Code: Select all

sudo chown jquintero:sambashare /home/jquintero/.credencial
sudo chmod 0600 /home/jquintero/.credencial
3 - i create a file called "/usr/local/bin/carpcomp" (Carpeta Compartida) with the follow content ;

Code: Select all

#!/bin/bash

#Recomiendo establecer primero las variables globales en este caso son, RED, CONTADOR, SEGUNDOS, INTENTOS, LRU.

#Monturas CIFS :	Metodo alternativo para montar carpetas disponibles en la Red Local (Intranet), cuando no funciona mediante Samba como se espera
#				Para permitir eliminar archivos necesitas especificar :
#				file_mode=0777,dir_mode=0777,gid=1000,uid=1000
#				el (g,u)id=1000 es del usuario guest (en el caso de la distro en vivo Porteus)

RED=0
CONTADOR=0

IP="10.48.1.220"
PuntoDeMontajeRemoto="Tecnologia"
PuntoDeMontajeLocal="/media/cifs/Tecnologia"
CarpetaCompartida=$(ping -c 1 "$IP" | sed -n '5p' | cut -c 24-33)
Argumentos="credentials=/etc/samba/credencial,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777"
#argumentos_originales="vers=1.0,username=inukaze,password=inukaze,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"

# Cantidad de Segundos a Esperar hasta el proximo bucle
SEGUNDOS=60

#Detener la pruebas despues de X intentos
INTENTOS=3

# Localizador de recursos uniformes (LRU / URL ). 
# Utiliza una direccion LRU (No debe ser 127.0.0.1) confiable 
# Una que siempre responda positivamente a nivel de intranet o internet
LRU=10.48.1.28

#Hasta que el CONTADOR sea igual a la cantidad de intentos, Hacer lo siguiente :
until [ $CONTADOR -eq "$INTENTOS" ] 
do
# Sumarle 1 al CONTADOR
let CONTADOR=CONTADOR+1
ESTADO_LRU=$(ping -c 1 "$LRU" | sed -n '5p' | cut -c 24-24)		#NOTA, esta direccion "10.48.1.28" es la del DNS Interno.
#Si el ESTADO de la LRU es Igual a 1 (Respuesta Recibida Satisfactoriamente)
	if [ $ESTADO_LRU -eq 1 ]
	then
		#Entonces RED sera igual a 1
		RED=1
		#Si RED es igual a 1 (Se encuentra aninada dentro de la variable "ESTADO_LRU")
			if [ $RED -eq 1 ]
				#Entonces el CONTADOR sera igual a la cantidad de INTENTOS
				then
				CONTADOR=$INTENTOS
				#Si no, RED sera igual a 0
				else
				RED=0
				#Fin de la condicion "Si" (La que esta anidada dentro del "ESTADO_LRU"
			fi
		#Si no (Del "ESTADO_LRU")
		else
		#Esperar la siguiente cantidad de SEGUNDOS :
		sleep $SEGUNDOS
	#Fin de la condicion "Si" (La que esta anidada dentro del "Hasta" [Until])
	fi
done


if [ $RED -eq 1 ]
    then
	#Primero crear carpeta(s) para el/los punto(s) de montaje(s)
	mkdir -p "$PuntoDeMontajeLocal"
	#Segundo Montar
	#mount -t cifs "//$IP/$PuntoDeMontajeRemoto" "$PuntoDeMontajeLocal" -o "$Argumentos"        #Desactivado indica "mount.cifs not have permission" / "mount.cifs (Error: 13) cannot read file /etc/samba/credencial, " mount.cifs (Error: 95) : Operation not allowed" #Errors without sense.
	#
	#Montar basado en la linea de fstab :
	#//10.48.1.220/Tecnologia /media/cifs/Tecnologia cifs credentials=/home/jquintero/.credencial,vers=default,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777	0		0
	sudo mount -a
    else
          exit 1 # -bailing, had to many tries
fi
Note this code is source from -> https://www.linuxquestions.org/question ... ost4689428
i just modify the things i need and translate the rest.

4 - i use the follow commands like root user :

Code: Select all

chmod a+o+x /usr/local/bin/carpcomp
This is just for solve " udevd[608]: specified group 'colord' unknown "

Code: Select all

groupadd -g 303 colord ;  useradd -d /var/lib/colord -u 303 -g colord -s /bin/false colord
This i saw on some site

Code: Select all

chmod 6755 /sbin/mount.cifs
i can't remember where :

https://unix.stackexchange.com/question ... -and-chown

https://linuxconfig.org/allow-sudo-user ... t-password

https://linuxhandbook.com/sudo-without-password/

https://askubuntu.com/questions/159007/ ... a-password

https://askubuntu.com/questions/767422/ ... red-folder

https://askubuntu.com/questions/1262249 ... nt-message

https://www.claudiokuenzler.com/blog/11 ... rn-code-13

https://forums.gentoo.org/viewtopic-t-9 ... a69f27a1a1

https://discussion.fedoraproject.org/t/ ... ted/112143

https://www.linuxquestions.org/question ... ost5883611

In this last site i saw something interesting like :
If this matters for anyone, this trick also succeeded in conditions slightly different from that above:

- Slackware 14.1 multilib
- cifs-utils 5.5

Anyway, the main procedure was:

- build/install libcap-ng 0.7.3 from slackbuilds.org (14.1, x64)
- rebuild cifs-utils 5.5. Here an additional trick was needed: including "-Wno-unused-result" in CFLAGS before ./configure
- after install, run chmod 6755 /sbin/mount.cifs

5 - I add to autostart on my xfce desktop, and trigger when my user is logged to use the script /usr/local/bin/carpcomp in max 3 minutes, the share folder from cifs is mounted correctly
Post Reply