utahjazz09
Posts: 3
Joined: Sun Aug 02, 2020 3:12 pm

Mounting a network drive on pi 4 for a Plex Media Server

Tue Aug 04, 2020 12:37 am

Hello,

So I have a network drive which houses my media files. I used to utilize another working set up (Control4) to access this media on any screen in the house. I've since moved and left Control4 behind, thankfully. I am now attempting to recreate the ability to access my media on any screen (Plex clients) in my new house using this same network drive along with Plex Media Server running on my pi 4. I think I am just about there, but I am having trouble getting my network drive mounted on my pi 4. I want this mount to occur automatically upon boot each time. Here is what I have done thus far:

updated my pi 4
installed Plex on my pi 4
Set up static IP on my pi 4
Set up new folder /home/pi/mynetworkdrive on my pi 4

This is where I am stuck:
Edited and added to /etc/fstab with the following line: //192.168.x.xxx/<file folder> /home/pi/mynetworkdrive cifs <username>, ,_netdev 0 0
I'm sure I have some argument and syntax errors.

First off, when I run sudo mount /home/pi/mynetworkdrive the system returns:
Password for root@//192.168.x.xxx/<file name>
It waits for me to enter the password. There is no password set on my network drive to to access this folder, only a user name.
When I hit enter at the password question, I get the following error:
mount error(22): Invalid argument

I can successfully run 'map network drive' to mount this drive in Windows with the following:
Drive: Z
Folder: //192.168.x.xxx/<file folder>
Then login with my credentials. Again, there is only a user name to access this folder. The password field is blank.

What am I doing wrong. Any help would be greatly appreciated. Thank you in advance.

nliviu
Posts: 32
Joined: Tue Jun 23, 2020 1:24 pm
Location: Romania

Re: Mounting a network drive on pi 4 for a Plex Media Server

Tue Aug 04, 2020 8:59 am

I don't have a passwordless samba share, but this works for me

Code: Select all

//192.168.x.xxx/<file folder> <local_mount_point> cifs user=<username>,pass=<password> 0 0
Maybe you can leave the <password> field empty, i.e. "pass=".

utahjazz09
Posts: 3
Joined: Sun Aug 02, 2020 3:12 pm

Re: Mounting a network drive on pi 4 for a Plex Media Server

Wed Aug 05, 2020 1:57 am

Thank you for your response. I tried as you suggested and still no luck. To me it seems like I'm missing argument(s) in the command line or the syntax is incorrect. Any other ideas?...

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Mounting a network drive on pi 4 for a Plex Media Server

Wed Aug 05, 2020 6:25 am

What brand is your "network drive"? Does it support Network File System (NFS) as well as CIFS/Samba?

If it does support that, enable it. It's a million times easier to mount an NFS share on a Linux system than a CIFS share. An NFS share also works with the Unix (owner, group, world) permissions so data security is easier to deal with.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jiml8
Posts: 25
Joined: Wed Aug 05, 2020 6:27 pm

Re: Mounting a network drive on pi 4 for a Plex Media Server

Thu Aug 06, 2020 12:50 am

I infer from this that you are using smb/cifs.

Take a look at smbclient. This is a command line utility for linux that will let you open and access a share.

I am not suggesting you use it permanently, but you can configure it to give you informative error messages which will help you with your debugging.

utahjazz09
Posts: 3
Joined: Sun Aug 02, 2020 3:12 pm

Re: Mounting a network drive on pi 4 for a Plex Media Server

Thu Aug 06, 2020 1:34 am

So, here is more detailed info on my "network drive"... It is a Zatabit media Server. I know it runs on some form of Linux. I honestly do not know if it supports NFS, but I would guess it does and it's likely enabled already. Part of the Zatabit's design was to accept shares, most notably with the Control4 system. Making these assumptions, can I test a NFS share easily to see if it works? How would I go about doing this? Thank you so much for the help.

User avatar
TommyG007
Posts: 63
Joined: Fri Jun 26, 2020 4:30 pm
Location: South Wales, UK

Re: Mounting a network drive on pi 4 for a Plex Media Server

Sun Aug 09, 2020 4:25 pm

I had a similar issue when trying to auto mount a network share on my Pi4 running Raspberry OS, I tried the fstab method and although it did work, the NAS folder wouldn't properly mount to my /home/pi/OMVNAS folder without first manually clicking on the network share icon in the top left of the file explorer window, so in the end I tried a different method. Here's what I did to get mine working successfully.

I'm in no way a Linux expert, so the way I got it working is likely not the best way, but I thought I'd share the method anyway because it does work for me.

I created the following script for mounting my NAS share folder to my /home/pi/OMVNAS folder, named it Map-OMVNAS.sh and saved it in my Documents folder, then made it executable. My NAS share doesn't require a password to connect.

Code: Select all

sudo mount.cifs //10.82.107.2/Shared /home/pi/OMVNAS -o user=root,password="" && exit

I then created a cron job (crontab -e) with the following script to automatically run the Map-OMVNAS.sh script at startup, with a 30 second delay.

Code: Select all

