我的实验环境:
- Windows宿主机
- VirtualBox虚拟化软件
- 一个Linux虚机
- 一个8G的USB磁盘
首先要让虚拟机能看到宿主机的USB设备,这是在VirtualBox中设置的。
选中虚机,右键选择“设置”菜单,再单击“USB设备”:
选中“启用USB控制器”,最右侧带+号的按钮为“USB筛选器”。可以看到我的USB磁盘,即“Generic Mass Storage [0105]”,其他的是我的手机,鼠标等。这个筛选器可根据USB设备的插拔状态动态显示。
跟踪/var/log/messages
文件,可以实时反映USB设备插拔的状态。
拔出USB磁盘时:
# tail -f /var/log/messages
...
Aug 22 16:13:11 oracle-19c-vagrant kernel: usb 1-1: USB disconnect, device number 2
插入USB磁盘时:
# tail -f /var/log/messages
...
Aug 22 16:13:21 oracle-19c-vagrant kernel: usb 1-1: new high-speed USB device number 3 using ehci-pci
Aug 22 16:13:21 oracle-19c-vagrant kernel: usb 1-1: New USB device found, idVendor=058f, idProduct=6387, bcdDevice= 1.05
Aug 22 16:13:21 oracle-19c-vagrant kernel: usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Aug 22 16:13:21 oracle-19c-vagrant kernel: usb 1-1: Product: Mass Storage
Aug 22 16:13:21 oracle-19c-vagrant kernel: usb 1-1: Manufacturer: Generic
Aug 22 16:13:21 oracle-19c-vagrant kernel: usb 1-1: SerialNumber: ACBA3715
Aug 22 16:13:21 oracle-19c-vagrant kernel: usb-storage 1-1:1.0: USB Mass Storage device detected
Aug 22 16:13:21 oracle-19c-vagrant kernel: scsi host3: usb-storage 1-1:1.0
Aug 22 16:13:22 oracle-19c-vagrant kernel: scsi 3:0:0:0: Direct-Access Generic Flash Disk 8.07 PQ: 0 ANSI: 4
Aug 22 16:13:22 oracle-19c-vagrant kernel: scsi 3:0:0:0: Attached scsi generic sg1 type 0
Aug 22 16:13:22 oracle-19c-vagrant kernel: sd 3:0:0:0: [sdb] 15728640 512-byte logical blocks: (8.05 GB/7.50 GiB)
Aug 22 16:13:22 oracle-19c-vagrant kernel: sd 3:0:0:0: [sdb] Write Protect is off
Aug 22 16:13:23 oracle-19c-vagrant kernel: sd 3:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Aug 22 16:13:23 oracle-19c-vagrant kernel: sdb: sdb1
Aug 22 16:13:23 oracle-19c-vagrant kernel: sd 3:0:0:0: [sdb] Attached SCSI removable disk
操作系统已经可以认到设备,sdb就是我的8G USB磁盘:
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 7.5G 0 disk
└─sdb1 8:17 1 7.5G 0 part
sda 8:0 0 37G 0 disk
├─sda2 8:2 0 36.5G 0 part
│ ├─vg_main-lv_swap 252:1 0 4G 0 lvm [SWAP]
│ └─vg_main-lv_root 252:0 0 32.5G 0 lvm /
└─sda1 8:1 0 500M 0 part /boot
但是,还需要mount,才能看到USB上文件系统的内容。
# mount /dev/sdb1 /mnt# ls -l /mnt
total 98456
drwxr-xr-x. 3 root root 4096 Mar 4 22:31 ????
-rwxr-xr-x. 1 root root 57769714 Mar 13 04:57 20240116 Oracle??????IT.pptx
-rwxr-xr-x. 1 root root 128 Dec 4 2023 autorun.inf
drwxr-xr-x. 5 root root 4096 Jan 30 2024 boot
-rwxr-xr-x. 1 root root 413738 Dec 4 2023 bootmgr
-rwxr-xr-x. 1 root root 1574256 Dec 4 2023 bootmgr.efi
drwxr-xr-x. 4 root root 4096 Jan 30 2024 efi
-rwxr-xr-x. 1 root root 32847218 Nov 14 2023 Oracle?????????IT.pptx
-rwxr-xr-x. 1 root root 8086988 May 31 22:22 Oracle?????????.pptx
-rwxr-xr-x. 1 root root 74184 Dec 4 2023 setup.exe
drwxr-xr-x. 12 root root 12288 Jan 30 2024 sources
drwxr-xr-x. 3 root root 4096 Jan 30 2024 support
drwxr-xr-x. 2 root root 4096 Jan 30 2024 System Volume Information# mount | grep sdb
/dev/sdb1 on /mnt type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)# umount /mnt
就是这样了,还有个遗留问题,就是中文还不能识别,后续再处理。
参考
- What do I do if the Chinese characters on a Linux ECS instance are garbled?