October 23, 2017, 02:57:22 am
News:
Pages: [1] 2 3
Print
Author Topic: Howto: Mount your network shares on bootup  (Read 40968 times)
greyback
Administrator
Hero Member
*****
Posts: 1639


View Profile
« on: May 01, 2007, 04:29:09 pm »

Note: This guide applies to OSD firmware versions 3.33-1.** and lower (aka Torfu). The 3.33-2.** firmware (aka Arizona) incorporates functionality that replaces this hack.
-G


Howto: Mount your network shares on bootup

Hey all,
I've managed to figure out how to get the OSD to load network shares on bootup, so you'll never have to type a username & password using the remote again! I'm no hacker, so this is very rough, but it works nicely for me. Here's a brief jist of how it's done:

It appears the directory /mnt/OSD is permanent storage, a power cycle does not erase its contents. Also, the /etc/init.d/rc bootup script actually looks for a shell script named rc.user in this directory & runs it if it exists - so all you've to do is figure out the mount commands for your shares, put them in this file & off you go!

Naturally, you'll need to be telnetted into the OSD for this. As a reminder, the username is "root" with either no password asked (for older fw), or else try "pablod".

Samba/Windows shares
The mount command looks like:
Code:
mount.cifs //<SERVER_ADDY>/<SHARE_FOLDER> /media/<MOUNT_POINT>  -o user=USERNAME,pass=PASSWORD,rw,nolock
where:
SERVER_ADDY is the IP address or hostname of the server.
SHARE_FOLDER is the name of the folder that's being shared.
MOUNT_POINT is an empty folder you wish for the share to appear (don't forget to create this first!)
USERNAME & PASSWORD are the details you use to connect to this share

So for example1:
Code:
mount.cifs //192.168.1.2/Video /media/Video -o user=joe,pass=bloggs,rw,nolock


NFS shares
Those with linux NFS shares setup can easily mount them using:
Code:
mount -t nfs <SERVER_ADDY>:<ABS_PATH_TO_SHARE> /media/<MOUNT_POINT>  -o rw,nolock,tcp,nfsvers=3
where:
SERVER_ADDY is the IP address or hostname of the server.
ABS_PATH_TO_SHARE is the absolute path of the folder that's being shared, matching that in /etc/exports on your server.
MOUNT_POINT is where the share appears.
Eg:
Code:
mount -t nfs 192.168.1.2:/home/Tunes /media/Tunes -o rw,nolock,tcp,nfsvers=3

Writing the bootup script
Once you've figured out the mount command(s), we just need to get them running automatically. Now initially I simply tried to stick them into /mnt/OSD/rc.user, but these mount commands didn't work correctly. While "mount" showed the resources correctly, trying to access them resulted in a server timeout each and every time. I guess that while rc.user is being run, other init process haven't completed which interfere with mount. So I tried to insert a "sleep 20" command before the mounts, which also didn't help confusingly. Eventually I did the following:

In /etc/OSD/rc.user (create if necessary), put the lines:
Code:
#!/bin/sh
sh bootscript.sh &

Then create a file in /etc/OSD called bootscript.sh, where you first issue a "sleep 20" command to wait for init process to finish, then run your mount commands. Also don't forget to make the mount point(s) first, as they vanish on reboot. You can use vi to edit text files on the OSD. Here's a crude example of bootscript.sh:
Code:
#!/bin/sh
sleep 20;
mkdir /media/Videos;
mkdir /media/Tunes;

mount.cifs //192.168.1.2/Video /media/Video -o user=joe,pass=bloggs,rw,nolock;

mount -t nfs 192.168.1.2:/home/Tunes /media/Tunes -o nolock,tcp,soft,intr,nfsvers=3;

Now for safety sake, test your bootscript.sh by running "sh ./bootscript.sh" to ensure the script runs correctly & has no syntax errors. If it works correctly, just reboot your OSD and you should see your network shares2 right there under Play|Browse! Now this is no means perfect, so please play around and if you've suggestions please let me know.
Enjoy!
-G

Note 1: entering this command sometimes gives a "could not update mount table" error, however the mount works! I'm guessing it's trying to update mtab which is read-only. No harm comes from this.

Note 2: if for some reason your mount commands fail, your mount point will still exist as simpe folders, and trying to record to them will quickly go wrong! A more elegant script would stick each mount in an if-else statement & clean up such errors. I've just kept it simple, such things are an exercise for the reader Smiley

EDIT (26/10/07): Extended sleep interval to 20 seconds as OSD initialisation is taking longer. Also recommended testing the bootscript manually before saving & rebooting, as corrupt bootscript.sh has been reported to interfere with bootup.
« Last Edit: April 15, 2008, 12:04:32 pm by greyback » Logged
forgeflow
Newbie
*
Posts: 26


View Profile
« Reply #1 on: May 01, 2007, 05:33:14 pm »

right on. This should help people trying to mount OS X SMB shares on the OSD.

OSD for Dummies time - how about a step by step guide of how to telnet into the OSD. Wink
Logged
dotslashlycos
Jr. Member
**
Posts: 56


View Profile WWW
« Reply #2 on: May 01, 2007, 06:58:39 pm »

haha, awesome ive been asking about this for a while now.. i never would have guessed that rc.d already looks for an init script in /mnt/OSD

woot!
Logged
dotslashlycos
Jr. Member
**
Posts: 56


View Profile WWW
« Reply #3 on: May 01, 2007, 07:04:15 pm »

Note 2: if for some reason your mount commands fail, your mount point will still exist as simpe folders, and trying to record to them will quickly go wrong! A more elegant script would stick each mount in an if-else statement & clean up such errors. I've just kept it simple, such things are an exercise for the reader Smiley

An if/else statement would look something like this:

if [ -e /media/Movies ]
then
        echo "Movies Already Exists - not Mounting"
else
        echo "Mounting Movies"
        mkdir /media/Movies
        mount -t cifs //192.168.1.20/movies /media/Movies -o user=guest,pass=pass
fi
Logged
greyback
Administrator
Hero Member
*****
Posts: 1639


View Profile
« Reply #4 on: May 02, 2007, 05:13:56 am »

OSD for Dummies time - how about a step by step guide of how to telnet into the OSD. Wink
Not a bad idea. I find the OSD is a great introduction to linux, since the OS is small & readonly, it's hard to break it!

There's still an issue where OS X shares don't work properly with the OSD. I've not figured out a workaround yet.

dotslashycos: Will that work? The /media/Movies directory disappears upon reboot. I'm more worried about mount returning failure. I'm a bit of a newbie at bash, but am guessing *something* like:
Code:
mkdir /media/Movies;
if mount -t cifs //192.168.1.20/movies /media/Movies -o user=guest,pass=pass;
then
      echo "Mount successful";
else
      echo "Mount failed, cleaning up";
      rmdir /media/Movies;
fi
-G
« Last Edit: May 02, 2007, 04:03:01 pm by greyback » Logged
yanvrno
Full Member
***
Posts: 110


View Profile
« Reply #5 on: May 03, 2007, 09:50:32 am »

using 3.28 1.00 I tried this mounting procedure
I was so excited when I read you could store a script on the OSD system. But I am seeing a problem.
I created a rc.user file with my script and put it in  /mnt/OSD

I find that it creates the directories but they cannot be accessed, I notice using the OSD screen menu when I view the media directory I see an X in a box next to the two new directory names.

I can paste the following  same script using telnet and it works fine, though it creates an additional directory with the same names. So for some reason the boot up rc.user script is read, its just not working for me.

mkdir /media/tiger
mkdir /media/debian
mount.cifs //192.168.1.33/OSDVideo /media/tiger -o user=guest,pass=password,rw,nolock
mount.cifs //192.168.1.101/osd /media/debian -o user=guest,pass=password,rw,nolock

What am I missing?
« Last Edit: May 03, 2007, 09:59:08 am by yanvrno » Logged
dotslashlycos
Jr. Member
**
Posts: 56


View Profile WWW
« Reply #6 on: May 03, 2007, 10:48:33 am »

can you post your rc.user script file?
Logged
greyback
Administrator
Hero Member
*****
Posts: 1639


View Profile
« Reply #7 on: May 03, 2007, 12:33:35 pm »

That sleep 10 command is vital. Mounts will fail at the time rc.user is called, hence the delay. You may need to extend it, but 10 seconds works for me.
-G
Logged
yanvrno
Full Member
***
Posts: 110


View Profile
« Reply #8 on: May 03, 2007, 02:13:54 pm »

Heres my rc.user script

#!/bin/sh
sh bootscript.sh &
sleep 10

mkdir /media/tiger
mkdir /media/debian
mount.cifs //192.168.1.33/OSDVideo /media/tiger -o user=guest,pass=password,rw,nolock
mount.cifs //192.168.1.101/osd /media/debian -o user=guest,pass=password,rw,nolock



I still get two directories with an x in a box next to them when I view them in the OSD menu
If I  paste the following script at the    ~ #   prompt in telnet it creates two new directories with the same names and they now mount fine

mkdir /media/tiger
mkdir /media/debian
mount.cifs //192.168.1.33/OSDVideo /media/tiger -o user=guest,pass=password,rw,nolock
mount.cifs //192.168.1.101/osd /media/debian -o user=guest,pass=password,rw,nolock
 
I did notice the rc.user file is   -rwxr-Sr-t   (Sorry Im not aware of what the S attribute does)

Thanks for your help


Logged
dotslashlycos
Jr. Member
**
Posts: 56


View Profile WWW
« Reply #9 on: May 03, 2007, 02:28:18 pm »

ah yeah you're calling a non-existent boot script and then calling the mount commands right inside the rc.user file.  You're gonna want to separate that out into two different files:

/mnt/OSD/rc.user:
Code:
#!/bin/sh
sh /mnt/OSD/mount_script.sh &

/mnt/OSD/mount_script.sh:
Code:
#!/bin/sh
sleep 10

mkdir /media/tiger
if mount.cifs //192.168.1.33/OSDVideo /media/tiger -o user=guest,pass=password,rw,nolock
then
      echo "Mounting tiger successful"
else
      echo "Mounting tiger failed, cleaning up"
      rmdir /media/tiger
fi

mkdir /media/debian
if mount.cifs //192.168.1.101/osd /media/debian -o user=guest,pass=password,rw,nolock
then
      echo "Mounting debian successful"
else
      echo "Mounting debian failed, cleaning up"
      rmdir /media/debian
fi

The reason behind this is that rc.user gets called pretty early on, so you want it to call the mount_script.sh file (in the background - hence the &) and then right away continue running the rest of the init processes.  Meanwhile, the mount_script.sh will have been called and sleep for a bit (10 seconds) while the rest of the init processes are running. 

(I also added an "if/else" statement so that if the mount fails, the directory will be removed so you won't have an extra folder hanging around.) 

The way you were doing it was forcing the rest of the init scripts to wait until after you had already tried (and failed) to mount your remote shares. 

hope this clears some things up.
« Last Edit: May 03, 2007, 02:52:10 pm by dotslashlycos » Logged
greyback
Administrator
Hero Member
*****
Posts: 1639


View Profile
« Reply #10 on: May 03, 2007, 03:08:25 pm »

yanvrno: sorry, the guide was a lil vague around that, I've edited it slightly so I hope it's clearer.

dotslashlycos: spot on!
-G
Logged
yanvrno
Full Member
***
Posts: 110


View Profile
« Reply #11 on: May 03, 2007, 05:17:28 pm »

Sorry guys I'm still having the same issue.
Still creates the directories but when I try to access them. It says "No such file or directory" even though I can see it as a directory

I was so sure that was the problem too.
I copy and pasted what you advised. When that did not work I took out the if then statements, still same issue

my rc.user script
#!/bin/sh
sh /mnt/OSD/mount_script.sh &

my mount_script.sh script
#!/bin/sh
sleep 10

mkdir /media/tiger
mkdir /media/debian
mount.cifs //192.168.1.33/OSDVideo /media/tiger -o user=guest,pass=password,rw,nolock
mount.cifs //192.168.1.101/osd /media/debian -o user=guest,pass=password,rw,nolock

Thanks for your help, dont give up, lol
Logged
greyback
Administrator
Hero Member
*****
Posts: 1639


View Profile
« Reply #12 on: May 03, 2007, 05:20:54 pm »

The following command allows you to mount Mac OS X shares (note: called "Windows Sharing" in System Preferences->Sharing - "Personal File Sharing" is Apple only), even with firewall up:
Code:
mount.cifs //<SERVER_ADDY>/<SHARE_FOLDER> /media/<MOUNT_POINT> -o username=<USERNAME>,password=<PASSWORD>,port=139

Macs with firewall up allows Samba access only through port 139. Linux always tries port 445 first, only after timeout does it try port 139. I dunno why OSDmain fails to mount Mac shares correctly, perhaps it only tries 445, but this is a workaround until they sort it out.
-G
Logged
greyback
Administrator
Hero Member
*****
Posts: 1639


View Profile
« Reply #13 on: May 03, 2007, 05:37:46 pm »

Hey yanvrno,
So the script is creating the directories, but when you go into them, the directory is empty, is that right? Or is it that when you are in /mnt/tmpfs/media and do an ls, there's a long pause, followed by an error?

Let's simplify, just create one directory, and one mount command. Reboot. Any luck then? If not, telnet in, run "dmesg | more" and see if there's any errors (near the bottom) referring to mount.cifs failing.

Your bootscript definitely works if you run it manually? (I put in the mkdir -p so it doesn't give an error if the directory already exists). Have you tried putting sleep to 20?

We'll get this working!
-G
Logged
greyback
Administrator
Hero Member
*****
Posts: 1639


View Profile
« Reply #14 on: May 03, 2007, 06:00:11 pm »

Also, one can see the errors output by the mount commands at bootup by having *only* this in /mnt/OSD/rc.user:

Code:
#!/bin/sh
sh /mnt/OSD/bootscript.sh > /mnt/OSD/messages.txt 2>&1 &

This will output all messages, errors or otherwise into "messages.txt" to help you see what might be going wrong. I/O errors and server timeouts all suggest to me that "sleep 10" is not a long enough delay.
-G
Logged
Pages: [1] 2 3
Print
Jump to: