博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux系统下查看USB设备名及使用USB设备
阅读量:6792 次
发布时间:2019-06-26

本文共 9424 字,大约阅读时间需要 31 分钟。

 

1、系统插入USB设备后,从控制台界面有如下提示:

从控制台信息可以看出插入的USB设备名。

从上图可以看出,插入的USB设备为sde4。

但是,如果是CRT工具远程连接过去,可以使用下面的命令来查看USB设备。

2、使用lsblk命令查找USB设备名

lsblk命令用于列出所有可用块设备的信息,而且还能显示他们之间的依赖关系,但是它不会列出RAM盘的信息。块设备有硬盘,闪存盘,cd-ROM等等。

如下所示:

[root@rhel7 ~]# lsblk  --插入USB设备前的分区情况NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsda                 8:0    0   20G  0 disk ├─sda1              8:1    0  500M  0 part /boot└─sda2              8:2    0 19.5G  0 part   ├─rhel-root     253:0    0 17.5G  0 lvm  /  └─rhel-swap     253:1    0    2G  0 lvm  [SWAP]sdb                 8:16   0    6G  0 disk ├─sdb1              8:17   0  100M  0 part ├─sdb2              8:18   0  110M  0 part └─sdb3              8:19   0  120M  0 part sdc                 8:32   0    5G  0 disk ├─sdc1              8:33   0  100M  0 part │ └─vgdate-lvvol1 253:2    0  292M  0 lvm  /lvmFiles├─sdc2              8:34   0  200M  0 part │ └─vgdate-lvvol1 253:2    0  292M  0 lvm  /lvmFiles├─sdc3              8:35   0  200M  0 part └─sdc4              8:36   0  250M  0 part sdd                 8:48   0    2G  0 disk sr0                11:0    1 1024M  0 rom  [root@rhel7 ~]# lsblk  --插入USB设备后的分区情况NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTsda                 8:0    0   20G  0 disk ├─sda1              8:1    0  500M  0 part /boot└─sda2              8:2    0 19.5G  0 part   ├─rhel-root     253:0    0 17.5G  0 lvm  /  └─rhel-swap     253:1    0    2G  0 lvm  [SWAP]sdb                 8:16   0    6G  0 disk ├─sdb1              8:17   0  100M  0 part ├─sdb2              8:18   0  110M  0 part └─sdb3              8:19   0  120M  0 part sdc                 8:32   0    5G  0 disk ├─sdc1              8:33   0  100M  0 part │ └─vgdate-lvvol1 253:2    0  292M  0 lvm  /lvmFiles├─sdc2              8:34   0  200M  0 part │ └─vgdate-lvvol1 253:2    0  292M  0 lvm  /lvmFiles├─sdc3              8:35   0  200M  0 part └─sdc4              8:36   0  250M  0 part sdd                 8:48   0    2G  0 disk sde                 8:64   1  7.5G  0 disk └─sde4              8:68   1  7.5G  0 part sr0                11:0    1 1024M  0 rom  [root@rhel7 ~]#
从上面的输出信息可以看出,设备为sde,为第一个分区sde4,大小为7.5GB sde                 8:64   1  7.5G  0 disk └─sde4              8:68   1  7.5G  0 part

3、使用fdisk工具识别USB设备名

fdisk是一个功能强大的工具,用于查看你系统中的所有分区表,包括所有的USB设备,使用root权限执行如下命令:

