在Linux系统中,扫描新增磁盘和识别新增磁盘的过程通常涉及到两个步骤:首先是使用fdisk -l
命令来扫描并列出所有磁盘设备,然后是使用udevadm monitor
命令来监控新设备的插入,接下来,我们将详细介绍这两个过程。
1、使用fdisk -l
命令扫描并列出所有磁盘设备:
fdisk -l
命令用于列出系统中所有的磁盘分区信息,在终端中输入以下命令即可:
sudo fdisk -l
运行该命令后,你将看到类似如下的输出:
Disk /dev/sda: 238.5 GiB, 25601049600 bytes, 500118192 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 identifier: 0x8c9d7a7e Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 131071 131064 50M eba /dev/sda2 131072 78633975 78623680 46G b W95 FAT32
在这个例子中,我们可以看到有两块磁盘设备:`/dev/sda`和`/dev/sdb`,这就是Linux系统扫描到的磁盘设备列表。
2、使用udevadm monitor
命令监控新设备的插入:
当新硬盘设备被插入时,Linux系统会自动触发一个事件,为了捕获这个事件并获取新设备的相关信息,我们可以使用udevadm monitor
命令,运行以下命令:
sudo udevadm monitor --poll --timeout=2 --status=health --name=/dev/sdb | grep 'add'
我们监控的是`/dev/sdb`设备,如果有新的设备被插入,你将看到类似如下的输出:
```
E: DevName-* (/dev/sdb) [event code] event type: add reason: added [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "" [{}] "识别到新设备(/dev/sdb)并触发了事件(add)" [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [], false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/99440.html