All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] Run a custom script after USB mount
@ 2015-04-17 15:21 Santhosh Ramani
  2015-04-17 16:23 ` Lionel Orry
  0 siblings, 1 reply; 10+ messages in thread
From: Santhosh Ramani @ 2015-04-17 15:21 UTC (permalink / raw)
  To: buildroot

Hello Everyone,

I am having some trouble with udev and rules.d. The buildroot system
automatically mounts any USB memory stick at the location /media/usb0. (I
have only USB host port). I would like to execute a script every time a USB
memory stick is inserted.

I added a custom rule in rules.d - I named it *z*usbdetect.rules (z so that
it runs at the very end, since I want it to run after usbmount.rules in
/lib/udev/rules.d has finished executing)

The content of the rules file are as follows:

KERNEL=="sd*", ATTRS{mode}=="a_host", ATTRS{serial}=="musb-hdrc.0.auto",
ATTRS{product}=="MUSB HDRC host driver", RUN+="/etc/hcc/usb-detected"

I have double checked that my script has execute permissions and I can run
it by hand. Am I missing something? Can you please point me in the right
direction?

Thank you for your help.
Regards

Santhosh

-- 
Greater the Difficulty....Sweeter is the Victory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150417/914a44d6/attachment.html>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-17 15:21 [Buildroot] Run a custom script after USB mount Santhosh Ramani
@ 2015-04-17 16:23 ` Lionel Orry
  2015-04-17 16:37   ` Santhosh Ramani
  0 siblings, 1 reply; 10+ messages in thread
From: Lionel Orry @ 2015-04-17 16:23 UTC (permalink / raw)
  To: buildroot

Dear Santhosh,

On Fri, Apr 17, 2015 at 5:21 PM, Santhosh Ramani <srcoolz@gmail.com> wrote:
> Hello Everyone,
>
> I am having some trouble with udev and rules.d. The buildroot system
> automatically mounts any USB memory stick at the location /media/usb0. (I
> have only USB host port). I would like to execute a script every time a USB
> memory stick is inserted.
>
> I added a custom rule in rules.d - I named it zusbdetect.rules (z so that it
> runs at the very end, since I want it to run after usbmount.rules in
> /lib/udev/rules.d has finished executing)
>
> The content of the rules file are as follows:
>
> KERNEL=="sd*", ATTRS{mode}=="a_host", ATTRS{serial}=="musb-hdrc.0.auto",
> ATTRS{product}=="MUSB HDRC host driver", RUN+="/etc/hcc/usb-detected"
>
> I have double checked that my script has execute permissions and I can run
> it by hand. Am I missing something? Can you please point me in the right
> direction?

have you checked that you are actually using the udev system, and not
mdev for example ?
As an aside note, I do the same using mdev and it works perfectly, so
I could get rid of udev and make my system lighter.

>
> Thank you for your help.
> Regards
>
> Santhosh
>
> --
> Greater the Difficulty....Sweeter is the Victory
>
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

Regards,
Lionel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-17 16:23 ` Lionel Orry
@ 2015-04-17 16:37   ` Santhosh Ramani
  2015-04-18 12:36     ` Thomas Petazzoni
  0 siblings, 1 reply; 10+ messages in thread
From: Santhosh Ramani @ 2015-04-17 16:37 UTC (permalink / raw)
  To: buildroot

Hello Lionel,


have you checked that you are actually using the udev system, and not
> mdev for example ?
> As an aside note, I do the same using mdev and it works perfectly, so
> I could get rid of udev and make my system lighter.


I checked the daemons that are running, and it seems udev is running.
However, I do see /sbin/mdev and /sbin/udevd, so not entirely sure which
one is running. Under System Configuration /dev management, I do have eudev
selected rather than mdev.

But regardless, shouldn't the script execute when USB is detected. I see
that it gets mounted properly at /media/usb0 but the script doesn't seem to
run.

Thanks once again for your reply.
Regards

Santhosh

-- 
Greater the Difficulty....Sweeter is the Victory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150417/7206b452/attachment.html>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-17 16:37   ` Santhosh Ramani
@ 2015-04-18 12:36     ` Thomas Petazzoni
  2015-04-23  3:02       ` Santhosh Ramani
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Petazzoni @ 2015-04-18 12:36 UTC (permalink / raw)
  To: buildroot

Dear Santhosh Ramani,

On Fri, 17 Apr 2015 11:37:41 -0500, Santhosh Ramani wrote:

> I checked the daemons that are running, and it seems udev is running.
> However, I do see /sbin/mdev and /sbin/udevd, so not entirely sure which
> one is running. Under System Configuration /dev management, I do have eudev
> selected rather than mdev.
> 
> But regardless, shouldn't the script execute when USB is detected. I see
> that it gets mounted properly at /media/usb0 but the script doesn't seem to
> run.

You may want to try 'udevadm --monitor' or something similar to debug
the udev events.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-18 12:36     ` Thomas Petazzoni
@ 2015-04-23  3:02       ` Santhosh Ramani
  2015-04-23  3:44         ` Santhosh Ramani
  2015-04-23 19:56         ` Arnout Vandecappelle
  0 siblings, 2 replies; 10+ messages in thread
From: Santhosh Ramani @ 2015-04-23  3:02 UTC (permalink / raw)
  To: buildroot

Hello Thomas,

Thanks for your reply - I was able to use 'udevadm monitor' to look at udev
events. Every time the USB is inserted, I do see udev messages indicate
'add'. These are the scripts and rules I have in the system - may be I'm
doing something wrong here...

I have added a rule in /etc/udev/rules.d/ and it has the following single
line.

*# cat /etc/udev/rules.d/99-usb-detection.rules*
* SUBSYSTEM=="usb", ACTION=="add", KERNEL=="sda*",
RUN+="/etc/hcc/usb-detected"*

The usb-detected script is nothing more than a launcher script that runs
the dummy scripts and ensures that udev doesn't have to wait for the script
to finish completion.

*# cat /etc/hcc/usb-detected*







*#! /bin/sh # # The following script is launched when a USB memory stick is
mounted # This is just a launcher script # /root/update_script & exit*

And the update_script is doing nothing but creating a new file.

*# cat /root/update_script*








*#! /bin/sh sleep 5 echo "" > /root/new echo
"******************************************************" >> /root/new echo
"Test file created" >> /root/new echo
"******************************************************" >> /root/new echo
"" >> /root/new*

I can run the usb-detected script and it works fine, however I don't think
it gets launched from the usb-rule. Any thoughts on this?

Thank you for your help.
Regards

Santhosh


On 18 April 2015 at 07:36, Thomas Petazzoni <
thomas.petazzoni@free-electrons.com> wrote:

> Dear Santhosh Ramani,
>
> On Fri, 17 Apr 2015 11:37:41 -0500, Santhosh Ramani wrote:
>
> > I checked the daemons that are running, and it seems udev is running.
> > However, I do see /sbin/mdev and /sbin/udevd, so not entirely sure which
> > one is running. Under System Configuration /dev management, I do have
> eudev
> > selected rather than mdev.
> >
> > But regardless, shouldn't the script execute when USB is detected. I see
> > that it gets mounted properly at /media/usb0 but the script doesn't seem
> to
> > run.
>
> You may want to try 'udevadm --monitor' or something similar to debug
> the udev events.
>
> Thomas
> --
> Thomas Petazzoni, CTO, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com
>



-- 
Greater the Difficulty....Sweeter is the Victory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150422/36eead56/attachment.html>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-23  3:02       ` Santhosh Ramani
@ 2015-04-23  3:44         ` Santhosh Ramani
  2015-04-23 19:56         ` Arnout Vandecappelle
  1 sibling, 0 replies; 10+ messages in thread
From: Santhosh Ramani @ 2015-04-23  3:44 UTC (permalink / raw)
  To: buildroot

Hello Thomas,

This is the output I get from the udevadm monitor

# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[4574.108256] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1 (usb)
KERNEL[4574.114729] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0
(usb)
KERNEL[4574.116502] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4
(scsi)
KERNEL[4574.116755] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/scsi_host/host4
(scsi_host)
UDEV  [4574.128129] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1 (usb)
UDEV  [4574.134332] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0
(usb)
UDEV  [4574.136982] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4
(scsi)
UDEV  [4574.141432] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/scsi_host/host4
(scsi_host)
KERNEL[4575.112353] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0
(scsi)
KERNEL[4575.114159] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0
(scsi)
KERNEL[4575.115028] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/scsi_disk/4:0:0:0
(scsi_disk)
KERNEL[4575.119508] add      /devices/virtual/bdi/8:0 (bdi)
KERNEL[4575.126051] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/scsi_device/4:0:0:0
(scsi_device)
KERNEL[4575.132346] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/block/sda
(block)
KERNEL[4575.132908] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/block/sda/sda1
(block)
UDEV  [4575.137353] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0
(scsi)
UDEV  [4575.145704] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0
(scsi)
UDEV  [4575.155363] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/scsi_disk/4:0:0:0
(scsi_disk)
UDEV  [4575.159306] add      /devices/virtual/bdi/8:0 (bdi)
UDEV  [4575.171496] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/scsi_device/4:0:0:0
(scsi_device)
UDEV  [4575.427571] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/block/sda
(block)
UDEV  [4576.767773] add
/devices/ocp.2/47400000.usb/47401400.usb/musb-hdrc.0.auto/usb1/1-1/1-1:1.0/host4/target4:0:0/4:0:0:0/block/sda/sda1
(block)

Thank you
Regards

Santhosh

-- 
Greater the Difficulty....Sweeter is the Victory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150422/bb8a1f96/attachment.html>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-23  3:02       ` Santhosh Ramani
  2015-04-23  3:44         ` Santhosh Ramani
@ 2015-04-23 19:56         ` Arnout Vandecappelle
  2015-04-23 23:04           ` Santhosh Ramani
  1 sibling, 1 reply; 10+ messages in thread
From: Arnout Vandecappelle @ 2015-04-23 19:56 UTC (permalink / raw)
  To: buildroot

On 04/23/15 05:02, Santhosh Ramani wrote:
> Hello Thomas,
> 
> Thanks for your reply - I was able to use 'udevadm monitor' to look at udev
> events. Every time the USB is inserted, I do see udev messages indicate 'add'.
> These are the scripts and rules I have in the system - may be I'm doing
> something wrong here...
> 
> I have added a rule in /etc/udev/rules.d/ and it has the following single line.
> 
> /# cat /etc/udev/rules.d/99-usb-detection.rules/*
> SUBSYSTEM=="usb", ACTION=="add", KERNEL=="sda*", RUN+="/etc/hcc/usb-detected"*

 If it's a scsi device, the subsystem is block, not usb, right?

 Regards,
 Arnout

[snip]


-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-23 19:56         ` Arnout Vandecappelle
@ 2015-04-23 23:04           ` Santhosh Ramani
  2015-04-28 18:51             ` Arnout Vandecappelle
  0 siblings, 1 reply; 10+ messages in thread
From: Santhosh Ramani @ 2015-04-23 23:04 UTC (permalink / raw)
  To: buildroot

Hello Arnout,

> /# cat /etc/udev/rules.d/99-usb-detection.rules/*
> > SUBSYSTEM=="usb", ACTION=="add", KERNEL=="sda*",
> RUN+="/etc/hcc/usb-detected"*
>  If it's a scsi device, the subsystem is block, not usb, right?


Yes you are correct - I removed the subsystem section and it now works
properly. I also was not restarting (or reloading) udev rules properly and
that was also contributing to the problem.

The script I want to run copies data from the USB stick and places it at a
given location. However, it seems that by the time the script finishes
executing the USB is not yet mounted so nothing gets copied. How can I
defer execution of the script until the volume is mounted, yet at the same
time not block udev. I tried the following:

usb-detected: Launcher Script

/etc/hcc/update_script & exit

I was hoping the second script "update" would be launched as a separate
process and will be non-blocking. I could then add sleep command in the
second script and delay execution. However, this doesn't seem to work. I
was not able to use 'disown' either, since it's a bash command. Similarly I
didn't have any luck with 'at' command either.

Any thoughts on how I can defer the thread and not block udev?

Thank you once again for all your replies.
Regards

Santhosh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150423/d2b2ae54/attachment.html>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-23 23:04           ` Santhosh Ramani
@ 2015-04-28 18:51             ` Arnout Vandecappelle
  2015-04-29  3:01               ` Santhosh Ramani
  0 siblings, 1 reply; 10+ messages in thread
From: Arnout Vandecappelle @ 2015-04-28 18:51 UTC (permalink / raw)
  To: buildroot

On 04/24/15 01:04, Santhosh Ramani wrote:
> Hello Arnout,
> 
>     > /# cat /etc/udev/rules.d/99-usb-detection.rules/*
>     > SUBSYSTEM=="usb", ACTION=="add", KERNEL=="sda*", RUN+="/etc/hcc/usb-detected"*
>      If it's a scsi device, the subsystem is block, not usb, right?
> 
> 
> Yes you are correct - I removed the subsystem section and it now works properly.
> I also was not restarting (or reloading) udev rules properly and that was also
> contributing to the problem. 
> 
> The script I want to run copies data from the USB stick and places it at a given
> location. However, it seems that by the time the script finishes executing the
> USB is not yet mounted so nothing gets copied. How can I defer execution of the
> script until the volume is mounted, yet at the same time not block udev. I tried
> the following:
> 
> usb-detected: Launcher Script
> 
> /etc/hcc/update_script & exit
> 
> I was hoping the second script "update" would be launched as a separate process
> and will be non-blocking. I could then add sleep command in the second script
> and delay execution. However, this doesn't seem to work. I was not able to use
> 'disown' either, since it's a bash command. Similarly I didn't have any luck
> with 'at' command either.
> 
> Any thoughts on how I can defer the thread and not block udev?

 Actually I don't use udev myself - I just read the documentation to answer your
