I'm trying to write an ansible playbook to automaticly scan new disks and put it into an existing VG and than extend it.
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.
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. They are usually can be found in /dev/mapper.
/dev/sdc (and allo other /dev/sd[az][az]?
) are just block devices. They CAN be used by LVM to create PV (physical volume), but they aren't "device mapper".
Now to the answer:
Linux uses 'next available in alphabet letter' for new device. 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).
If you want to identify your devices you may use symlinks provided by 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.
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.
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:08:00.0-sas-0x50030480013afa6c-lun-0
- SAS drive with WWN 0x50030480013afa6c attached to a specific PCI controller. pci-0000:01:00.0-scsi-0:2:1:0
- 'strange' scsi device #2 attached to a specific PCI controller. In my case it is a hardware RAID by LSI. If you really want to handle new devices regardless of their names, please look at Udev scripts, which allows to reacts on new devices. 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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.