[root@rhel7 ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0006c7ae   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *        2048     1026047      512000   83  Linux/dev/sda2         1026048    41943039    20458496   8e  Linux LVMDisk /dev/sdb: 6442 MB, 6442450944 bytes, 12582912 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xaa06e007   Device Boot      Start         End      Blocks   Id  System/dev/sdb1            2048      206847      102400   8e  Linux LVM/dev/sdb2          206848      432127      112640   8e  Linux LVM/dev/sdb3          432128      677887      122880   8e  Linux LVMDisk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0c16d904   Device Boot      Start         End      Blocks   Id  System/dev/sdc1            2048      206847      102400   8e  Linux LVM/dev/sdc2          206848      616447      204800   8e  Linux LVM/dev/sdc3          616448     1026047      204800   8e  Linux LVM/dev/sdc4         1026048     1538047      256000   8e  Linux LVMDisk /dev/sdd: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x3990990c   Device Boot      Start         End      Blocks   Id  SystemDisk /dev/mapper/rhel-root: 18.8 GB, 18756927488 bytes, 36634624 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/vgdate-lvvol1: 306 MB, 306184192 bytes, 598016 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/sde: 8022 MB, 8022654976 bytes, 15669248 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xcad4ebea   Device Boot      Start         End      Blocks   Id  System/dev/sde4   *          63    15669184     7834561    7  HPFS/NTFS/exFAT[root@rhel7 ~]#

从上图可以看出USB设备的信息如下:

Disk /dev/sde: 8022 MB, 8022654976 bytes, 15669248 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xcad4ebea   Device Boot      Start         End      Blocks   Id  System/dev/sde4   *          63    15669184     7834561    7  HPFS/NTFS/exFAT

使用dmesg命令来识别出USB设备名

dmesg是一个重要的用于打印或者控制内核环形缓冲区的命令。环形缓冲区是一种数据结构,它存放着内核操作数据的信息。

运行如下的命令来查看内核操作信息,它同时也会打印出USB设备的信息:

……[ 1055.720971]  sde: sde4[ 1055.816921] sd 6:0:0:0: [sde] Attached SCSI removable disk[ 1168.185175] usb 1-1: USB disconnect, device number 6[ 1250.915177] usb 1-1: new full-speed USB device number 7 using ohci-pci[ 1251.361378] usb 1-1: New USB device found, idVendor=8644, idProduct=800b[ 1251.364410] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3[ 1251.367812] usb 1-1: Product: USB Flash Disk                [ 1251.370072] usb 1-1: Manufacturer: General                       [ 1251.372505] usb 1-1: SerialNumber: 000000000000C4FC[ 1251.378864] usb-storage 1-1:1.0: USB Mass Storage device detected[ 1251.383180] scsi host7: usb-storage 1-1:1.0[ 1252.415350] scsi 7:0:0:0: Direct-Access     General  USB Flash Disk   1.00 PQ: 0 ANSI: 2[ 1252.424925] sd 7:0:0:0: Attached scsi generic sg5 type 0[ 1252.451723] sd 7:0:0:0: [sde] 15669248 512-byte logical blocks: (8.02 GB/7.47 GiB)[ 1252.481780] sd 7:0:0:0: [sde] Write Protect is off[ 1252.484715] sd 7:0:0:0: [sde] Mode Sense: 03 00 00 00[ 1252.507694] sd 7:0:0:0: [sde] No Caching mode page found[ 1252.510073] sd 7:0:0:0: [sde] Assuming drive cache: write through[ 1252.624206]  sde: sde4[ 1252.722176] sd 7:0:0:0: [sde] Attached SCSI removable disk[root@rhel7 ~]#

其实上面的信息就是刚插入USB设备时服务器控制台上输出的信息。

查看USB设备内的文件:

从上面的信息可以看出,虽然USB设备已插入到Linux系统,但是挂载点mounted on是为空的,也就是还没有完成挂载,必须先挂载后才能使用。

[root@rhel7 ~]# mkdir -p /mnt/MyUSB[root@rhel7 ~]# mount /dev/sde4 /mnt/MyUSB/mount: unknown filesystem type 'ntfs'[root@rhel7 ~]# df -hTFilesystem                Type      Size  Used Avail Use% Mounted on/dev/mapper/rhel-root     xfs        18G  4.6G   13G  26% /devtmpfs                  devtmpfs  911M     0  911M   0% /devtmpfs                     tmpfs     921M     0  921M   0% /dev/shmtmpfs                     tmpfs     921M  8.4M  912M   1% /runtmpfs                     tmpfs     921M     0  921M   0% /sys/fs/cgroup/dev/sda1                 xfs       497M  124M  374M  25% /boot/dev/mapper/vgdate-lvvol1 xfs       289M   16M  274M   6% /lvmFilestmpfs                     tmpfs     185M     0  185M   0% /run/user/0

重新格式化为ext4格式:

[root@rhel7 ~]# mkfs.ext4 /dev/sde4mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks490560 inodes, 1958640 blocks97932 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=200697446460 block groups32768 blocks per group, 32768 fragments per group8176 inodes per groupSuperblock backups stored on blocks:         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done                            Writing inode tables: done                            Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information:      done

重新挂载后就可以使用了:

[root@rhel7 ~]# mount /dev/sde4 /mnt/MyUSB/[root@rhel7 ~]# cd /mnt/MyUSB/[root@rhel7 MyUSB]# touch testMyUsb[root@rhel7 MyUSB]# lslost+found  testMyUsb[root@rhel7 MyUSB]#

使用df -hT命令查看挂载的USB设备:

[root@rhel7 MyUSB]# df -hTFilesystem                Type      Size  Used Avail Use% Mounted on/dev/mapper/rhel-root     xfs        18G  4.6G   13G  26% /devtmpfs                  devtmpfs  911M     0  911M   0% /devtmpfs                     tmpfs     921M     0  921M   0% /dev/shmtmpfs                     tmpfs     921M  8.4M  912M   1% /runtmpfs                     tmpfs     921M     0  921M   0% /sys/fs/cgroup/dev/sda1                 xfs       497M  124M  374M  25% /boot/dev/mapper/vgdate-lvvol1 xfs       289M   16M  274M   6% /lvmFilestmpfs                     tmpfs     185M     0  185M   0% /run/user/0/dev/sde4                 ext4      7.3G   34M  6.9G   1% /mnt/MyUSB   //已挂载成功了,大小为7.3GB[root@rhel7 MyUSB]#

  

转载地址:http://ngago.baihongyu.com/

你可能感兴趣的文章
C++初学者请进--------关于学好C++的经典资料汇总
查看>>
checkbox设置复选框的只读效果不让用户勾选
查看>>
Golang 源码阅读 os.File
查看>>
IE 6 下出现 双倍距离 以及解决方案
查看>>
LayaAir 自旋转的小球跟随鼠标移动
查看>>
linux nginx 指定目录不可执行php文件
查看>>
django环境搭建
查看>>
共享 iOS沙盒文件管理
查看>>
MIME
查看>>
CMPopTipView
查看>>
windows系统下安装虚拟机-mac系统-视频教程
查看>>
spring ContentNegotiatingViewResolver---负责调用不同的j
查看>>
嵌入式Linux C编程 03
查看>>
华为聚簇表聚簇索引原理
查看>>
数据挖掘笔记
查看>>
Nginx配置性能优化
查看>>
Ubuntu下安装numpy and matplotlib
查看>>
Spring 统一管理输出
查看>>
LEXUS OPENCART 自适应主题模板 ABC-0019-01 HIGHLIGHTED FEA
查看>>
设置ListView页眉注意事项
查看>>