1
votes

I'm trying to write a script that make a list of connected USBs list like this:

  • MyFlash - ADATA
  • BootUSB - ADATA
  • MyBackup - SAN DISK

But I don't know how to identify the connected USB device is a storage one, and the volume name of it.

C/C++, Python, or Node.js help are welcome, and only under Linux OS.

I'm looking to mount and remount using code, but I think It will be easy to use Linux commands for this.

3
I'm pretty sure that external devices like that show up under the "sda, sdb, etc" list. - durbnpoisn
I know @durbnpoisn, but I'm looking how Linux mount it with the its name, there is a place where Linux gets USb storage information. Till now, using usb-devices command line, I can know that the connected device is a usb-storage. But the volume name, I'm still searching about it. - Ahmed Shendy
Do you mean the symbolic links at /dev/disk/by-label/*? - rodrigo
@rodrigo, mmm, I just found it now that any (previously) labeled USB storage that is connected to your system will get its label as a symbolic link under /dev/disk/by-label/. If It is not labeled previously, system won't create for it - Ahmed Shendy
But I don't know why if I do umount for the USB storage, its symbolic label gets deleted. I'm also can't see any details about my tablet. - Ahmed Shendy

3 Answers

0
votes

Give this a shot:

udevadm info -a -n /dev/usbdevice

Further info:

udevinfo -q all -n /dev/sda

Still further info:

lsusb -v
lshw
0
votes

Use the command blkid(8) to identify UUID, filesystem type, volume label, etc of your visible/formatted partitions in your system. It's used by the system scripts to collect information and mount filesystems, so you will have no problems in parsing its output.

0
votes

If is already mounted and is any of the following types of partitions you could see:

mount -l|grep -E 'fuseblk|vfat|ext4'