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 MOUNTPOINT sda 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 MOUNTPOINT sda 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 -l Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0006c7ae Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 41943039 20458496 8e Linux LVM Disk /dev/sdb: 6442 MB, 6442450944 bytes, 12582912 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk 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 LVM Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk 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 LVM Disk /dev/sdd: 2147 MB, 2147483648 bytes, 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x3990990c Device Boot Start End Blocks Id System Disk /dev/mapper/rhel-root: 18.8 GB, 18756927488 bytes, 36634624 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/vgdate-lvvol1: 306 MB, 306184192 bytes, 598016 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sde: 8022 MB, 8022654976 bytes, 15669248 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk 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 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk 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 -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 18G 4.6G 13G 26% / devtmpfs devtmpfs 911M 0 911M 0% /dev tmpfs tmpfs 921M 0 921M 0% /dev/shm tmpfs tmpfs 921M 8.4M 912M 1% /run tmpfs 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% /lvmFiles tmpfs tmpfs 185M 0 185M 0% /run/user/0
重新格式化為ext4格式:
[root@rhel7 ~]# mkfs.ext4 /dev/sde4 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 490560 inodes, 1958640 blocks 97932 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2006974464 60 block groups 32768 blocks per group, 32768 fragments per group 8176 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing 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]# ls lost+found testMyUsb [root@rhel7 MyUSB]#
使用df -hT命令查看掛載的USB設備:
[root@rhel7 MyUSB]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 18G 4.6G 13G 26% / devtmpfs devtmpfs 911M 0 911M 0% /dev tmpfs tmpfs 921M 0 921M 0% /dev/shm tmpfs tmpfs 921M 8.4M 912M 1% /run tmpfs 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% /lvmFiles tmpfs tmpfs 185M 0 185M 0% /run/user/0 /dev/sde4 ext4 7.3G 34M 6.9G 1% /mnt/MyUSB //已掛載成功了,大小為7.3GB [root@rhel7 MyUSB]#