Plex: Automount With VirtualBox

2 minute read

Description:

So, the last time I moved some folders around between my drives I setup a new Plex directory for movies and such and now it won’t auto mount like it used to. I used to fstab entries and it worked fine. I was tinkering around and I found a method, but I can’t seem to get it to work. Will update this post when it is complete, but right now what I do is:

  • Reboot the VM
  • Login and run a bash file that automounts the drives
  • Not sure why crontab isn’t working

To Resolve:

  1. First, I setup the shared folders in Virtualbox and then expose them to the CentOS vm as read only and auto mount.

  2. I then set cron to start automatically before login:

    1
    
    sudo systemctl enable crond
    
  3. Here is a bash script that will get called

    1
    2
    3
    
    #!/bin/sh
    mount -t vboxsf google /mnt/google/
    mount -t vboxsf vids /mnt/vids/
    
  4. Here is the crontab entry

    1
    2
    3
    
    sudo crontab -e
    
    @reboot sleep 15; /home/user/myscript.sh
    
  5. Reboot to test, didn’t work. Had to do steps in description…

UPDATE: 2018-04-01 - This was fixed by doing the following:

  1. Remove the auto mount drives for VirtualBox completely.

  2. In my Windows Host, I just created a new user “smb”.

  3. I took my two folders that Plex needs to access and gave the security permissions for “smb” to read only.

  4. In my CentOS VM, I tested:

    1
    2
    3
    4
    
    smbclient -m SMB3 -U smb //192.168.0.20
    (enter password)
    # Prompt changes to: smb:
    exit
    
  5. So I know that it works interactively. Next I just made sure to enable “samba” and “samba-client” in the firewall.

  6. Now just need to update my /etc/fstab so it will automount:

    1
    2
    
    //192.168.0.20/google-backup /mnt/google cifs vers=3.0,username=smb,password=Pa$$word,rw,uid=1000,gid=976 0 0
    //192.168.0.20/vids /mnt/vids cifs vers=3.0,username=smb,password=Pa$$word,rw,uid=1000,gid=976 0 0
    
  7. It would be better to create a credentials file and put that in your home directory and access it that way:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    The quickest way to auto-mounting a password-protected share is to edit /etc/fstab (with root privileges), to add this line:
    
    //servername/sharename /media/windowsshare cifs username=msusername,password=mspassword,iocharset=utf8,sec=ntlm 0 0  
    This is not a good idea however: /etc/fstab is readable by everyone and so is your Windows password in it. The way around this is to use a credentials file. This is a file that contains just the username and password.
    
    Using a text editor, create a file for your remote servers logon credential:
    
    gedit ~/.smbcredentials  
    Enter your Windows username and password in the file:
    
    username=msusername  
    password=mspassword  
    Save the file, exit the editor.
    
    Change the permissions of the file to prevent unwanted access to your credentials:
    
    chmod 600 ~/.smbcredentials  
    Then edit your /etc/fstab file (with root privileges) to add this line (replacing the insecure line in the example above, if you added it):
    
    //servername/sharename /media/windowsshare cifs credentials=/home/ubuntuusername/.smbcredentials,iocharset=utf8,sec=ntlm 0 0  
    Save the file, exit the editor.
    
    Finally, test the fstab entry by issuing:
    
    sudo mount -a  
    If there are no errors, you should test how it works after a reboot. Your remote share should mount automatically.
    

Comments