Find the answer to your Linux question:
Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By gregm
Hi. I'm writing a PAM module - authentication to system via USB. I've already written pam module and installation script but faced a following problem. When I log normally and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2013
    Posts
    9

    Autodetect USB devices


    Hi.

    I'm writing a PAM module - authentication to system via USB. I've already written pam module and installation script but faced a following problem.

    When I log normally and then open pendrive's directory in file manager my module works as it then somehow loads the contents to /run/media/kokosek/PEN-NAME (I use OpenSUSE 12.3 64bit) which I need. Without opening dir in gui, /run/media is empty.

    Moreover, when I open dir in gui, ls /run/media/kokosek shows my pendrive and I activate the module and log out... it works (I can log back in). But if before logging in I disconnect the pendrive and connect it again it doesn't work (/run/media not empty, /run/media/kokosek empty).

    So here's what I need: command or a program which I'd add to my installation script so that when I turn on the computer and the display manager shows up there will already be every connected device in
    /run/media/kokosek.

    After reboot I can see my pendrive in gui and lsusb shows me it but /run/media is empty. So I just need to load pendrives I guess.

    Regards,
    kokosek

  2. #2
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,044
    kokosek likes this.

  3. #3
    Just Joined!
    Join Date
    Nov 2013
    Posts
    9
    For TLDR there's a summary in the end.

    Thanks a lot! It helped but not completely.

    What I did:
    -checked USB's partition label in Partitioner (ADATA UFD)
    -appended /etc/fstab to (\040 is code for space):
    Code:
    /dev/disk/by-id/ata-ST1000LM024_HN-M101MBB_S2RQJ9ECC30453-part6 swap                 swap       defaults              0 0
    /dev/disk/by-id/ata-ST1000LM024_HN-M101MBB_S2RQJ9ECC30453-part5 /                    ext4       acl,user_xattr        1 1
    /dev/disk/by-id/ata-ST1000LM024_HN-M101MBB_S2RQJ9ECC30453-part7 /home                ext4       acl,user_xattr        1 2
    proc                    /proc                           proc    defaults                0 0
    sysfs                   /sys                            sysfs   noauto                  0 0
    debugfs                 /sys/kernel/debug               debugfs noauto                  0 0
    devpts                  /dev/pts                        devpts  mode=0620,gid=5         0 0
    LABEL=ADATA\040UFD      /storage/ADATA\040UFD           vfat    auto,defaults           1 2
    -mv /etc/udev/rules.d/99-sth.rules /etc/udev/rules.d/98-sth.rules
    -made /etc/udev/rules.d/99-mount.rules with content:
    Code:
    #run mount -a everytime a block device is added/removed
    SUBSYSTEM=="block", run+="/bin/mount -a"
    -executed /etc/init.d/boot.udev restart

    How does it work:
    -after reboot it loads all USB devices to /storage
    -after unplugging and plugging back is sees them again
    -compute needs all the devices from /etc/fstab to be connected - otherwise welcome emergency mode
    -makes all USB devices' owner root

    Why the last point happens? Because I changed in /etc/fstab "auto,hotplug,defaults" to "auto,defaults" as "journalctl -b" showed me the error:
    Code:
    kernel: FAT-fs (sde1): Unrecognized mount option "hotplug" or missing value
    Obviously, I need to fix the last two points. I tried changing "hotplug" to "nofail" - then it boots without the pendrive but when I disconnect it and connect it again /storage/ADATA\ UFD is empty.

    SUMMARY. What I need is either of the option:
    -another way of automatically loading all USB devices to some directory after reboot and being able to disconnect them and connect them again and not changing their owner to root
    -new option for /etc/fstab which allows me to reconnect pendrives and still have them in e.g. /storage AND some way of not changing all devices' owner to root
    -fix to option "nofail" so that when USB is reconnected system will mount it again
    Last edited by kokosek; 01-18-2014 at 11:49 PM.

  4. #4
    Just Joined!
    Join Date
    Nov 2013
    Posts
    9
    I messed sth up, it works. I probably first commented the line in 99-mount.rules having faced emergency mode and then, after finding nofail I didn't uncomment it, I believe.

    So, summing up, what do you need to do is:
    -add every device you want to mount automatically to /etc/fstab with appropriate label (e.g. LABEL=KOKOSEK) or UUID (UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) with option nofail
    -add the file mentioned above named as 99-mount.rules (renaming before all other files with prefix 99)
    -/etc/init.d/boot.udev restart

    How does it work?
    The rule which was added react every time when device was (dis)connected. It then executes mount -a.
    Having all devices in /etc/fstab, all of them are mounted after mount -a as they're with option auto (which is default btw, added it just to be sure that it'll work when sth changes).
    The nofail option is needed so that when a device is not found the system will still boot as there won't be any errors (nofail makes them silent) and therefore we avoid the emergancy mode. When we are in the "normal mode"(?) we don't need to worry about a thing thanks to the .rules file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •