Hi,
I’d like to have several users accessing to the auto-mount shares. I’ve find that the following command would add the user “romain” the right to read the share:
net usershare add Videos /media/Videos/ "Auto-mount Volume" osmc:F,romain:R
However, after reboot, the configuration goes back to default. Is there a way to make permanent changes to the automount shares?
Thanks in advance
Julien
I know this is an old thread, but is there a way to do this yet? I have USB hard drives that I’ve added in fstab that mount in /mnt, but samba auto-shares them so it won’t let me create another share with guest access.
It’s further complicated because it auto-shares using the label name of the HDD. My library on other PC’s use that label name, so I’d either need to (a) mount the hard drive under a different label name and rescan/redirect all the other PC’s, or (b) get the OSMC auto-share to either not share them so I can do it manually, or share them with guest read/write access.
Note: It’s a local network so security isn’t a worry for me. If I could lock down future drives that would be good, but it’s more important that I have access to everything on the current drives.
Udisks-glue shouldn’t do anything for any drive that is already mounted (eg in fstab) which means an automount share should not get added. So try this:
Safely unmount your external drive - this will cause the samba automount share to be removed. (Confirm this is the case) Now edit fstab and add an entry for your drive. (Remember to add nofail as a mount option so the drive not being plugged in doesn’t cause the system to fail to boot! Also remember to create the mount point directory…)
Then shut down, plug the drive in and boot up again. If this has worked the drive should be mounted wherever your fstab entry specified but there will be no automount share added. You should now be able to add a custom share in smb-shares.conf.
Automount shares are deleted automatically when drives are safely removed/unmounted, but probably not during a reboot, so it’s necessary to unmount the drive specifically rather than just shutting down and unplugging the drive.
You can check the status of automount shares with:
Thanks for the suggestions Mandrake, but it’s still ending up in the automount section.
Sure enough, “sudo net usershare info” showed that my drives were auto-mounted. I did “sudo umount -a” and then “sudo net usershare info” showed nothing. I then checked the /etc/fstab was right, and that the mount point directories existed, and did “sudo mount -a”. Again, they showed up as automounted in “sudo net usershare info”.
If I remove the drive from fstab, umount then mount, it isn’t listed in net usershare, so it doesn’t appear to be auto-mounting, but when I enter it in fstab then net usershare seems to think that it has auto-mounted.
You would have to think my fstab entries are wrong. I’ve tried a couple of version and still no good:
...
# Add custom shares in smb-shares.conf instead of editing smb.conf so they will not be
# overwritten by samba updates. You can only add new shares to smb-shares.conf, not change
# the default shares or global options. If you need full control see smb-local.conf above.
include = /etc/samba/smb-shares.conf
and /etc/samba/smb-shares.conf contains (just a working example)
[devices]
browsable = yes
read only = no
valid users = osmc
path = /mnt
force user = root
comment = Deprecated (Please use the Auto-mount Volume shares)
hide files = /$RECYCLE.BIN/System Volume Information/desktop.ini/thumbs.db/
[mynas]
browsable = yes
read only = no
valid users = osmc
path = /mnt/nas1
force user = root
comment = Deprecated (Please use the Auto-mount Volume shares)
hide files = /$RECYCLE.BIN/System Volume Information/desktop.ini/thumbs.db/
where devices and mynas are the visible network shares in this test environment where only user osmc gets access to.
I’ve done exactly that, and my shares are in smb-shares.conf, but the auto-share thing keeps stealing them.
My smb.conf has the include line, and smb-shares.conf has this:
[HDD2]
path = /mnt/HDD2
available = yes
browsable = yes
public = yes
writable = yes
guest ok = yes
force user = osmc
[HDD1]
path = /mnt/HDD1
available = yes
browsable = yes
public = yes
writable = yes
guest ok = yes
force user = osmc
OK, I’ve tried something else. I’ve added a “_2” suffix and tried mounting them at /mnt/HDD1_2 and /mnt/HDD2_2 (after creating the directories, of course). The drives mount fine, and I can mount each drive at both HDDx and HDDx_2 simultaneously. I’ve also edited smb-shares.conf to point at HDD1_2, etc. But when I restart the samba server (“sudo service smbd restart”), then run “sudo net usershare info” it has auto-mounted every mount point with “comment=Auto-mount Volume”, and they’re all password protected.
TL;DR: The Udisks-glue is hijacking my samba shares, even if I manually enter them in fstab and manually add the share to smb-shares.conf.
Can you post your system journal and fstab so I can see whether udisks-glue is trying to process an already mounted drive or not ? It shouldn’t be - for example the root file system is already mounted and does not get a share automatically for it.
Both partitions mount under /mnt instead of /media, as expected, and do not get any samba automount share.
However from studying your log I have a hunch of what the problem may be - basically udisks-glue is not waiting for fstab mounts to complete before attempting to mount the remaining drives/partitions, in fact there seems to be a race condition between udisks-glue and systemd both trying to mount the drive at the same time, hence the error in your log about only root being allowed to mount the partition.
To test this theory could you edit the systemd service for udisks-glue:
sudo nano /lib/systemd/system/udisks-glue.service
Change the After line in the [Unit] section to:
After = local-fs.target remote-fs.target
(eg adding local-fs.target)
Then save and reboot. Let me know if that helps, and please post the system journal again after testing the change whether or not it works so that I can see the difference in startup ordering.
Actually, I just remembered that I had the same problem with another box. /mnt/usbdl is in my /etc/fstab, but getting auto-shared with limited permissions. My workaround was making a second samba share named usbstick.
The problem seems to be that your manual fstab entry is not actually working - by the time udisks-glue is starting the drive has still not been mounted by systemd, thus udisks-glue will try to mount it and consequently add the samba share as well. (It tries to mount any local drives that have not already been mounted)
Udisks-glue will actually honour the mount path specified in /etc/fstab which is why it is gets mounted in the right place.
I don’t seem to be able to reproduce the problem, and I have tested on both a Pi 2 and a Vero with an external 2.5" drive - no problems at all.
Is it possible your drive is very slow at spinning up ? Does the problem still happen during a warm reboot where the external drive is not powered down ?
Not sure if it’s related, but I had trouble getting my fstab entry to work too. The trouble was similar in the sense that the hard drive was slower than the pi boot. The solution in my case (from here) was to add a small delay:
sudo nano /boot/cmdline.txt
{add to end} rootdelay=20
I understand what you’re saying. However, if I enter “sudo umount -a” the drive unmounts properly (at least, I can’t see anything when I ls in that directory). Then “sudo mount -a” seems to work fine and I can see and access all the files again. So at least after the initial boot, the fstab seems to be working.
Hmm, not really. One external drive does take time to spin up and will spin down after a while, but the other seems to be on all the time and access is effectively instant. And “usbdl” on the RPi2 is a flash USB stick, so should always be instant. Problem does still happen when I warm reboot and the drives are already spinning.
Is there a way to turn off the auto-samba sharing thing completely? I’m happy to setup my own shares, if I can turn off the automatic ones.
In the mean time, I’ll try some different fstab options to see if that works.
What I mean is that your fstab entry is not causing the drive to get mounted during boot, or at least not soon enough, (especially with the udisks-glue.service change I suggested) causing it to be mounted by udisks-glue when it should get mounted by systemd.
Does the drive mount at all if you mask the udisks and udisks-glue services ?
sudo systemctl mask udisks udisks-glue
Then reboot - this will completely disable the automounter. Check to see whether your fstab entries mount your drives or not. To enable the automounter again again:
If I mask udisks as you described, the drives mount fine. If I enter “sudo net usershare info”, only [boot] is listed. But if I browse to it from a PC, I see the various shares, including the OSMC home folder and the shares I’ve set up in smb-shares.conf.
OK, I’ve figured something out that might be useful. If I give my Samba share a new, unique name in smb-shares.conf, then it works fine with guest access. However, if I use a name that I’ve ever used as a mount point (e.g. /mnt/foldername/ while udisks service is running, then if I use that as a samba sharename ([foldername]) and restart samba, then it asks for a user & pass. Even if I unmount and delete the /mnt/foldername, if you use it as a samba share name it will still ask for a user/pass.
If I mask udisks & udisks-glue as you mention above, then any new foldernames can be used for guest access, but I still can’t use ones that I’ve used in the past.
I just found a spare USB stick lying around with the label “MASTER32”. I inserted it, waited a minute, then took it out again. I was then tried creating a samba share with guest access using the label “MASTER32”, and it asks me for a password.
Somewhere it is storing the names of all the USB drives that have been inserted. Is there a way to flush these out?
(And berto, thanks for the suggestion, but rootdelay didn’t change anything.)
I did another experiment. I renamed a USB stick as “DONTUSE78” in another PC. Before I connected it to the OSMC box, I added a line for it in fstab, a folder in /mnt/, and a guest share in smb-shares.conf. Then I connected the USB stick to OSMC, and it mounted fine, and had guest access over samba, even after a reboot.
Then I removed the line from fstab, and the share from smb-shares.conf, and rebooted. When it came back, the USB had auto-mounted and auto-shared with a user/pass required for access over samba. I restored the fstab and samba share, and did a reboot, but now it won’t let me access it as a guest.
If I set it up so it’s working fine (now using label DONTUSE79), then remove the line from fstab and reboot: guest access doesn’t work.
If I set it up so it’s working fine (now using label DONTUSE80), then remove the share from smb-shares.conf and reboot: it doesn’t auto-share the folder, so it’s not shared. If you re-add it to smb-shares.conf, guest access works.
The good news is I’ve figured out a workaround: I’ll disconnect all drives, do a fresh install, add everything to fstab and smb-shares.conf, then reconnect the drives. Although it would be nice if we could figure out why auto-mounting means you can never re-use that samba share name for guest access.
Have you ever checked the content of directory /var/lib/samba/usershares/ ?
On my system I found a lot of old/orphan entries although I can’t remember to have used the net usershare add command at all.
That’s because the usershares are probably still there. Samba usershares are persistent until they are removed - normally we add a usershare when a disk is detected, and remove it when it is removed. This can lead to usershares being left configured if you just disable the services, however a physical share does not appear at the client unless the drive is also present. So you can end up with orphaned shares in /var/lib/samba/usershares as @JimKnopf suggests.
You could either delete all files in /var/lib/samba/usershares to start fresh, or you could use ‘sudo net usershare delete ’ to get rid of it. No need to do a full reinstall.