Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Device stays in /dev after removal

    Hello all,

    I have some devices in /dev that i don't use anymore.

    brw-rw---- 1 root floppy 8, 16 2011-07-25 07:17 /dev/sdb
    brw-rw---- 1 root floppy 8, 32 2011-07-25 07:17 /dev/sdc
    brw-rw---- 1 root floppy 8, 48 2011-07-25 07:17 /dev/sdd
    brw-rw---- 1 root floppy 8, 64 2011-07-25 07:17 /dev/sde
    brw-rw---- 1 root floppy 8, 80 2011-07-25 07:17 /dev/sdf
    brw-rw---- 1 root floppy 8, 81 2011-07-25 07:17 /dev/sdf1
    There is a pendrive in /dev/sdf, but there isn't in the others.
    If i remove the sdf and conect another one, its reconize as sdc.

    How can i clean/fix this?

    Edit: With the udevadm info -a -n [device name] i can see that the ATTRS{serial} is the same from sdb to sde, the sdf is other pendrive.
    Last edited by playerum; 07-25-2011 at 03:12 PM. Reason: More information

  2. #2
    Those devices should get cleaned up after a reboot, if you have a fairly recent version of udev running. I wouldn't remove them manually, if I were you - that is the kernel/udev's job. You can verify what block devices are actually seen by the kernel with:
    ls -d /sys/block/sd*
    If you want your pendrive to always be given the same block device name (sdc, e.g.) then use a udev rule. See this page for details.

  3. #3
    The same..
    [root@???? ~]# ls -ld /sys/block/sd* 
    drwxr-xr-x 8 root root 0 2011-07-26 08:56 /sys/block/sda/
    drwxr-xr-x 5 root root 0 2011-07-26 08:56 /sys/block/sdb/
    drwxr-xr-x 5 root root 0 2011-07-26 08:56 /sys/block/sdc/
    drwxr-xr-x 5 root root 0 2011-07-26 08:56 /sys/block/sdd/
    drwxr-xr-x 5 root root 0 2011-07-26 08:56 /sys/block/sde/
    drwxr-xr-x 6 root root 0 2011-07-26 08:56 /sys/block/sdf/
    I have this problem with Mandriva
    2008.1 -
    2009.1 -

    Let me explain what i need.
    I have a backup script that verify wich device is conected, but with this problem it takes the first one, and sometimes the firt one its not the correct. If you have a sugestion it would be very helpfull.

    I'll try to make a ls -l /dev/disk/by-label/, then cut what i need, but if the pendrive has no label i'll get nothing, so i'll need to label the pendrive and then make the ls. Again if you have any suggestion.

  4. $spacer_open
  5. #4
    You should be able to get the vendor/device ids from the /sys filesystem (there are other ways, too, like udevadm and lsusb, .e.g.). but if you want a quick fix, you could do something like:
    for disk in $(ls -d /sys/block/sd*); do
      dev=$(basename $disk)
      vendor=$(cat $disk/device/vendor|sed -e 's| .*$||')
      echo "disk $dev vendor: '$vendor'"
      model=$(cat $disk/device/model|sed -e 's| .*$||')
      echo "disk $dev model: '$model'"
      if [ "$vendor" == "$pendrive_vendor" -a "$model" == "$pendrive_model" ]; then
    echo Your pendrive is on device $pendrive_dev
    Substitute the values in the top two lines for the correct vendor and model info for your pendrive, e.g.:
    cat /sys/block/sdf/device/vendor
    cat /sys/block/sdf/device/model

  6. #5
    i'm using this:
        for udi in $(/usr/bin/hal-find-by-capability --capability storage)
    	DEVICE=$(hal-get-property --udi $udi --key block.device)
    	if [[ $(hal-get-property --udi $udi --key storage.bus) = "usb" ]]
        	    parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
    	    DISPOSITIVO=$(echo $DEVICE'1'- | tr "-" '\n' | head -n1)
    	printf "$DISPOSITIVO\n"
    but with this problem i got this:
    And i need only:
    /dev/sdf1 (thats where the pendrive is connected)

    Any suggestion?

  7. #6
    Well, I guess all those devices are legitimate storage devices. What does this command tell you?

    grep -H . /sys/block/sd*/device/model
    Maybe you need to reboot...

    EDIT: Are you un-mounting the pendrive, before removing it? That might clog up dev with unused block devices...

  8. #7
    /sys/block/sda/device/model:WDC WD1600AABS-5
    /sys/block/sdb/device/model:USB SD Reader   
    /sys/block/sdc/device/model:USB CF Reader   
    /sys/block/sdd/device/model:USB SM Reader   
    /sys/block/sde/device/model:USB MS Reader   
    /sys/block/sdf/device/model:DT 101 G2
    I've rebooted a lot of times and nothing.

    About the un-mounting question, i can't confirm, because it's a remote machine, but it's 99,99 % chance that the pendrive wasn't mounted. The backup is done twice a day.

  9. #8
    Is this backup script under your control, i.e. can you modify it?

    If so, couldn't you:

    1. get vendor/model info from:

    cat /sys/block/sdf/device/vendor
    cat /sys/block/sdf/device/model

    2. insert the code i posted earlier into the appropriate place in your backup script, using the values from step 1 above for the 'pendrive_vendor' and 'pendrive_model' values. run by itself, using the proper pendrive_ values, it should return 'sdf'. You can then just prepend '/dev/' to it. and if you need to verify partitions,
    ls -d /sys/block/sda/sda[0-9]*
    or am i misunderstanding your problem?

  10. #9
    This does the trick, but there some problems:
    - i need to insert the vendor/model in each script
    - If another pendrive is connected i'll need to edit the script again (i have around 150 machines to do this)

    I need exactly what your code gives (Your pendrive is on device sdf), but it needs to be automatic.

  11. #10
    When is this backup script run? When the pendrive is inserted? Or by a cronjob or some other daemon? If the latter, when is the pendrive inserted?

    In either case, when the pendrive is inserted, is it automounted to some directory? If that is the case, then your backup script can look in the output of 'df' for the device being mounted, and if it finds it - use it, .e.g.

    for dev in sdb sdc sde sdf; do
      mounted=$(df|awk "\$1 ~ /$dev/{print \$6}")
      if [ -n "$mounted" ]; then
        echo "USB device $dev is mounted on $mounted"
    That is hacky. If I were you, i'd write a custom udev rule to always mount hot-plugged usb storage devices to a certain directory (e.g. /media/pendrive - if multiple devices, then also /media/pendrive_1, /media/pendrive_2, etc.), then the backup script would just look in the output of 'df' for /media/pendrive* and exit, if not found, otherwise, use it and continue with the backup script.

    All this requires is a rule in /etc/udev/rules.d/ (see the link in my original response) and a restart of udev. You'd have to copy this udev rule to all your servers, but it is just a one time copy, and this rule would not have to be updated for different models of pendrives.

    If you want help writing the udev rule, let me know, I have something along those lines currently working.

Posting Permissions

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