0

I have an USB stick which contains private stuff like the SSH key. I want to mount this stick to my own home directory with 0700 permissions. Currently I do this with this line in /etc/fstab:

LABEL=KAYSTICK /home/k/.kaystick auto rw,user,noauto,umask=077,fmask=177 0 0

This works great but there is one minor problem: In Nautilus (The Gnome file manager) the mount point ".kaystick" is displayed. I guess Nautilus simply scans the /etc/fstab file and displays everything it finds there. This mount point is pretty useless because it can't be clicked when the device is not present and it can't be clicked when the device is present (Because then it is already mounted). I know this is a really minor problem because I could simply ignore it but I'm a perfectionist and so I want to get rid of this useless mount point in Nautilus.

Is there another way to customize the mount point and mount options for a specific USB device? Maybe it can be configured in udev? If yes, how?

kayahr
  • 313
  • 4
  • 14

1 Answers1

0

Found it out by myself. I added the file /lib/udev/rules.d/99-kaystick.rules with this content:

IMPORT{program}="/sbin/blkid -o udev -p %N"
ENV{ID_FS_LABEL}!="KAYSTICK", GOTO="kaystick_end"
ACTION=="add", RUN+="/bin/mkdir -m 0 -p /home/k/KAYSTICK", RUN+="/bin/mount -o noatime,umask=077,fmask=177,utf8,uid=1000,gid=1000,sync /dev/%k /home/k/KAYSTICK"
ACTION=="remove", RUN+="/bin/umount -l /dev/%k", RUN+="/bin/rmdir /home/k/KAYSTICK"
LABEL="kaystick_end"

and then ran this command to reload the udev rules:

udevadm control --reload-rules

Now everytime I insert my USB stick a directory /home/k/KAYSTICK is created and the stick is mounted to this directory with custom mount options. When removing the stick it is automatically unmounted and the directory is removed. Auto-unmounting wasn't working with the /etc/fstab solution I tried before so this solution is much better.

kayahr
  • 313
  • 4
  • 14