Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
Hello all, I have some devices in /dev that i don't use anymore. Code: ... brw-rw---- 1 root floppy 8, 16 2011-07-25 07:17 /dev/sdb brw-rw---- 1 root floppy 8, 32 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! playerum's Avatar
    Join Date
    Aug 2010
    Posts
    24

    Device stays in /dev after removal


    Hello all,

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

    Code:
    ...
    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
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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:
    Code:
    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
    Just Joined! playerum's Avatar
    Join Date
    Aug 2010
    Posts
    24
    The same..
    Code:
    [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 - 2.6.24.4-desktop-1mnb
    2009.1 - 2.6.29.1-server-4mnb

    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. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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:
    Code:
    #!/bin/bash
    pendrive_vendor='JetFlash'
    pendrive_model='TS8GJF2A'
    
    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
        pendrive_dev=$dev
        break
      fi
    done
    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

  5. #5
    Just Joined! playerum's Avatar
    Join Date
    Aug 2010
    Posts
    24
    i'm using this:
    Code:
    #!/bin/bash
    
        for udi in $(/usr/bin/hal-find-by-capability --capability storage)
        do
    	DEVICE=$(hal-get-property --udi $udi --key block.device)
    	if [[ $(hal-get-property --udi $udi --key storage.bus) = "usb" ]]
    	then
        	    parent_udi=$(hal-find-by-property --key block.storage_device --string $udi)
    
    	    DISPOSITIVO=$(echo $DEVICE'1'- | tr "-" '\n' | head -n1)
    	printf "$DISPOSITIVO\n"
    	fi
        done
    but with this problem i got this:
    Code:
    /dev/sdf 
    /dev/sdf1
    /dev/sde1
    /dev/sdd1
    /dev/sdc1
    /dev/sdb1
    And i need only:
    /dev/sdf1 (thats where the pendrive is connected)

    Any suggestion?

  6. #6
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Well, I guess all those devices are legitimate storage devices. What does this command tell you?

    Code:
    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...

  7. #7
    Just Joined! playerum's Avatar
    Join Date
    Aug 2010
    Posts
    24
    Code:
    /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.

  8. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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,
    Code:
    ls -d /sys/block/sda/sda[0-9]*
    or am i misunderstanding your problem?

  9. #9
    Just Joined! playerum's Avatar
    Join Date
    Aug 2010
    Posts
    24
    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.

  10. #10
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    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.

    Code:
    #!/bin/bash
    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"
        break
      fi
    done
    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.

Page 1 of 2 1 2 LastLast

Posting Permissions

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