Skip to content

Instantly share code, notes, and snippets.

@dghodgson
Last active January 3, 2019 23:41
Show Gist options
  • Save dghodgson/49da6175371cdde317e662fb8a7d078a to your computer and use it in GitHub Desktop.
Save dghodgson/49da6175371cdde317e662fb8a7d078a to your computer and use it in GitHub Desktop.
Major rewrite, Change ID_PATH to use `scsi_default` pattern, Add support for handling partitions
### 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}"
#!/bin/bash
###
# 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 block | grep -v block)
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="pci-${DevHost}-scsi-${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"
@dghodgson
Copy link
Author

89-fix-intel-scu.rules should obviously be copied to the /etc/udev/rules.d directory. The udev-fix-intel-scu.sh script should be installed to /usr/local/bin.

Script produces a string for use in the ID_PATH variable in the same format as the handle_scsi_default function from the path_id builtin. The script could easily be changed with a little work to match some other format, but I found this to produce the most reliable results.

I tried to make the script as generic as possible, so it could likely be used on other storage controllers without issue to produce the scsi_default format strings. However it's still a hack, so use at your own risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment