views:

3915

answers:

12

I want to mount a USB drive, two of them and I need two different mount points. Unfortunately, the Linux kernel underwent a name change and I can't figure out which /dev location is the right one. Is there a way to look through dmesg or /proc or somewhere else to find out which device node is a USB drive.

(I'm using ArchLinux if that helps any.../dev/sda is the first hard drive, /dev/sr0 is a dvd drive, etc.)

edit: The USB drive is connected to a USB hub. I looked through dmesg and it says the hub was connected and it scanned for the 3 devices connected to it. Still can't see where my USB drive is though.

+1  A: 

If you unplug the USB drive and plug it back in, you should see it initialize from the kernel (dmesg)

Howler
+5  A: 

Easiest way - look at the output of dmesg after connecting the USB device. It should show you what /dev node was assigned to it.

zigdon
A: 

Take a look at the tree under /dev/disk. It lists disks and their partitions (file systems) by various schemes.

Ted Percival
A: 

/var/log/message if dmesg no longer has the information.

Allan Wind
A: 

I believe all the usb devices are /dev/sd* in Arch. Not on my Linux box at the moment, so I can't double check that. I believe the Arch wiki is very good about things like this.

docgnome
Those are (possibly emulated) Scsi Disk Devices.
Arafangion
+2  A: 

Try the command udevinfo -q all -n /dev/sda, where /dev/sda is the path to your disk. This gives you a boatload of info about the disk you're looking at - there's an entry that tells you about the bus it's connected to.

This of course saves you from having to grep through dmesg and/or logs.

Nathan Tomkins
A: 

Is this a programming question?

char see[40];
if (programming_question) {
    strcpy(see, "http://libusb.sf.net/");
} else {
    strcpy(see, "http://wiki.archlinux.org/index.php/Udev");
}
fprintf(stdout, "%s\n", see);
jsumners
A: 

ls -l /dev/disk/by-id/usb*

Under the default udev rules, that will show you most usb devices and it will show you the symlink to their block-device name on the system.

If that doesn't work, look at /dev/disk/by-id/ directly.

D.J. Capelis
+1  A: 

As long as you are running udev, you can do this easily by referencing /dev/disk/by-id/usb-manufacturername_*serialnumber*. These appear as symbolic links which you can either directly reference within your fstab, or which you can dereference using readlink -e to determine the associated block device.

Here's a real world example. On my machine, I have 3 USB hard drives connected. These each show up in /dev/disk/by-id with unique serial numbers (although they share a common manufacturer string). I have created symbolic links to each of these three unique entries, and can now quickly determine which drive is which (and which device is associated with each drive) by running readlink -e linkname. For example, running readlink -e /root/disk2 on my machine currently displays "/dev/sde", while readlink -e /root/disk3 produces no output whatsoever.

stormlash
+1  A: 

# The following solution works on Ubuntu and other 
# Debian derived Linux distributions.

# Become root
su

# Find USB devices.
# Search for pattern "sd" i.e.
# :/sd
dmesg | less

# Find out what partitions are currently mounted
df -h | less

# Find out where the different(i.e. Windows,NTFS,ext3) volumes 
# are in the partition table
fdisk -l | less

# On my system they are 
# dev       File System
# ########  ###########
# /dev/sdb  ext2
# /dev/sdc  ext2

# See properties of sd. devices
udevinfo -a -p `udevinfo -q path -n /dev/sdb` | less
udevinfo -a -p `udevinfo -q path -n /dev/sdc` | less
# ... look for ATTRS{vendor}
# :/ATTRS{vendor}

# Instruct udev to make symlinks for the drives based on the manufactor,
# size, or any number of properties or attributes of the device. 
# That symlink will always point to that device. You can modify your 
# fstab to use the udev defined symlink which in turn allows you to 
# always address the device using the same path.
cat > /etc/udev/rules.d/85-usb-hd-fix.rules <<ENDOFFILE
# backup500
SUBSYSTEM=="block", ATTRS{vendor}=="Maxtor  ", SYMLINK+="backup500", GROUP="disk", MODE="0660"
# backup160
SUBSYSTEM=="block", ATTRS{vendor}=="MAXTOR S", SYMLINK+="backup160", GROUP="disk", MODE="0660"

ENDOFFILE

# Change the attributes of the udev rules file
chmod 644 /etc/udev/rules.d/85-usb-hd-fix.rules

# Restart udev
/etc/init.d/udev restart

# Test udev
udevtest /sys/block/sdb block
udevtest /sys/block/sdc block

# Create the mount points
mkdir -p /mnt/backup500
mkdir -p /mnt/backup160

# Append the following to /etc/fstab
/dev/backup500                             /mnt/backup500  ext2         rw,auto,user                0       0
/dev/backup160                             /mnt/backup160  ext2         rw,auto,user                0       0

# Now, mount all devices defined in /etc/fstab
mount -a

# Or mount individually
mount /mnt/backup500
mount /mnt/backup160

#################### OPTIONAL ####################

# To ensure the drives are always mounted, insert the 
# following line to /etc/rc.local before "exit 0"
mount -a

# Change the attributes of the udev rules file
chmod 755 /etc/rc.local

# Reboot
shutdown -r now

#################### OPTIONAL ####################
Dragos Toader
A: 

Hi everyone,

what if this is what I get from my dmesg:

<6>usb 1-1: new full speed USB device using oxnas-ehci and address 3
<6>usb 1-1: configuration #1 chosen from 1 choice

How do I mount this??? I don't see anything like usb 1-1 in the /dev directory...

Thanks, Janos

+1  A: 

/dev/disk/by-* is the easiest way in this case, if for some reason you want to make life more interesting you can use HAL.

To list all devices you use:

hal-device

To get a specific property you use (this will return /dev/sd* on a USB storage device):

hal-get-property --udi $UDI --key block.device

There is also:

hal-find-by-capability
hal-find-by-property

If you want to make it even more complicated you can relatively easy write yourself a HAL based auto mounter, which can be quite handy if you want to automate things completly.

And just for completeness there are also:

lsusb -v
lshw

Which provides some general information about USB and your hardware in general.

Grumbel