Linux – How to detect SD card insertion (just the SD card, not the card reader) in Linux

debianlinuxmemory-cardsd card

I have a headless debian (3.2.0-3-686-pae) to which I wanted to attach a standalone card reader to automatically process my pictures. The idea is that the reader will be plugged in all the time and I would just insert the SD card.

Unfortunately the card is not detected when I insert it.

  • the card reader is correctly recognized
  • when I connect the card reader with the SD card already inserted both are correctly recognized and the card is automatically mounted.

Therefore this is the action of inserting the card into a working card reader which is not recognized. There are no messages in /var/log/messages (nor anywhere else). When the card reader is inserted the messages are correct:

Aug  4 14:25:03 server kernel: [711743.411320] usb 1-6: USB disconnect, device number 5
Aug  4 14:25:12 server kernel: [711751.964021] usb 1-6: new high-speed USB device number 6 using ehci_hcd
Aug  4 14:25:12 server kernel: [711752.097364] usb 1-6: New USB device found, idVendor=058f, idProduct=6366
Aug  4 14:25:12 server kernel: [711752.097369] usb 1-6: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Aug  4 14:25:12 server kernel: [711752.097373] usb 1-6: Product: Mass Storage Device
Aug  4 14:25:12 server kernel: [711752.097375] usb 1-6: Manufacturer: Generic
Aug  4 14:25:12 server kernel: [711752.097377] usb 1-6: SerialNumber: 058F63666433
Aug  4 14:25:12 server kernel: [711752.098062] scsi4 : usb-storage 1-6:1.0
Aug  4 14:25:13 server kernel: [711753.224612] scsi 4:0:0:0: Direct-Access     Multiple Card  Reader     1.00 PQ: 0 ANSI: 0
Aug  4 14:25:14 server kernel: [711753.810820] sd 4:0:0:0: [sdc] 1984000 512-byte logical blocks: (1.01 GB/968 MiB)
Aug  4 14:25:14 server kernel: [711753.811559] sd 4:0:0:0: [sdc] Write Protect is off
Aug  4 14:25:14 server kernel: [711753.829719]  sdc: sdc1
Aug  4 14:25:14 server kernel: [711753.840025] sd 4:0:0:0: [sdc] Attached SCSI removable disk

I was wondering if I am missing something somewhere (the behavior above is out of the box – I did not need to configure anything) -or- that the insertion of a card into an already-connected card reader is simply not recognized by design.


EDIT: While fora discussions claim that the lack of message is normal, it obviously works for some (thanks Piskvor nad darnir for the comments).
I will leave the question unanswered and file a bug with Debian – updating this post if there is any progress.

EDIT: filed Bug#684306 (bugs.debian.org)

Best Answer

Here's how I've solved this problem:

  1. Install the udisks package
  2. Run udisks --poll-for-media

Via a udev rule I then trigger a script that takes care of downloading the data from my CF card automatically.

Related Question