[Solved] Connect network share at boot

Post here if you are a new Porteus member and you're looking for some help.
JeWe
Ronin
Ronin
Posts: 3
Joined: 23 Aug 2018, 19:16
Distribution: 4.0

[Solved] Connect network share at boot

Post#1 by JeWe » 23 Aug 2018, 19:29

Hi,

I'm new to Porteus and installed 4.0 on a 9 year old Igel thinclient, runs like a charm :-)

Now I want to connect a network share (Windows domain, on a Synology NAS) at boot up. Therefore I edited
/etc/rc.d/rc.local with this onliner:
mount.cifs \\IP-Address/share /mnt/share -o /root/.smbcredentials

.smbcredentials looks like this:
user=windows-user
password=password
domain=windows-domain

If I'm starting /etc/rc.d/rc.local with guest account, mount.cifs isn't found. If I do this as root, everything works as it should.
Rebooting the system, the network share isn't connected. I copied /etc/rc.d/rc.local to rootcopy-dir with no luck.

Any ideas? I would be really happy to get this running.

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Connect network share at boot

Post#2 by Ed_P » 24 Aug 2018, 01:10

mount.cifs is not a guest command.

Code: Select all

guest@porteus:~$ mount.cifs
bash: mount.cifs: command not found
guest@porteus:~$ su
Password: 
root@porteus:/home/guest# mount.cifs

Usage:  mount.cifs <remotetarget> <dir> -o <options>
Would a sudo command help? Maybe a script with the sudo command that the /etc/rc.d/rc.local file would reference.

mynetshr.sh

Code: Select all

#!/bin/sh
echo guest | sudo -S mount.cifs \\IP-Address/share /mnt/share -o /root/.smbcredentials   > /dev/null 2>&1 &
:unknown:
Ed

User avatar
Blaze
DEV Team
DEV Team
Posts: 3869
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus current ☯ all DEs ☯
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

Connect network share at boot

Post#3 by Blaze » 24 Aug 2018, 05:10

Hi JeWe.
Welcome on the board!
How about setuid?
Open terminal and run these commands:

Code: Select all

su
toor
chmod u+s /sbin/mount.cifs
Linux 6.6.11-porteus #1 SMP PREEMPT_DYNAMIC Sun Jan 14 12:07:37 MSK 2024 x86_64 Intel(R) Xeon(R) CPU E3-1270 v6 @ 3.80GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Navi 23 [Radeon RX 6600] [1002:73ff] (rev c7) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

JeWe
Ronin
Ronin
Posts: 3
Joined: 23 Aug 2018, 19:16
Distribution: 4.0

Connect network share at boot

Post#4 by JeWe » 24 Aug 2018, 10:25

Thanks for your answers!

@Ed
Not sure, if I get this right. I made the little shell script and saved it in /home/guest. Then I edited /etc/rc.d/rc.local
sh /home/guest/mynetshr.sh

After a reboot, network share isn't mounted. With user guest, I can start rc.local or the script mynetshr.sh. No effect.

@Blaze
mount.cifs already got enough permission (755). As @Ed stated, I can't execute this command, so I simply copied it to /bin.
Execute my command, it says
Permission denied: No match for Mountpoint found in /etc/fstab
Quite clear, guest doesn't have access to /root
Executing mount.cifs without any option works.

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Connect network share at boot

Post#5 by Ed_P » 24 Aug 2018, 14:11

JeWe did you make the script executable.

Code: Select all

chmod +x mynetshr.sh
Test it by executing it in a terminal window.

Code: Select all

./mynetshr.sh
If it doesn't work remove the redirect at the end so any error msgs will be visible.

The copy you have in /bin should be removed so it executes the correct version.
Ed

jssouza
Legendary
Legendary
Posts: 1165
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm

Connect network share at boot

Post#6 by jssouza » 24 Aug 2018, 15:01

JeWe, rc.local is executed as root at the end of bootup, so it is probably not a permission issue.
However, during boot up, the PATH is not set (since root user has not yet logged in). Hence you need to call the mount.cifs command using the full path, that is: /sbin/mount.cifs

Some other things:
1. In your command, you start with \\IP-Address. The mount.cifs example I saw in the manual has forward slashes //.
2. Also, from the manual it does not say if the -o options can come from a file. Try passing it directly.
3. You are trying to mount at /mnt/share. By default Porteus does not have this directory. Is this directory already present in your system during bootup? If not, you need to also create this directory in your rc.local before you mount it.

Code: Select all

/bin/mkdir /mnt/share
Maybe one of the above also could have made the command to fail at bootup. It would also be helpful if you redirect stdout and stderr of the command to a file, so that if the command still fails, you can read out the file to see what error it says.

So, put this in you rc.local (after you create /mnt/share if that does not exist) and copy it to rootcopy:

Code: Select all

/sbin/mount.cifs //IP-Address/share /mnt/share -o user=windows-user,password=password,domain=windows-domain &> /root/mount_log.txt

User avatar
Blaze
DEV Team
DEV Team
Posts: 3869
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus current ☯ all DEs ☯
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

Connect network share at boot

Post#7 by Blaze » 24 Aug 2018, 17:23

JeWe, open terminal and run these commands:

Code: Select all

su
toor
mkdir /media/share
echo -e username=windows-user\\npassword=password\\ndomain=windows-domain > /home/guest/.smblocal1
chmod 400 /home/guest/.smblocal1
echo 'echo -e \\n# Local partitions:\\n//IP-Address/share /media/share cifs credentials=/home/guest/.smblocal1,dir_mode=0777,file_mode=0777,users 0 0 >> /etc/fstab' >> /etc/rc.d/rc.local
chmod u+s /sbin/mount.cifs
cat /dev/null > ~/.bash_history && history -c
reboot
Use /media path for mount your Windows partitions, because you will see your mounted partition at the left sidebar of your file manager.
JeWe wrote:
24 Aug 2018, 10:25
mount.cifs already got enough permission (755)

Code: Select all

-rwxr-xr-x 1 root root  39560 сен 27  2017 /sbin/mount.cifs*
With this permission you not able to mount partitions as guest user
This program is not installed setuid root - "user" CIFS mounts not supported.
but if you apply setuid via chmod 4755 /sbin/mount.cifs you will able to do this.
JeWe wrote:
24 Aug 2018, 10:25
I can't execute this command, so I simply copied it to /bin.
:%)... do not do this.

Cheers
Linux 6.6.11-porteus #1 SMP PREEMPT_DYNAMIC Sun Jan 14 12:07:37 MSK 2024 x86_64 Intel(R) Xeon(R) CPU E3-1270 v6 @ 3.80GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Navi 23 [Radeon RX 6600] [1002:73ff] (rev c7) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

JeWe
Ronin
Ronin
Posts: 3
Joined: 23 Aug 2018, 19:16
Distribution: 4.0

Connect network share at boot

Post#8 by JeWe » 28 Aug 2018, 10:22

Really big thanks to everyone for your kind help!

@jssouza
Logging the output of the mount leads to the solution:
mount error (101): Network is unreachable

So I followed this one:
https://superuser.com/questions/1180988 ... -of-system

Created a script and started it from /etc/rc.d/rc.local, works!

Case closed, surely I'll be back with other dumb questions :-)

Post Reply