Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Nov 27 '11 at 10:56

This question came from our site for professional and enthusiast programmers.

1  
Can't see it? Maybe wait for a bit. Or try another USB port. See what differences there is in 'lsusb' –  Nick Devereaux Mar 10 '09 at 23:02
    
Might want to rephrase the question somewhat - not all usb devices are disks, after all. –  Arafangion Mar 10 '09 at 23:23
1  
The df command shows you where it was mounted –  Will Sheppard Aug 28 '13 at 14:09
add comment

14 Answers 14

up vote 35 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

All of these are good suggestions, but the quickest and least verbose method is to just type the following in the terminal:

mount

which will give a list of all the mounted devices (this assumes the USB drive is mounted, which is usually the case with modern Linux distros).

share|improve this answer
    
No, it doesn't magically mount your device. You have to specify it with mount /dev/id /mount/point, so that doesn't work. –  polym yesterday
    
My answer addresses the user's question 'Is there a way to look through dmesg or /proc or somewhere else to find out which device node is a USB drive.', and is not intended to provide guidance on the practicality of mounting a drive under Linux. –  AnotherLongUsername 22 hours ago
add comment

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.

share|improve this answer
5  
In Debian, udevinfo is renamed udevadm. –  Steve Pomeroy Aug 23 '11 at 14:44
6  
On Ubuntu, the command seems to be "udevadm info --query=all -n /dev/sda" –  machineghost Dec 13 '11 at 6:06
    
I suppose they renamed the command at some point - when I wrote the answer (ages ago) the command worked on the ubuntu system that I posted it from ;) –  Eltariel Dec 15 '11 at 5:08
    
Command works still in ubuntu, udevadm info --query=all -n /dev/ttyUSB1 –  Siddharth Jun 4 '13 at 8:43
1  
udevadm info --query=all -n /dev/ttyUSB in Fedora too. –  slm Oct 26 '13 at 14:50
add comment

/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.

share|improve this answer
2  
/dev/disk/by-id/*usb* is very helpful. –  Rob Dec 12 '11 at 18:56
    
/dev/disk/by-label ftw. Thanks :) –  Triptych Jun 17 '13 at 13:25
add comment

the simplest method to see what's going on is just typing (as root of course):

blkid -c /dev/null

this gives you a complete overview about all block devices even if not mounted

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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

share|improve this answer
add comment

For USB devices you can simply do

REMOVABLE_DRIVES=""
for _device in /sys/block/*/device; do
    if echo $(readlink -f $_device)|egrep -q "usb"; then
        _disk=`echo $_device | cut -f4 -d/`
        REMOVABLE_DRIVES="$REMOVABLE_DRIVES $_disk"
    fi
done
echo Removable drives found: $REMOVABLE_DRIVES
share|improve this answer
add comment

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

share|improve this answer
add comment

I think I found what you're looking for. Maybe the code snippet is helpful for you:

How to detect if /dev/* is a USB device?

share|improve this answer
add comment

Here is my updated answer for Ubuntu 10.04 LTS.
This will detect the external USB drives on boot every time.

# Become root
su

# Find USB devices.
# Search for sd
# :/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
#  
#  Disk /dev/sda: 160.0 GB, 160041885696 bytes
#  255 heads, 63 sectors/track, 19457 cylinders
#  Units = cylinders of 16065 * 512 = 8225280 bytes
#  Sector size (logical/physical): 512 bytes / 512 bytes
#  I/O size (minimum/optimal): 512 bytes / 512 bytes
#  Disk identifier: 0x00062bd5
#  
#     Device Boot      Start         End      Blocks   Id  System
#  /dev/sda1   *           1       19269   154778211   83  Linux
#  /dev/sda2           19270       19457     1510110    5  Extended
#  /dev/sda5           19270       19457     1510078+  82  Linux swap / Solaris
#  
#  Disk /dev/sdb: 500.1 GB, 500107862016 bytes
#  255 heads, 63 sectors/track, 60801 cylinders
#  Units = cylinders of 16065 * 512 = 8225280 bytes
#  Sector size (logical/physical): 512 bytes / 512 bytes
#  I/O size (minimum/optimal): 512 bytes / 512 bytes
#  Disk identifier: 0x00000000
#  
#     Device Boot      Start         End      Blocks   Id  System
#  /dev/sdb1               1       60801   488384001   83  Linux
#  
#  Disk /dev/sdc: 500.1 GB, 500107862016 bytes
#  255 heads, 63 sectors/track, 60801 cylinders
#  Units = cylinders of 16065 * 512 = 8225280 bytes
#  Sector size (logical/physical): 512 bytes / 512 bytes
#  I/O size (minimum/optimal): 512 bytes / 512 bytes
#  Disk identifier: 0xde504d75
#  
#     Device Boot      Start         End      Blocks   Id  System
#  /dev/sdc1               1       60801   488384001   83  Linux

# See properties of sd. devices
udevadm info --attribute-walk --name /dev/sdb1
udevadm info --attribute-walk --name /dev/sdd1

udevadm info -a -p `udevadm info -q path -n /dev/sdb1` | grep -e "SUBSYSTEM==" -e "KERNEL==" -e "ATTR{partition}==" -e "ATTR{size}==" -e "ATTRS{serial}==" 
#   KERNEL=="sdb1"
#   SUBSYSTEM=="block"
#   ATTR{partition}=="1"
#   ATTR{size}=="976768002"
#   ATTRS{serial}=="2HA4DF8P    "
#   ATTRS{serial}=="0000:02:0a.2"
udevadm info -a -p `udevadm info -q path -n /dev/sdc1` | grep -e "SUBSYSTEM==" -e "KERNEL==" -e "ATTR{partition}==" -e "ATTR{size}==" -e "ATTRS{serial}==" 
#   KERNEL=="sdc1"
#   SUBSYSTEM=="block"
#   ATTR{partition}=="1"
#   ATTR{size}=="976768002"
#   ATTRS{serial}=="2HA16NDX    "
#   ATTRS{serial}=="0000:02:0a.2"

# External hard drives
# d - delete all existing partitions
# n - add a new partition
#     p  - primary partition 
#     1  - partition number 1
#     83 - partition type: 83 Linux
# w - write table to disk and exit  
fdisk /dev/sdb
fdisk /dev/sdc

# Create ext2 filesystems on USB drives and format them
# I create ext2 not ext3 because for a while there was
# only ext2 filesystem support on Windows.
# I wanted to be able to read the filesystem from a
# Windows machine.
# Your needs may be different.
mkfs.ext2 /dev/sdb1
mkfs.ext2 /dev/sdc1

# Determine kernel version (see below)
uname -r

# Instruct udev to make symlinks for the drives based on the manufactor,
# size, or any number of properties about the device. That symlink will
# always point to that device regardless of what device node
# (ie /dev/sda, /dev/sdb) it ends up getting assigned. Then you can modify
# your fstab to use the symlink vs the device node, which in turn allows
# you to always address the device the same way.
# Put a hard return at the end so it would print
cat > /etc/udev/rules.d/85-usb-hd-fix.rules <<'EOF'
# Udevadm info starts with the device specified by the devpath and then
# walks up the chain of parent devices. It prints for every device
# found, all possible attributes in the udev rules key format.
#
# A rule to match, can be composed by the attributes of the device 
# (first paragraph or block of rules)
# and the attributes from one single parent device.
# (any paragraph or block of rules following the first paragraph or block of rules)
#
# For example, below we see some of the attributes of the device listed first
#   SUBSYSTEM
#   KERNEL
#   ATTR{partition}
#   ATTR{size}
# and the attribute from one single parent device listed last
#   ATTRS{serial}

# backup500
SUBSYSTEM=="block", KERNEL=="sd?1", ATTR{partition}=="1", ATTR{size}=="976768002" , ATTRS{serial}=="2HA4DF8P    ", SYMLINK+="backup500", GROUP="disk", MODE="0660"
# backup501
SUBSYSTEM=="block", KERNEL=="sd?1", ATTR{partition}=="1", ATTR{size}=="976768002" , ATTRS{serial}=="2HA16NDX    ", SYMLINK+="backup501", GROUP="disk", MODE="0660"

EOF

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

# Test udev
udevadm test /sys/block/sdb block
udevadm test /sys/block/sdc block

# Test udev
restart udev

# Install kernel for PentiumPro
sudo apt-get install linux-686

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

# Make sure that the external USB drives (identified by the udev system) 
# are not referenced in /etc/fstab
# 
# The current /etc/fstab file looks like:
cat /etc/fstab
# Should look like
# # /etc/fstab: static file system information.
# #
# # <file system> <mount point>   <type>  <options>       <dump>  <pass>
# proc            /proc           proc    defaults        0       0
# # /dev/sda1
# UUID=fb518094-0d3b-42f4-a1cc-a3fa659fcd8a /               ext3    relatime,errors=remount-ro 0       1
# # /dev/sda5
# UUID=b04dba06-114e-0fa5-f823-75a116ae2fc0 none            swap    sw              0       0
# /dev/scd0        /media/cdrom0    udf,iso9660 user,noauto,exec,utf8 0       0
# /dev/fd0         /media/floppy0   auto    rw,user,noauto,exec,utf8 0       0

# Install sdparm
apt-get update
apt-get install sdparm

# See the current state of the STANDBY drive flag
sdparm -al /dev/backup500
# This should be 1 (on/true/enabled)

# Set STANDBY to 0 (off/false/disabled)
sdparm --clear STANDBY -6 /dev/backup500

# See the current state of the STANDBY drive flag
# This should be 0 (off/false/disabled)
sdparm -al /dev/backup500

# Modify script /etc/rc.local to mount all filesystems in /etc/fstab
cat > /etc/rc.local <<'EOF'
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Set STANDBY to 0 (off/false/disabled) only on the Maxtor OneTouch enclosures
sdparm --clear STANDBY -6 /dev/backup500
sdparm --clear STANDBY -6 /dev/backup501

# Mount USB drives
mount -t ext2 -o rw,auto,user /dev/backup500 /mnt/backup500
mount -t ext2 -o rw,auto,user /dev/backup501 /mnt/backup501
exit 0

EOF

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

# Reboot
shutdown -r now

# The following should already be mounted automatically after the reboot
# If not mounted, mount manually
# mount /mnt/backup500
# mount /mnt/backup501

# Create or rename directories
# mkdir -p /mnt/backup501/backup501/files
# mkdir -p /mnt/backup500/backup500/files

# Create symbolic links
# /home/backup500  -> /mnt/backup500/backup500
# /home/backup501  -> /mnt/backup501/backup501
ln -s /mnt/backup500/backup500 /home
ln -s /mnt/backup501/backup501 /home
# To remove the links
# unlink /home/backup500
# unlink /home/backup501
share|improve this answer
add comment

# The following solution works on Ubuntu and other 
# Debian derived Linux distributions pre 10.4 Lucid Lynx.
# Earlier utilities udevtest and udevinfo have been replaced by udevadm
# For the udevadm answer see my post below.

# 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 ####################
share|improve this answer
add comment

protected by nhinkle Jan 2 '13 at 5:58

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.