3 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
4 shopt -s inherit_errexit
2>/dev
/null ||
: # ignore fail in bash < 4.4
6 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
8 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
11 # todo: we should make this be a service which sets the /sys/ value
12 # before the mount target or something like that, because if you hot
13 # plug a drive in, its ata number will change on reboot, meaning you
14 # have to remember to run this again and then reboot again.
16 # example from t8 kernel
17 # Sep 01 14:35:01 watson kernel: ata7.00: status: { DRDY }
18 # Sep 01 14:35:01 watson kernel: ata7.00: failed command: WRITE FPDMA QUEUED
19 # Sep 01 14:35:01 watson kernel: ata7.00: cmd 61/08:c0:b8:bf:ff/00:00:01:00:00/40 tag 24 ncq 4096 out
22 # https://wiki.archlinux.org/index.php/Solid_state_drive#Resolving_NCQ_errors
23 # evo-870 doesnt get along well with d16.
24 # 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
27 if [[ $1 == debug
]]; then
32 if [[ $1 == no-upgrub
]]; then
36 regex
='^.*-part[0-9]*$'
37 for path
in /dev
/disk
/by-id
/ata-Samsung_SSD_870
*; do
38 if [[ ! $path =~
$regex ]]; then
44 if [[ ! -e $byid ]]; then
45 if $debug; then echo "samsung 870 not plugged in or not found"; fi
56 depth
=$
(cat /sys
/block
/$dev/device
/queue_depth
)
57 if [[ $depth != 0 ]]; then
58 if grep -qF libata.force
=noncq
/proc
/cmdline
; then
59 echo $0: warning
, cant change queue_depth due to globally disabled ncq
62 echo "updating to 1 if not: cat /sys/block/$dev/device/queue_depth"
63 cat /sys
/block
/$dev/device
/queue_depth
65 echo 1 >/sys
/block
/$dev/device
/queue_depth
69 sys
=$
(readlink
/sys
/block
/$dev)
70 ata
=${sys#*/*/*/*/ata}
73 arg
=libata.force
=${ata}.00:noncq
75 if ! grep "^GRUB_CMDLINE_LINUX_DEFAULT=.*[\" ]${arg//./\\.}[\" ]" /etc
/default
/grub
; then
76 sed -ri "s/([\" ])libata.force=[^ ]+ */\1/g;s/^GRUB_CMDLINE_LINUX_DEFAULT=\"(.*)/GRUB_CMDLINE_LINUX_DEFAULT=\"$arg \1/" /etc
/default
/grub
78 echo "$0: warning: grub updated. you may want to reboot"
79 if type -P update-grub2
&>/dev
/null
; then