question. so I really can't say.

 However, can't you add something to whatever script is doing the mounting, so
you can be sure that it's mounted already?

 Regards,
 Arnout

> 
> Thank you once again for all your replies.
> Regards
> 
> Santhosh


-- 
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Buildroot] Run a custom script after USB mount
  2015-04-28 18:51             ` Arnout Vandecappelle
@ 2015-04-29  3:01               ` Santhosh Ramani
  0 siblings, 0 replies; 10+ messages in thread
From: Santhosh Ramani @ 2015-04-29  3:01 UTC (permalink / raw)
  To: buildroot

Hello Arnout,

I was able to solve the problem, and here is what I did to resolve it.
Buildroot adds a script to udev called "usbmount", so when I added my
script I named it "z-usb-detect" to ensure that it runs after usbmount.
This in conjunction with reloading udev rules "udevadm control
--reload-rules".

These two allowed my script to run fine. The z-usb-detect is a pilot script
that uses "& exit" at the end. I am not certain if this actually helps, but
I added it regardless. It could be helpful if someone explained how this
helps or doesn't help.

Additionally, my actual script uses a "sleep 2" at the start to allow more
time for the mount process to complete.

Thanks again for all your help guys.
Regards

Santhosh

On 29 April 2015 at 00:21, Arnout Vandecappelle <arnout@mind.be> wrote:

> On 04/24/15 01:04, Santhosh Ramani wrote:
> > Hello Arnout,
> >
> >     > /# cat /etc/udev/rules.d/99-usb-detection.rules/*
> >     > SUBSYSTEM=="usb", ACTION=="add", KERNEL=="sda*",
> RUN+="/etc/hcc/usb-detected"*
> >      If it's a scsi device, the subsystem is block, not usb, right?
> >
> >
> > Yes you are correct - I removed the subsystem section and it now works
> properly.
> > I also was not restarting (or reloading) udev rules properly and that
> was also
> > contributing to the problem.
> >
> > The script I want to run copies data from the USB stick and places it at
> a given
> > location. However, it seems that by the time the script finishes
> executing the
> > USB is not yet mounted so nothing gets copied. How can I defer execution
> of the
> > script until the volume is mounted, yet at the same time not block udev.
> I tried
> > the following:
> >
> > usb-detected: Launcher Script
> >
> > /etc/hcc/update_script & exit
> >
> > I was hoping the second script "update" would be launched as a separate
> process
> > and will be non-blocking. I could then add sleep command in the second
> script
> > and delay execution. However, this doesn't seem to work. I was not able
> to use
> > 'disown' either, since it's a bash command. Similarly I didn't have any
> luck
> > with 'at' command either.
> >
> > Any thoughts on how I can defer the thread and not block udev?
>
>  Actually I don't use udev myself - I just read the documentation to
> answer your
> question. so I really can't say.
>
>  However, can't you add something to whatever script is doing the
> mounting, so
> you can be sure that it's mounted already?
>
>  Regards,
>  Arnout
>
> >
> > Thank you once again for all your replies.
> > Regards
> >
> > Santhosh
>
>
> --
> Arnout Vandecappelle                          arnout at mind be
> Senior Embedded Software Architect            +32-16-286500
> Essensium/Mind                                http://www.mind.be
> G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
> LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
> GPG fingerprint:  7CB5 E4CC 6C2E EFD4 6E3D A754 F963 ECAB 2450 2F1F
>



-- 
Greater the Difficulty....Sweeter is the Victory
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20150429/93880a08/attachment.html>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-04-29  3:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-17 15:21 [Buildroot] Run a custom script after USB mount Santhosh Ramani
2015-04-17 16:23 ` Lionel Orry
2015-04-17 16:37   ` Santhosh Ramani
2015-04-18 12:36     ` Thomas Petazzoni
2015-04-23  3:02       ` Santhosh Ramani
2015-04-23  3:44         ` Santhosh Ramani
2015-04-23 19:56         ` Arnout Vandecappelle
2015-04-23 23:04           ` Santhosh Ramani
2015-04-28 18:51             ` Arnout Vandecappelle
2015-04-29  3:01               ` Santhosh Ramani

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.