Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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/ $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/ $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/ $kernel $env{DEVPATH} $env{ID_PATH} $env{ID_WWN} $env{ID_SERIAL}"
# Get properties for the device
### 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
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"

This comment has been minimized.

Copy link
Owner Author

@Toasty27 Toasty27 commented Oct 22, 2017

89-fix-intel-scu.rules should obviously be copied to the /etc/udev/rules.d directory. The 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