X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=fai%2Fconfig%2Ffiles%2Fusr%2Fbin%2Fmyncq%2Fkd;fp=fai%2Fconfig%2Ffiles%2Fusr%2Fbin%2Fmyncq%2Fkd;h=e2b6494a4b7b8a5bc5219bc0540e2ffc6ccfe9ec;hb=739efea3642e2f8a7a672c4600da152a27bedf1a;hp=0000000000000000000000000000000000000000;hpb=2fad38490e36bd2f0328b82c38448d9675e662e8;p=automated-distro-installer diff --git a/fai/config/files/usr/bin/myncq/kd b/fai/config/files/usr/bin/myncq/kd new file mode 100755 index 0000000..e2b6494 --- /dev/null +++ b/fai/config/files/usr/bin/myncq/kd @@ -0,0 +1,57 @@ +#!/bin/bash + +if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi +shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4 +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR + +[[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@" + +# https://wiki.archlinux.org/index.php/Solid_state_drive#Resolving_NCQ_errors +# evo-870 doesnt get along well with d16. +# Dmesg gives us an ata number we could disable specifically on the command line, but I've had that number change on me between oses, so reenabling ncq + +upgrub=true +if [[ $1 == no-upgrub ]]; then + upgrub=false +fi + +byid=/dev/disk/by-id/ata-Samsung_SSD_870_QVO_8TB_S5VUNG0N900656V +if [[ ! -e $byid ]]; then + # not plugged in we assume + exit 0 +fi + +dev=$(readlink $byid) +if [[ ! $dev ]]; then + exit 1 +fi + +dev=${dev##*/} + +depth=$(cat /sys/block/$dev/device/queue_depth) +if [[ $depth != 0 ]]; then + if grep -qF libata.force=noncq /proc/cmdline; then + echo $0: warning, cant change queue_depth due to globally disabled ncq + else + echo 1 >/sys/block/$dev/device/queue_depth + fi +fi + +sys=$(readlink /sys/block/$dev) +ata=${sys#*/*/*/*/ata} +ata=${ata%%/*} + +arg=libata.force=${ata}.00:noncq + +if ! grep "^GRUB_CMDLINE_LINUX_DEFAULT=.*[\" ]${arg//./\\.}[\" ]" /etc/default/grub; then + sed -ri "s/^GRUB_CMDLINE_LINUX_DEFAULT=\"(.*)/GRUB_CMDLINE_LINUX_DEFAULT=\"$arg \1/" /etc/default/grub + if $upgrub; then + echo "$0: warning: grub updated. you may want to reboot" + if type -P update-grub2 &>/dev/null; then + update-grub2 + else + update-grub + fi + fi +fi