@reboot sleep 30;/home/pi/Documents/Map-OMVNAS.sh

I set this up a few weeks ago now and I haven't had a single issue with it, after every reboot, the NAS folder is mapped correctly a few seconds after the desktop loads up. :D

jiml8
Posts: 25
Joined: Wed Aug 05, 2020 6:27 pm

Re: Mounting a network drive on pi 4 for a Plex Media Server

Mon Aug 17, 2020 8:46 pm

TommyG007 wrote: I had a similar issue when trying to auto mount a network share on my Pi4 running Raspberry OS, I tried the fstab method and although it did work, the NAS folder wouldn't properly mount to my /home/pi/OMVNAS folder without first manually clicking on the network share icon in the top left of the file explorer window, so in the end I tried a different method. Here's what I did to get mine working successfully.

I'm in no way a Linux expert, so the way I got it working is likely not the best way, but I thought I'd share the method anyway because it does work for me.

I created the following script for mounting my NAS share folder to my /home/pi/OMVNAS folder, named it Map-OMVNAS.sh and saved it in my Documents folder, then made it executable. My NAS share doesn't require a password to connect.

Code: Select all

sudo mount.cifs //10.82.107.2/Shared /home/pi/OMVNAS -o user=root,password="" && exit

I then created a cron job (crontab -e) with the following script to automatically run the Map-OMVNAS.sh script at startup, with a 30 second delay.

Code: Select all

@reboot sleep 30;/home/pi/Documents/Map-OMVNAS.sh

I set this up a few weeks ago now and I haven't had a single issue with it, after every reboot, the NAS folder is mapped correctly a few seconds after the desktop loads up. :D
To do it "officially" you should use systemd. The advantage to using systemd is that you will have proper mount/dismount capability on startup and shutdown, and systemd will manage it for you. You won't notice any difference over the way you are doing it now, except when things go wrong and the bootup does not go right.

To use systemd, you would create a service in /etc/systemd/system/

I do something very similar to what you want on my workstation. Here is my mountnas.service in /etc/systemd/system/

Code: Select all

[Unit]
Description = Mount jssnas iscsi share
Wants = display-manager.service
After = NetworkManager-wait-online.service network.target

[Service]
ExecStart = /usr/local/bin/mountNAS

[Install]
WantedBy = graphical.target
This would work for you, once you change the description.

Then as root, take the command line you presently have in your cron, and put it in the file /usr/local/bin/mountNAS.

chmod a+x mountNAS to make that file executable.

Then, the following command:
systemctl enable mountnas

And the mounting of the share will happen on startup, handled by systemd.

To handle unmounting on shutdown, here is the unmountnas.service file:

Code: Select all

[Unit]
Description = Unmount jssnas iscsi share
Before = shutdown.target
DefaultDependencies = yes

[Service]
ExecStart = /usr/local/bin/unmountNAS

[Install]
WantedBy = exit.target
with a similarly installed unmount script.

Now, what you are doing works fine. But if you would prefer to do it the "official" way, this is how you would do that.

User avatar
TommyG007
Posts: 63
Joined: Fri Jun 26, 2020 4:30 pm
Location: South Wales, UK

Re: Mounting a network drive on pi 4 for a Plex Media Server

Mon Aug 17, 2020 9:21 pm

jiml8 wrote:
Mon Aug 17, 2020 8:46 pm
To do it "officially" you should use systemd. The advantage to using systemd is that you will have proper mount/dismount capability on startup and shutdown, and systemd will manage it for you. You won't notice any difference over the way you are doing it now, except when things go wrong and the bootup does not go right.

To use systemd, you would create a service in /etc/systemd/system/

I do something very similar to what you want on my workstation. Here is my mountnas.service in /etc/systemd/system/

Code: Select all

[Unit]
Description = Mount jssnas iscsi share
Wants = display-manager.service
After = NetworkManager-wait-online.service network.target

[Service]
ExecStart = /usr/local/bin/mountNAS

[Install]
WantedBy = graphical.target
This would work for you, once you change the description.

Then as root, take the command line you presently have in your cron, and put it in the file /usr/local/bin/mountNAS.

chmod a+x mountNAS to make that file executable.

Then, the following command:
systemctl enable mountnas

And the mounting of the share will happen on startup, handled by systemd.

To handle unmounting on shutdown, here is the unmountnas.service file:

Code: Select all

[Unit]
Description = Unmount jssnas iscsi share
Before = shutdown.target
DefaultDependencies = yes

[Service]
ExecStart = /usr/local/bin/unmountNAS

[Install]
WantedBy = exit.target
with a similarly installed unmount script.

Now, what you are doing works fine. But if you would prefer to do it the "official" way, this is how you would do that.

Thanks a lot for the very useful info!

I'm definitely going to give that a go tomorrow. I did think there was likely a proper way to auto-mount network shares but all my Googling let me down on that one. I just wish there was a nice graphical way to set up the mounts (like Windows has) but beggars can't be choosers.

I've got a few other Linux boxes dotted around so I'm going to try the systemd method on those ones too.

Thanks again, much appreciated :D

Return to “Networking and servers”