Better way to script USB device mount in Linux

前端 未结 5 650
鱼传尺愫
鱼传尺愫 2020-12-15 14:26

I\'m writing a python module for a device that interacts with a user supplied USB memory stick. The user can insert a USB memory stick in the device USB slot, and the device

5条回答
  •  误落风尘
    2020-12-15 14:39

    why don't you simply use an udev rule? i had to deal with a similar situation, and my solution was to create a file in /etc/udev/rules.d containing following rule:

    SUBSYSTEMS=="scsi", KERNEL=="sd[b-h]1", RUN+="/bin/mount -o umask=000 /dev/%k /media/usbdrive"
    

    one assumption here is that nobody ever inserts more than one usb stick at time. it has however the advantage that i know in advance where the stick will be mounted (/media/usbdrive).

    you can quite surely elaborate it a bit to make it smarter, but personally i never had to change it and it still works on several computers.

    however, as i understand, you want to be alerted somehow when a stick is inserted, and perhaps this strategy gives you some trouble on that side, i don't know, didn't investigate...

提交回复
热议问题