Determine if a usb is mounted using lsusb data

19,807

Solution 1

My suggestion would be to use lsusb in conjunction with the dmesg command to determine if the USB device is mounted.

Here' a sample output from lsusb and dmesg from my Ubuntu machine. The output from dmesg includes the device number and product/vendor information reported by lsusb

dbala@ubuntu:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 001 Device 005: ID 0781:5530 SanDisk Corp. Cruzer U3 4gb SDCZ36

dbala@ubuntu:~$ dmesg | tail
[1084707.969418] usb 1-1: new high speed USB device number 5 using ehci_hcd
[1084708.119662] scsi5 : usb-storage 1-1:1.0
[1084709.120841] scsi 5:0:0:0: Direct-Access     SanDisk  Cruzer           1.19 PQ: 0   ANSI: 5
[1084709.125158] sd 5:0:0:0: Attached scsi generic sg2 type 0
[1084709.130677] sd 5:0:0:0: [sdb] 31266816 512-byte logical blocks: (16.0 GB/14.9 GiB)
[1084709.138819] sd 5:0:0:0: [sdb] Write Protect is off
[1084709.138821] sd 5:0:0:0: [sdb] Mode Sense: 43 00 00 00
[1084709.146812] sd 5:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[1084709.186467]  sdb: sdb1
[1084709.215365] sd 5:0:0:0: [sdb] Attached SCSI removable disk
dbala@ubuntu:~$ 

Solution 2

mount with no arguments will list all mounted file system. For example:

~ » mount                                                                                                                                                                                   wangbin@dhcp12-241
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=3988728k,nr_inodes=997182,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
/dev/sda1 on / type ext4 (rw,relatime,seclabel,data=ordered)

If you know your usb disk device, e.g./dev/sdb, you can try to search it in the output:

mount | grep '/dev/sdb'
Share:
19,807
Kraken18
Author by

Kraken18

Updated on June 15, 2022

Comments

  • Kraken18
    Kraken18 almost 2 years

    I'm trying to identify if a usb storage device (usb stick) is mounted or not on a linux distro (modified Ubuntu 10.04). At the moment I use the lsusb -v command and parse it to obtain the Bus, Device and ID of the USB device I'm interesed in.

    Bus:001 DEVICE:008 ID 0781:5560 SanDisk Corp. . . .

    What I ideally want is to be able to use the data I get from lsusb -v to determine if that usb has been mounted or not.

    I've never really fiddled in this area before (its kind of just ended up in my lap) any pointers would be appreciated. I've looked on here and other sites and learnt some interesting things but nothing that really gets me any closer. I can see in /proc/mount that the usb is mounted but can't match the info I get for the device with lsusb with what I get in cat /proc/mount, as this will form part of an application I need to be able to match one with another.

    FYI:The application is written in python and I'm under the constraint of not being able to use external libraries such as pyUSB. As I say any pointers/help would be greatly appreciated.

    Cheers