Mount Shares Locally

From Amahi Wiki
Jump to: navigation, search
Warning.png WARNING
This is recommended only for advanced users, proceed with caution.



Mounting your Samba shares locally is useful when you are using Greyhole, and want to write or in any way work with those files locally. Greyhole data should only be accessed through shares, so mounting those shares locally is an easy way to work with Greyhole data safely.

Download and Setup

  • As root, install the mount_shares_locally initd script:

On Amahi 7 (Fedora 19)

yum install cifs-utils
curl -o /etc/init.d/mount_shares_locally http://dl.amahi.org/mount_shares_locally.fedora
chmod +x /etc/init.d/mount_shares_locally
chkconfig --add mount_shares_locally

On Amahi 6 (Ubuntu 12.04)

sudo apt-get install cifs-utils curl
sudo curl -o /etc/init.d/mount_shares_locally http://dl.amahi.org/mount_shares_locally.ubuntu
sudo chmod +x /etc/init.d/mount_shares_locally
sudo update-rc.d mount_shares_locally defaults

Configuration

  • As root, edit /etc/init.d/mount_shares_locally and replace ***set this string to your username!*** (line 12) with your username. Example username="amahi"
vi /etc/init.d/mount_shares_locally
  • Create the /home/your_username/.smb_credentials file. This is a simple text file (use your favorite text editor).
vi /home/your_username/.smb_credentials
  • Enter the following:
 username=your_username
 password=your_password
 domain=HOME
  • Verify the .smb_credentials is owned by root:root or 1stadminuser:users:
ls -al /home/your_username/.smb_credentials
NOTE: your_username and your_password in the .smb_credentials file needs to be the original username (1st Admin User) and password you created when you installed the OS (NOT root).
  • To test your new mounts, you can execute as root user:
Mount
service mount_shares_locally start
Unmount
service mount_shares_locally stop
NOTE: If you used /etc/rc.local and /etc/fstab to mount shares locally in the past, you can remove what you added in those files now (DO NOT remove the drive mount lines). The above initd script replaces all this.

Re-mount to Add new shares

If you added new share to Greyhole, you need to restart the script by executing as root user (or sudo):

service mount_shares_locally restart

This will unmount and remount all your shares, reflecting all the new shares you added.

Where everything is mounted

You will find the mounted shares in /mnt/samba/*

For example, your "Pictures" share would be located at /mnt/samba/Pictures. When working with files on the HDA, access them via this share and NOT the traditional /var/hda/files/pictures location.

Uninstall

To uninstall mount_shares_locally, do the following as root:

service mount_shares_locally stop
rm -rf /etc/init.d/mount_shares_locally
rm -rf /home/your_username/.smb_credentials
chkconfig --del mount_shares_locally
rm -rf /mnt/samba/*

Now if you choose to reinstall later, your machine will be in a clean state.

Revise mount_shares_locally

Warning!
This is NOT an officially supported script for Amahi. Use at your own risk. We cannot guarantee it will work.


Some apps used by Amahi are used to download files etc. Often we want these files to end up in our shares. Let's say that SickBeard is used to download TV episodes. You then have to configure SickBeard to place your new episode somewhere. A logical place is to save to the landing zone of your Greyhole share which could be /var/hda/files/TV. There are two downsides to this though.

  • Greyhole is not notified of the fact that a file is added and only discovers it and makes it available in your share after a fsck, which could take a long time.
  • Files deleted through apps in this folder don't register a delete event that Greyhole can pick up and thus only the symlink in the landing zone is removed. The actual file copies remain on disc. Similarly users running Plex Media Server for example will have issues if the clients are allowed to delete contents and the server is configured to work on the landing zone. I described this issue when packaging Plex a long time ago here.


Since Greyhole uses Samba as a layer between the user and itself we would like to keep our writes and deletes to the shares and not the actual landing zone. But since apps (most of them) run as the user apache it will not be able to access /mnt/samba, which is the default mount point if you set up mount_shares_locally. This following script retains the function of the original script but also adds a second mount point under /mnt/apache where the apache user will have read and write access. I have kept it simple and it will use the same credentials as the main mount. So only shares available to that user will be available for apache.

By doing this apache will now have a place where it is allowed to read and write files to your shares and SickBeard can thus be configured to place the new episode in /mnt/apache/TV which is then instantly picked up by Greyhole and file copies distributed to the discs in your pool as configured.

Note that this script is based of the Greyhole original one and uses /etc/samba/smb.conf as the source of your shares and does not load the shares from the database like the old HDA version of the script did. If that behaviour is desired that can be easily added by replacing the lines

testparm -s /etc/samba/smb.conf 2>/dev/null | grep "^\[" | grep -v "\[global\]" | grep -v "\[homes\]" | awk -F'[' '{print $2}' | awk -F']' '{print $1}' | xargs -d "\n" mkdir -p

with

mysql -u root -phda -e "select comment from shares" hda_production | grep -v "^comment$" | xargs -d "\n" mkdir -p

Troubleshooting

MySQL Problems

Since Greyhole moved from SQL Lite to MySQL, you may hit a problem where Greyhole and the mount_shares_locally script both attempt to start before MySQL in bootup, leading to the services not starting properly. If this happens, you can try this to fix it:

ls /etc/rc.d/rc3.d/
  • Look for any entries marked S-1. If there are any, they need to be removed. Run the following as root:
rm S-1*

Share Permissions

Ensure your share file and ownership permissions are correct:

ls -al /var/hda/files

For example, the correct permissions are:

drwxr-xr-x. 10 root  root  4096 Jul 29 17:02 .
drwxr-xr-x. 13 root  root  4096 Dec  5  2013 ..
drwxrwxr-x   2 1stadmin users 4096 Dec  5  2013 books

If this is not correct, you will need to change them:

chmod -R 775 /var/hda/files/sharename
chown -R 1stadminuser:users /var/hda/files/sharename
NOTE: Replace 1stadminuser with your admin user name and sharename with the actual share name.