Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.


  Search this Thread
Old 10-30-2008, 04:34 AM   #1
LQ Newbie
Registered: Jan 2008
Posts: 14

Rep: Reputation: 0
how to get the device ID of a USB mass storage device


I need to mount a USB mass storage device (a memory stick) on to my linux.
from the output of "dmesg" I can see the device name/node is "sdb1".

At different times, when I inserted different USB drives, on different linux PCs I have seen this name in different ways. Sometimes its "sda" sometimes "sda1" etc.

My requirement is I should be able to mount the USB device from "C" program using the mount system call ie.

int mount(const char *source, const char *target, const char *filesystemtype,
unsigned long mountflags, const void *data);

So I need the device name/node everytime.

1) My question is say I hardcoded the device name as "sdb1" after reading the output of "dmesg" manually. Is the name going to be same everytime.
I may be using a different USB device etc.

2) Or is there a way to get the device name dynamically by invoking some linux system call, so that at startup I check this and mount accordingly.

Thanks in advance.
Old 10-30-2008, 05:58 AM   #2
Senior Member
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 5, Linux Lite
Posts: 4,312

Rep: Reputation: 210Reputation: 210Reputation: 210
The command lsusb will show you the device id. Depending on your system you may be able to run that command without having to be root first. Try:
as a normal user. If both fail switch to root and do:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mass storage device USB xeebeeeeeee Linux - Hardware 10 02-13-2008 12:11 PM
USB Mass storage Device purefan Linux - Hardware 15 06-06-2005 01:56 PM
usb - mass storage device d1l2w3 Mandriva 7 01-10-2005 10:10 PM
USB Mass Storage Device ebasi Linux - Hardware 2 12-23-2004 02:06 PM
Usb mass storage device laguna Linux - Hardware 4 08-12-2002 02:16 AM > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 09:49 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration