-
-
Save danielewood/acf3dd68b3209ce75742585a2a314a75 to your computer and use it in GitHub Desktop.
Make address assignment reliable across drive swaps and reboots when paired with HP SAS Expanders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Reset the device's path variables and symlinks | |
KERNEL=="sd*", ENV{DEVTYPE}=="disk" SUBSYSTEM=="block", DRIVERS=="isci", PROGRAM="/usr/local/bin/udev-fix-intel-scu.sh $kernel $env{DEVPATH} $env{ID_PATH} $env{ID_WWN} $env{ID_SERIAL}", ENV{ID_PATH_TAG}="%c{1}", ENV{ID_PATH}="%c{4}", SYMLINK="disk/by-id/%c{2} disk/by-id/%c{3} disk/by-path/%c{4}" | |
KERNEL=="sd*", ENV{DEVTYPE}=="partition" SUBSYSTEM=="block", DRIVERS=="isci", PROGRAM="/usr/local/bin/udev-fix-intel-scu.sh $kernel $env{DEVPATH} $env{ID_PATH} $env{ID_WWN} $env{ID_SERIAL}", ENV{ID_PATH_TAG}="%c{1}", ENV{ID_PATH}="%c{4}", SYMLINK="disk/by-id/%c{2}-part%n disk/by-id/%c{3}-part%n disk/by-path/%c{4}-part%n" | |
### No modifications to symlinks or properties, used for testing | |
#KERNEL=="sd*", SUBSYSTEM=="block", DRIVERS=="isci", PROGRAM="/usr/local/bin/udev-fix-intel-scu.sh $kernel $env{DEVPATH} $env{ID_PATH} $env{ID_WWN} $env{ID_SERIAL}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Modified from https://gist.github.com/Toasty27/49da6175371cdde317e662fb8a7d078a | |
# udev rules:/usr/lib/udev/rules.d/68-fix-intel-scu.rules | |
# Needs to execute before 69-vdev.rules for vdev_id.conf to reference remapped paths. | |
# Script:/usr/local/bin/udev-fix-intel-scu.sh | |
# Changes make address assignment reliable across drive swaps and reboots when paired with HP SAS Expanders. | |
# Resultantant paths should look like: | |
# /dev/disk/by-path/pci-0000:03:00.0-sas-0x5001438020b95e-phy00 | |
# /dev/disk/by-path/pci-0000:03:00.0-sas-0x5001438020b95e-phy00-part1 | |
# /dev/disk/by-path/pci-0000:03:00.0-sas-0x5001438020b95e-phy00-part9 | |
# /dev/disk/by-path/pci-0000:03:00.0-sas-0x5001438020e51f-phy00 | |
# /dev/disk/by-path/pci-0000:03:00.0-sas-0x5001438020e51f-phy00-part1 | |
# /dev/disk/by-path/pci-0000:03:00.0-sas-0x5001438020e51f-phy00-part9 | |
# I trimmed the last two characters of the SAS expander address, | |
# as those seem to change with each disk, and replaced it with the port number on the expander. | |
### | |
# Get properties for the device | |
### | |
Dev=$1 | |
DevPath=$2 | |
IDPath=$3 | |
IDWWN=$4 | |
IDSerial=$5 | |
LOG_FILE=/var/log/udev-intel-scu-fix/dev-${1}.log | |
### Log initial values for properties | |
echo $(date) >> $LOG_FILE | |
echo "Vars:" >> $LOG_FILE | |
echo "$Dev" >> $LOG_FILE | |
echo "$DevPath" >> $LOG_FILE | |
echo "$IDPath" >> $LOG_FILE | |
echo "$IDWWN" >> $LOG_FILE | |
echo "$IDSerial" >> $LOG_FILE | |
echo "" >> $LOG_FILE | |
### | |
# Get the PCI host address and the SCSI device address | |
# This is done most reliably by enumerating the DEVPATH tree and greping | |
#+ for child values | |
### | |
DevHost=$(IFS='/' read -a array <<< $(echo $DevPath); printf '%s\n' "${array[@]}" | grep -B 1 host | grep -v host) | |
DevScsiID="$(IFS='/' read -a array <<< $(echo $DevPath); printf '%s\n' "${array[@]}" | grep -B 1 target | grep -v target | awk -F':' '{print $3}')" | |
printf -v DevScsiID "%02d" $DevScsiID | |
DevScsiID="phy$DevScsiID" | |
echo "Host: $DevHost Disk: $DevScsiID" >> $LOG_FILE | |
### | |
# Create the new ID_PATH and ID_PATH_TAG strings | |
# We're basically trying to copy the output of the `handle_scsi_default` | |
#+ function in the path_id builtin | |
### | |
newIDPath=`echo "${IDPath}-${DevScsiID}" | sed 's/..\-lun\-0//' | sed 's/'"${DevScsiID}-${DevScsiID}"'/'"${DevScsiID}"'/'` | |
newIDPathTag=$(echo $newIDPath | sed 's/:/_/g') | |
echo "Old ID_PATH: $IDPath" >> $LOG_FILE | |
echo "New ID_PATH: $newIDPath" >> $LOG_FILE | |
echo "" >> $LOG_FILE | |
echo "------------------------" >> $LOG_FILE | |
echo "" >> $LOG_FILE | |
### Output our modified properties for use by udev | |
echo "$newIDPathTag ata-$IDSerial wwn-$IDWWN $newIDPath" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment