User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Removalable media is inserted

Sat Mar 21, 2015 12:22 am

Hi is there a way in Raspbian to have this feature? For example when you put in your usb flash drive a prompt appear that says removal media insterted.
BTW I got this idea because i am using my laptop with Lubuntu and when i insert my usb flash drive the prompt appears.
:mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Removalable media is inserted

Sat Mar 21, 2015 1:06 am

Search the forum, I posted a way to do this using a udev script and a udev rule to detect a USB device being inserted.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Removalable media is inserted

Sat Mar 21, 2015 1:50 am

The search sucks. Also how would i exactly know what to search for? :mrgreen:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Removalable media is inserted

Sat Mar 21, 2015 1:55 am

OOPs I guess the search doesn't suck after all :lol: Marios voice: I got it http://www.raspberrypi.org/forums/viewt ... le#p710181 :geek:
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
expandables
Posts: 654
Joined: Fri Jun 27, 2014 7:34 pm
Location: Neverland with Michael Jackson

Re: Removalable media is inserted

Sat Mar 21, 2015 2:07 am

Mr. Lawson is this all i need to do?

Code: Select all

sudo nano /usr/local/bin/flash_drive

Code: Select all

#!/usr/bin/python

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

for i in range(20):
  GPIO.output(18, 1)
  sleep(0.1)
  GPIO.output(18, 0)
  sleep(0.1)

Code: Select all

sudo nano /etc/udev/rules.d/71-flash_drive.rules

Code: Select all

ACTION="add", SUBSYSTEMS=="usb", ATTRS{removable}=="removable", RUN+="/usr/local/bin/flash_drive $kernel'"

Code: Select all

 sudo /etc/init.d/udev
By thinking like an engineer you can create a raspberry pi.
Michael Jackson enthusiast.
I got the PI model B, B+ and PI 2 model B.
When will I get the A? I don't know.

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Removalable media is inserted

Sat Mar 21, 2015 10:59 am

That should work as long as the device you insert has the "removable" attribute.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Removalable media is inserted

Sat Mar 21, 2015 11:04 am

Actually, this happens by default (at least in the latest Raspbian GUI).

I usually have to do work to turn it off (since I find this Windows behavior annoying [if I want Windows, I know which machines here have it installed and running]).

Then again, I usually turn this feature off in Windows as well.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Beginners”