简体   繁体   English

查找USB硬盘驱动器的已安装卷和安装点

[英]Find mounted volumes and mountpoint of USB hard drives

I am trying to write a Python script to identify USB devices that did not get auto-mounted correctly in Linux. 我正在尝试编写Python脚本来识别未在Linux中正确自动安装的USB设备。 I am currently using subprocess and calling lsusb to gather the USB devices and then using PyUsb (A libusb 1.0 python wrap library) to find the category of the USB device so I can identify if it is a Mass Storage Media. 我目前正在使用subprocess进程并调用lsusb来收集USB设备,然后使用PyUsb(一个libusb 1.0 python包装库)来找到USB设备的类别,以便我可以确定它是否是大容量存储介质。 What I can't figure out is how to bridge the information I have into the mountpoint that belongs to that USB drive. 我不知道如何将我拥有的信息桥接到属于该USB驱动器的安装点。 I need a combination of Linux commands that will get me the information I can use to link a mountpoint to a specific USB device so I can use subprocess and some basic parsing to create the script. 我需要Linux命令的组合,这些命令将为我提供可用于将安装点链接到特定USB设备的信息,因此我可以使用subprocess和一些基本解析来创建脚本。 Or maybe some other way to do this with Python modules I haven't thought of using. 也许还有其他方法可以使用我从未想过使用的Python模块来做到这一点。

I found a way to do it using information from mount and fdisk . 我找到了一种使用mountfdisk信息的方法。 I wrote a python module that encapsulates everything if anyone has the need for something similar: https://github.com/arthurbayerlein/Python/blob/master/storage_media.py 我编写了一个python模块,如果有人需要类似的东西,它会封装所有内容: https : //github.com/arthurbayerlein/Python/blob/master/storage_media.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM