1

I was trying to attach specific USB drive to home folder of the user. I have installed vsftpd, but Kodi can't move on upper hierarchy. So he can't access /media folder, but FileZilla can.

My USB is automounted by system when I connect it,as /media/DRIVE, always with same name.

I'm trying to create symlink ln -s /media/DRIVE /home/user/DRIVE — this works for navigation, when i trying to access file this always not working, I don't know why. User has access to this folder and file, he is sudouser.

So I found the much better solution mount --bind /media/DRIVE /home/user/DRIVE — and thats works as I wanted. All fine, but after device ejected and plugged in again the system create new folder /media/DRIVE_ so this bind is not working.

I also try to bind specific device by UUID, but no result.

What I doing wrong? I googled more, and found advice to create custom systemd service for that, is this correct way, and where I can read documentation for mounting services.

I'm using Debian with systemd.

dr_
  • 29,602
Niklan
  • 113
  • 1
    (1) vstpd doesn't follow symlinks outside the chroot, for security reasons. Either install a different ftp demon, or mount the USB stick inside inside the chroot. (2) Keep in mind that whatever you do, it must work with and without the USB drive present. Bind-mounts don't sound like a good idea to solve this problem. – dirkt Jan 23 '17 at 16:07
  • Can you recommend different ftp demon? – Niklan Jan 23 '17 at 16:17

1 Answers1

1

You could try the debian usbmount package. The script /usr/share/usbmount/usbmountis triggered by udev when a USB storage device is connected, according to the rules in /lib/udev/rules.d/usbmount.rules. It looks for e.g. the UUID of the device, and mounts according to entries in the /etc/fstab (which, of course, should have option noauto).

Or modify /etc/usbmount/usbmount.conf for the path of (dynamic) mount points (if no entry in etc/fstab). This is also supported.

If this does not match your needs, you may modify the usbmountscript, e.g. to name the dynamic mount points after the UUID of the device.

ridgy
  • 831
  • Thank you for answer. I trying to achieve with this method. I installed usbmount package, and added this line UUID=40B6271B474560E0 /home/USERNAME/DRIVE none bind,noauto 0 0 to /etc/fstab, but has no result. I also noticed that usbmount created new link usb in /media folder, but it not work. – Niklan Jan 23 '17 at 17:55
  • For entries in /etc/fstab you have to define the fs-type and the 'normal' options, as usbmount will issue a real mount (no mount --bind). So this might be UUID=40B6271B474560E0 /home/USERNAME/DRIVE ext4 defaults,noauto 0 0 (please change the values accordingly). Also, in /etc/usbmount/usbmount.conf set VERBOSE=yes and look if you find usbmount messages in the logfiles (syslog or debug.log). – ridgy Jan 23 '17 at 18:14
  • I was trying this lines UUID=40B6271B474560E0 /home/USERNAME/DRIVE fuseblk rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096,noauto 0 0 - i get this line from /etc/mtab when previously this drive automounted and worked from /media. And those lines UUID=40B6271B474560E0 /home/USERNAME/DRIVE auto defaults,noauto 0 0 and UUID=40B6271B474560E0 /home/USERNAME/DRIVE fuseblk defaults,noauto 0 0. With all three lines drive not mounted at all. I also tried to create /home/USERNAME/DRIVE folder before mount, this has no result. What is my mistake? – Niklan Jan 24 '17 at 04:29
  • It seems your partition is formatted as NTFS (thus fstype=fuseblk). To solve this issue with usbmount, see e.g. http://raspberrypi.stackexchange.com/questions/41959/automount-various-usb-stick-file-systems-on-jessie-lite (it's for raspbian, which in fact is debian jessie) – ridgy Jan 24 '17 at 14:11
  • 1
    Thank you. This is helped. Now my USB drive is mounted to /home/USERNAME/DRIVE. But there is another problem. /media/DRIVE is missing for now. I'm trying to fix this. sudo mkdir /media/DRIVE (or this is not work) add to fstab $ UUID=40B6271B474560E0 /media/DRIVE ntfs-3g defaults,noauto 0 0 and below /media/DRIVE /home/USERNAME/DRIVE none noauto,bind 0 0 thats not worked. If i remove second line all start working. When i trying to access directories with this two lines I get this ls: reading directory .: Input/output error – Niklan Jan 25 '17 at 16:45
  • I thought your intention was to have the drive mounted below your HOME folder. Usually, devices are only mounted once (to one mountpoint); using mount --bind will be difficult for dynamic mounts. If necessary, you might modify the usbmount script, but that is beyond the scope of this answer. – ridgy Jan 25 '17 at 20:18
  • Ok, I get it. Thank you. Now I understand that better. This is not critical to have this drive at /media at all, so this is solved my problem. – Niklan Jan 26 '17 at 05:41