TIP Discover usb devices from dev entries
From Gentoo Linux Wiki
This article is still a Stub. You can help Gentoo-Wiki by expanding it.
Contents |
[edit] Introduction
Sometimes you plug in a usb peripheral or two, or three. And then you reboot. Then all the sudden, you have three devices occupying the scsi layer, and any of them could be the first, second, or third disk. How to tell which is which?
[edit] With fdisk
You can use fdisk! Fdisk will list each disk device, and will show partitions, blocks, filesystems, etc:
Disk /dev/sda: 127 MB, 127451136 bytes 4 heads, 61 sectors/track, 1020 cylinders Units = cylinders of 244 * 512 = 124928 bytes
Device Boot Start End Blocks Id System /dev/sda 1 1020 124409+ b W95 FAT32
[edit] With dmesg
A common thing to do is using dmesg. Usually dmesg contains a lot of information and the output gets quite long. Therefore, you can use various methods to ease reading. Choose your favorite from the following:
- dmesg | tail -10
- dmesg | less
- dmesg | more
- dmesg | most
- dmesg | grep sda
[edit] With udev
Using udev, probably the easiest way is to query udevinfo the following way:
udevinfo -q env -n /dev/sdX
where you replace the X with the appropriate device node name. This does not need to be more than a, b etc. As far as I know, there is no direct way you can query udevinfo on a vendor/model name.
Now in my case, this returns something like
$ udevinfo -q env -n /dev/sda ID_VENDOR=CREATIVE ID_MODEL=MuVo_N200 ID_REVISION=1162 ID_SERIAL=CREATIVE_MuVo_N200_0002F67B3F43899E ID_TYPE=disk ID_BUS=usb ID_PATH=usb-0002F67B3F43899E:0:0:0
If there is no info available, it returns
$ udevinfo -q env -n /dev/sda no record for 'sda' in database
My suggestion for using this in a script is to do
udevinfo -q env -n /dev/sdX | grep ID_SERIAL
You can check there what device you are dealing with, giving you both Vendor and Model (you could do those separately, obviously). With the line grep returns, you can check the name and mount it on the right mountpoint. If grep returns nothing, apparently there wasn't any device at the node you were trying to query on.
[edit] With volume names
You can give your partitions a name to make them uniquely recognizable.
For a reiserfs partition, do:
reiserfstune -l <LABEL> <partition>
For ext2/2xt3, do:
tune2fs -L <LABEL> <partition>
You can then see the partition names with fdisk.
A nifty feature is to mount a partition according to its label. Given an ext3 partition called STORAGE, add the following entry to your /etc/fstab:
| LABEL=STORAGE | /mnt/storage | ext3 | defaults,users | 0 | 0 |
You will then be able to mount the partition as soon as its device node got created by udev, using only the mount point.
[edit] Links
- You might also be interested in a more general article about UDEV.
