本文主要是介绍如何判断/dev/sda1 是硬盘 还是U盘 ,查看文件系统格式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
利用 udevadm 查询的 硬盘 sda1信息
root@localhost:~# udevadm info --query=all --name=sda1
P: /devices/platform/soc/soc:aux_bus/3200000.sata/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
N: sda1
S: disk/by-id/ata-SATA_SSD_A46207871A8900469457-part1
S: disk/by-path/platform-3200000.sata-ata-1-part1
S: disk/by-uuid/72873cae-e72d-4347-8963-5a83effcb3d7
E: DEVLINKS=/dev/disk/by-id/ata-SATA_SSD_A46207871A8900469457-part1 /dev/disk/by-path/platform-3200000.sata-ata-1-part1 /dev/disk/by-uuid/72873cae-e72d-4347-8963-5a83effcb3d7
E: DEVNAME=/dev/sda1
E: DEVPATH=/devices/platform/soc/soc:aux_bus/3200000.sata/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
E: DEVTYPE=partition
E: ID_ATA=1
E: ID_ATA_DOWNLOAD_MICROCODE=1
E: ID_ATA_FEATURE_SET_APM=1
E: ID_ATA_FEATURE_SET_APM_CURRENT_VALUE=254
E: ID_ATA_FEATURE_SET_APM_ENABLED=1
E: ID_ATA_FEATURE_SET_HPA=1
E: ID_ATA_FEATURE_SET_HPA_ENABLED=1
E: ID_ATA_FEATURE_SET_PM=1
E: ID_ATA_FEATURE_SET_PM_ENABLED=1
E: ID_ATA_FEATURE_SET_SECURITY=1
E: ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
E: ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=2
E: ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=2
E: ID_ATA_FEATURE_SET_SMART=1
E: ID_ATA_FEATURE_SET_SMART_ENABLED=1
E: ID_ATA_ROTATION_RATE_RPM=0
E: ID_ATA_SATA=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN1=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN2=1
E: ID_ATA_WRITE_CACHE=1
E: ID_ATA_WRITE_CACHE_ENABLED=1
E: ID_BUS=ata
E: ID_FS_TYPE=ext4
E: ID_FS_USAGE=filesystem
E: ID_FS_UUID=72873cae-e72d-4347-8963-5a83effcb3d7
E: ID_FS_UUID_ENC=72873cae-e72d-4347-8963-5a83effcb3d7
E: ID_FS_VERSION=1.0
E: ID_MODEL=SATA_SSD
E: ID_MODEL_ENC=SATA\x20SSD\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
E: ID_PART_ENTRY_DISK=8:0
E: ID_PART_ENTRY_NUMBER=1
E: ID_PART_ENTRY_OFFSET=63
E: ID_PART_ENTRY_SCHEME=dos
E: ID_PART_ENTRY_SIZE=500118129
E: ID_PART_ENTRY_TYPE=0xc
E: ID_PART_TABLE_TYPE=dos
E: ID_PATH=platform-3200000.sata-ata-1
E: ID_PATH_TAG=platform-3200000_sata-ata-1
E: ID_REVISION=SAFM02.3
E: ID_SERIAL=SATA_SSD_A46207871A8900469457
E: ID_SERIAL_SHORT=A46207871A8900469457
E: ID_TYPE=disk
E: MAJOR=8
E: MINOR=1
E: PARTN=1
E: SUBSYSTEM=block
E: TAGS=:systemd:
E: USEC_INITIALIZED=5071225
利用 udevadm 查询的 U盘 sda1信息
root@localhost:~# udevadm info --query=all --name=sdb1
P: /devices/platform/soc/soc:aux_bus/2f00000.usb3/xhci-hcd.0.auto/usb2/2-1/2-1:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1
N: sdb1
S: disk/by-id/usb-Kingston_DataTraveler_3.0_408D5C1E8E4FB081E94BB9CE-0:0-part1
S: disk/by-label/YAFEI
S: disk/by-path/platform-xhci-hcd.0.auto-usb-0:1:1.0-scsi-0:0:0:0-part1
S: disk/by-uuid/606D-7B1D
E: DEVLINKS=/dev/disk/by-path/platform-xhci-hcd.0.auto-usb-0:1:1.0-scsi-0:0:0:0-part1 /dev/disk/by-id/usb-Kingston_DataTraveler_3.0_408D5C1E8E4FB081E94BB9CE-0:0-part1 /dev/disk/by-label/YAFEI /dev/disk/by-uuid/606D-7B1D
E: DEVNAME=/dev/sdb1
E: DEVPATH=/devices/platform/soc/soc:aux_bus/2f00000.usb3/xhci-hcd.0.auto/usb2/2-1/2-1:1.0/host1/target1:0:0/1:0:0:0/block/sdb/sdb1
E: DEVTYPE=partition
E: ID_BUS=usb
E: ID_FS_LABEL=YAFEI
E: ID_FS_LABEL_ENC=YAFEI
E: ID_FS_TYPE=vfat
E: ID_FS_USAGE=filesystem
E: ID_FS_UUID=606D-7B1D
E: ID_FS_UUID_ENC=606D-7B1D
E: ID_FS_VERSION=FAT32
E: ID_INSTANCE=0:0
E: ID_MODEL=DataTraveler_3.0
E: ID_MODEL_ENC=DataTraveler\x203.0
E: ID_MODEL_ID=1666
E: ID_PART_ENTRY_DISK=8:16
E: ID_PART_ENTRY_FLAGS=0x80
E: ID_PART_ENTRY_NUMBER=1
E: ID_PART_ENTRY_OFFSET=2048
E: ID_PART_ENTRY_SCHEME=dos
E: ID_PART_ENTRY_SIZE=30275584
E: ID_PART_ENTRY_TYPE=0xc
E: ID_PART_ENTRY_UUID=01dc4848-01
E: ID_PART_TABLE_TYPE=dos
E: ID_PART_TABLE_UUID=01dc4848
E: ID_PATH=platform-xhci-hcd.0.auto-usb-0:1:1.0-scsi-0:0:0:0
E: ID_PATH_TAG=platform-xhci-hcd_0_auto-usb-0_1_1_0-scsi-0_0_0_0
E: ID_REVISION=PMAP
E: ID_SERIAL=Kingston_DataTraveler_3.0_408D5C1E8E4FB081E94BB9CE-0:0
E: ID_SERIAL_SHORT=408D5C1E8E4FB081E94BB9CE
E: ID_TYPE=disk
E: ID_USB_DRIVER=usb-storage
E: ID_USB_INTERFACES=:080650:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Kingston
E: ID_VENDOR_ENC=Kingston
E: ID_VENDOR_ID=0951
E: MAJOR=8
E: MINOR=17
E: PARTN=1
E: SUBSYSTEM=block
E: TAGS=:systemd:
E: USEC_INITIALIZED=3240909653
判断 sda1是U盘还是硬盘 ?
if [ `udevadm info --query=all --name=sd$i$j | grep ID_BUS | grep ata -c` -eq 1 ];thenecho "This is Hard disk"fiif [ `udevadm info --query=all --name=sd$i$j | grep ID_BUS | grep usb -c` -eq 1 ];thenecho "This is U disk"fi
判断 sda1/mmcblk0p1 文件系统格式 ?
root@localhost:~# udevadm info --query=all --name=sdb1 | grep ID_FS_TYPE
E: ID_FS_TYPE=vfat
root@localhost:~#
root@localhost:~#
root@localhost:~#
root@localhost:~# udevadm info --query=all --name=mmcblk0p1 | grep ID_FS_TYPE
E: ID_FS_TYPE=ext3
这篇关于如何判断/dev/sda1 是硬盘 还是U盘 ,查看文件系统格式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!