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 ...
- 07-25-2011 #1
Device stays in /dev after removal
Hello all,
I have some devices in /dev that i don't use anymore.
There is a pendrive in /dev/sdf, but there isn't in the others.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
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
- 07-26-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,818
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:
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.Code:ls -d /sys/block/sd*
- 07-26-2011 #3
The same..
I have this problem with MandrivaCode:[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/
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.
- 07-26-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,818
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:
Substitute the values in the top two lines for the correct vendor and model info for your pendrive, e.g.: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
cat /sys/block/sdf/device/vendor
cat /sys/block/sdf/device/model
- 07-26-2011 #5
i'm using this:
but with this problem i got 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
And i need only:Code:/dev/sdf /dev/sdf1 /dev/sde1 /dev/sdd1 /dev/sdc1 /dev/sdb1
/dev/sdf1 (thats where the pendrive is connected)
Any suggestion?
- 07-26-2011 #6Linux Guru
- Join Date
- May 2011
- Posts
- 1,818
Well, I guess all those devices are legitimate storage devices. What does this command tell you?
Maybe you need to reboot...Code:grep -H . /sys/block/sd*/device/model
EDIT: Are you un-mounting the pendrive, before removing it? That might clog up dev with unused block devices...
- 07-26-2011 #7I've rebooted a lot of times and nothing.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
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.
- 07-26-2011 #8Linux Guru
- Join Date
- May 2011
- Posts
- 1,818
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,or am i misunderstanding your problem?Code:ls -d /sys/block/sda/sda[0-9]*
- 07-26-2011 #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.
- 07-26-2011 #10Linux Guru
- Join Date
- May 2011
- Posts
- 1,818
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.
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.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
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.


Reply With Quote
