简体   繁体   English

我如何知道Linux中的下一个设备映射器?

[英]How do I know the next device mapper in Linux?

I'm trying to write an ansible playbook to automaticly scan new disks and put it into an existing VG and than extend it. 我正在尝试编写一个简单的剧本,以自动扫描新磁盘并将其放入现有的VG中,然后进行扩展。

Unfortunately I can't figure out how Linux knows the next device mapper for example (/dev/sdc), to create a perfect ansible playbook to execute this task for me. 不幸的是,我无法弄清楚Linux如何知道下一个设备映射器(例如/ dev / sdc),从而无法创建完美的ansible剧本来为我执行此任务。

Scanning new disk online: 在线扫描新磁盘:

echo 0 0 0 | tee /sys/class/scsi_host/host*/scan

Someone have any idea about this? 有人对此有任何想法吗?

Thanks. 谢谢。

You are using confusing terminology. 您正在使用令人困惑的术语。 Device mapper is framework which is used by LVM, occasionally one may use device mapper as name for devices created by applications which use device mapper. 设备映射器是LVM使用的框架,有时可能会使用device mapper作为由使用设备映射器的应用程序创建的设备的名称。 They are usually can be found in /dev/mapper. 通常可以在/ dev / mapper中找到它们。

/dev/sdc (and allo other /dev/sd[az][az]? ) are just block devices. / dev / sdc(以及其他/dev/sd[az][az]? )只是块设备。 They CAN be used by LVM to create PV (physical volume), but they aren't "device mapper". LVM可以使用它们来创建PV(物理体积),但是它们不是“设备映射器”。

Now to the answer: 现在来回答:

Linux uses 'next available in alphabet letter' for new device. Linux对新设备使用“下一个字母可用”。 Unfortunately, 'next available' for kernel and for user may be a different thing. 不幸的是,内核和用户的“下一个可用”可能是另一回事。 If device has been unplugged (or died, or rescanned with reset) and underlying device is marked as been still used, Linux will use 'next letter', so replugged /dev/sdc may appear as /dev/sdd , or, if /dev/sdd is busy, /dev/sde , down to /dev/sdja (I'm not sure where it ends, but there is no such thing as /dev/sdzz AFAIK). 如果设备已拔出(或死亡,或通过重置重新扫描),并且基础设备被标记为仍在使用,则Linux将使用“下一个字母”,因此重新插入的/dev/sdc可能显示为/dev/sdd ,或者,如果/dev/sdd忙于/dev/sde ,直到/dev/sdja (我不确定它在哪里结束,但是没有/dev/sdzz AFAIK这样的东西)。

If you want to identify your devices you may use symlinks provided by udev. 如果要标识设备,则可以使用udev提供的符号链接。 They are present in /dev/disk and reflects different way to identify devices: - by-id - device ID is used (usually name and vendor) - by-partuuid - by UUID of existing partition on disk - by-uuid - by generated UUID unique for each drive - by-path - by it's logical location. 它们存在于/dev/disk和反映了不同的方法来识别的设备: - by-id -设备ID用于(通常名称和供应商) - by-partuuid -通过现有分区的UUID在磁盘上- by-uuid -通过产生的每个驱动器的唯一UUID( by-path )由逻辑位置决定。

I thing last one is the best: If you plug your device in the same slot it would have same name in /dev/disk/by-path regardless of vendor, id, existing filesystems and state of other block devices. 最后一点是最好的:如果将设备插入相同的插槽,则无论供应商,id,现有文件系统和其他块设备的状态如何,其在/dev/disk/by-path名称都相同。

Here few examples of name you may find there: 在此可以找到一些名称示例:

  • pci-0000:00:1f.2-ata-3 - ATA disk #3 attached to a specific controller at PCI. pci-0000:00:1f.2-ata-3 -ATA磁盘#3附加到PCI上的特定控制器。
  • pci-0000:08:00.0-sas-0x50030480013afa6c-lun-0 - SAS drive with WWN 0x50030480013afa6c attached to a specific PCI controller. pci-0000:08:00.0-sas-0x50030480013afa6c-lun-0将WWN 0x50030480013afa6c连接到特定PCI控制器的SAS驱动器。
  • pci-0000:01:00.0-scsi-0:2:1:0 - 'strange' scsi device #2 attached to a specific PCI controller. pci-0000:01:00.0-scsi-0:2:1:0连接到特定PCI控制器的'strange'scsi设备#2。 In my case it is a hardware RAID by LSI. 就我而言,它是LSI的硬件RAID。

If you really want to handle new devices regardless of their names, please look at Udev scripts, which allows to reacts on new devices. 如果您真的想处理新设备而不管它们的名称如何,请查看Udev脚本,该脚本可对新设备做出反应。 Dealing with udev may be tricky, here example of such scripts in Ceph project: They process all disks with specific paritions ID automatically by udev rules: https://github.com/ceph/ceph/tree/master/udev 处理udev可能很棘手,这里是Ceph项目中此类脚本的示例:它们通过udev规则自动处理具有特定分区ID的所有磁盘: https : //github.com/ceph/ceph/tree/master/udev

What about this? 那这个呢?

- name: Find /sys/class/scsi_host hostX softlinks
  find:
    path: '/sys/class/scsi_host'
    file_type: link
    pattern: 'host*'
  register: _scsi_hosts

- name: Rescanning for new disks
  command: 'echo "- - -" > {{ item }}/scan'
  changed_when: false
  with_items: _scsi_hosts.files.path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM