Compare commits

...

2 Commits

Author SHA1 Message Date
Dave Russell a9da09fc89
Update script version to v3.6.120 and add reboot option 3 weeks ago
Dave Russell 267808e3f7
Add --reboot option for NAS DSM updates 3 weeks ago
  1. 5
      CHANGES.txt
  2. 109
      syno_hdd_db.sh

5
CHANGES.txt

@ -1,3 +1,8 @@
v3.6.120
- Added --reboot option to reboot the NAS after a DSM update where the build number has changed.
- Only needed if NVMe volume or PCIe card need a 2nd reboot after DSM update.
- Note: This version of the script needs to run once to create the file that tracks the DSM build number.
v3.6.119 v3.6.119
- Bug fix for "cat: /sys/block//sys/block/sata1/device/vendor: No such file or directory" errors. Issue #554 - Bug fix for "cat: /sys/block//sys/block/sata1/device/vendor: No such file or directory" errors. Issue #554

109
syno_hdd_db.sh

@ -29,7 +29,7 @@
# /var/packages/StorageManager/target/ui/storage_panel.js # /var/packages/StorageManager/target/ui/storage_panel.js
scriptver="v3.6.119" scriptver="v3.6.120"
script=Synology_HDD_db script=Synology_HDD_db
repo="007revad/Synology_HDD_db" repo="007revad/Synology_HDD_db"
scriptname=syno_hdd_db scriptname=syno_hdd_db
@ -90,6 +90,9 @@ Options:
recent model IronWolf and IronWolf Pro drives. recent model IronWolf and IronWolf Pro drives.
For NAS with x86_64 CPUs only For NAS with x86_64 CPUs only
Installs IHM on '22 series and newer models (untested) Installs IHM on '22 series and newer models (untested)
--reboot Reboot after a DSM update when build number has changed
Only needed if NVMe volume or PCIe card need a 2nd
reboot after DSM update
-h, --help Show this help message -h, --help Show this help message
-v, --version Show the script version -v, --version Show the script version
@ -113,7 +116,8 @@ args=("$@")
# Check for flags with getopt # Check for flags with getopt
if options="$(getopt -o SIabcdefghijklmnopqrstuvwxyz0123456789 -l \ if options="$(getopt -o SIabcdefghijklmnopqrstuvwxyz0123456789 -l \
ssd:,ihm,restore,showedits,noupdate,nodbupdate,m2,force,incompatible,ram,pcie,wdda,email,autoupdate:,help,version,debug \ ssd:,ihm,restore,showedits,noupdate,nodbupdate,m2,force,\
incompatible,ram,pcie,wdda,email,autoupdate:,reboot,help,version,debug \
-- "$@")"; then -- "$@")"; then
eval set -- "$options" eval set -- "$options"
while true; do while true; do
@ -181,6 +185,9 @@ if options="$(getopt -o SIabcdefghijklmnopqrstuvwxyz0123456789 -l \
delay="0" delay="0"
fi fi
;; ;;
--reboot) # Reboot once more after major DSM update
do_reboot="yes"
;;
-h|--help) # Show usage options -h|--help) # Show usage options
usage usage
;; ;;
@ -238,6 +245,7 @@ if [[ $color != "no" ]]; then
Cyan='\e[0;36m' # ${Cyan} Cyan='\e[0;36m' # ${Cyan}
#White='\e[0;37m' # ${White} #White='\e[0;37m' # ${White}
Error='\e[41m' # ${Error} Error='\e[41m' # ${Error}
Warn='\e[47;31m' # ${Warn}
Off='\e[0m' # ${Off} Off='\e[0m' # ${Off}
else else
echo "" # For task scheduler email readability echo "" # For task scheduler email readability
@ -251,6 +259,18 @@ if [[ $( whoami ) != "root" ]]; then
exit 1 exit 1
fi fi
detect_scheduler(){
# Check if stdin is a terminal (interactive)
[ ! -t 0 ] && return 0
# Check parent process
local parent
parent=$(ps -p $PPID -o comm=)
[[ "$parent" =~ (systemd-run|sched|crond) ]] && return 0
return 1
}
# Get DSM major version # Get DSM major version
dsm=$(/usr/syno/bin/synogetkeyvalue /etc.defaults/VERSION majorversion) dsm=$(/usr/syno/bin/synogetkeyvalue /etc.defaults/VERSION majorversion)
if [[ $dsm -gt "6" ]]; then if [[ $dsm -gt "6" ]]; then
@ -306,7 +326,7 @@ fi
# Get StorageManager version # Get StorageManager version
storagemgrver=$(/usr/syno/bin/synopkg version StorageManager) storagemgrver=$(/usr/syno/bin/synopkg version StorageManager)
# Show StorageManager version # Show StorageManager version
if [[ $storagemgrver ]]; then echo -e "StorageManager $storagemgrver"; fi if [[ $storagemgrver ]]; then echo -e "- StorageManager $storagemgrver"; fi
# Get SynoOnlinePack version # Get SynoOnlinePack version
if [[ $dsmversion -gt "72" ]]; then if [[ $dsmversion -gt "72" ]]; then
@ -321,19 +341,20 @@ if [[ $dsmversion -gt "72" ]]; then
SOPinfo="/var/packages/SynoOnlinePack/INFO" SOPinfo="/var/packages/SynoOnlinePack/INFO"
fi fi
SOPpkgver="$(/usr/syno/bin/synogetkeyvalue $SOPinfo version)" SOPpkgver="$(/usr/syno/bin/synogetkeyvalue $SOPinfo version)"
echo -e "SynoOnlinePack$v2 version $SOPpkgver\n" #echo -e "SynoOnlinePack$v2 version $SOPpkgver\n"
else echo "- SynoOnlinePack$v2 version $SOPpkgver"
echo "" #else
# echo ""
fi fi
# Show host drive db version # Show host drive db version
if [[ -f "/var/lib/disk-compatibility/${model}_host_v7.version" ]]; then if [[ -f "/var/lib/disk-compatibility/${model}_host_v7.version" ]]; then
echo -n "${model}_host_v7 version " echo -n "- ${model}_host_v7 version "
cat "/var/lib/disk-compatibility/${model}_host_v7.version" cat "/var/lib/disk-compatibility/${model}_host_v7.version"
echo -e "\n" echo -e "\n"
fi fi
if [[ -f "/var/lib/disk-compatibility/${model}_host.version" ]]; then if [[ -f "/var/lib/disk-compatibility/${model}_host.version" ]]; then
echo -n "${model}_host version " echo -n "- ${model}_host version "
cat "/var/lib/disk-compatibility/${model}_host.version" cat "/var/lib/disk-compatibility/${model}_host.version"
echo -e "\n" echo -e "\n"
fi fi
@ -361,7 +382,7 @@ pause(){
# Check latest release with GitHub API # Check latest release with GitHub API
syslog_set(){ syslog_set(){
if [[ ${1,,} == "info" ]] || [[ ${1,,} == "warn" ]] || [[ ${1,,} == "err" ]]; then if [[ ${1,,} == "info" || ${1,,} == "warn" || ${1,,} == "err" ]]; then
if [[ $autoupdate == "yes" ]]; then if [[ $autoupdate == "yes" ]]; then
# Add entry to Synology system log # Add entry to Synology system log
/usr/syno/bin/synologset1 sys "$1" 0x11100000 "$2" /usr/syno/bin/synologset1 sys "$1" 0x11100000 "$2"
@ -447,7 +468,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
echo -e "\n${Cyan}There is a newer version of this script available.${Off}" echo -e "\n${Cyan}There is a newer version of this script available.${Off}"
echo -e "Current version: ${scriptver}\nLatest version: $tag" echo -e "Current version: ${scriptver}\nLatest version: $tag"
scriptdl="$scriptpath/$script-$shorttag" scriptdl="$scriptpath/$script-$shorttag"
if [[ -f ${scriptdl}.tar.gz ]] || [[ -f ${scriptdl}.zip ]]; then if [[ -f ${scriptdl}.tar.gz || -f ${scriptdl}.zip ]]; then
# They have the latest version tar.gz downloaded but are using older version # They have the latest version tar.gz downloaded but are using older version
echo "You have the latest version downloaded but are using an older version" echo "You have the latest version downloaded but are using an older version"
sleep 10 sleep 10
@ -457,7 +478,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
sleep 10 sleep 10
else else
if [[ $autoupdate == "yes" ]]; then if [[ $autoupdate == "yes" ]]; then
if [[ $age -gt "$delay" ]] || [[ $age -eq "$delay" ]]; then if [[ $age -gt "$delay" || $age -eq "$delay" ]]; then
echo "Downloading $tag" echo "Downloading $tag"
reply=y reply=y
else else
@ -557,7 +578,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
cleanup_tmp cleanup_tmp
# Notify of success (if there were no errors) # Notify of success (if there were no errors)
if [[ $copyerr != 1 ]] && [[ $permerr != 1 ]]; then if [[ $copyerr != 1 && $permerr != 1 ]]; then
echo -e "\n$tag ${scriptfile}$vids_txt$changestxt downloaded to: ${scriptpath}\n" echo -e "\n$tag ${scriptfile}$vids_txt$changestxt downloaded to: ${scriptpath}\n"
syslog_set info "$script successfully updated to $tag" syslog_set info "$script successfully updated to $tag"
@ -585,6 +606,16 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
fi fi
# Show if running in shell or via task scheduler
if detect_scheduler; then
echo "Running via task scheduler"
sch_task="yes"
else
echo "Running in interactive shell"
sch_task=""
fi
# Warn if script located on M.2 drive # Warn if script located on M.2 drive
get_script_vol() { get_script_vol() {
local script_root vol_num vg_name local script_root vol_num vg_name
@ -644,13 +675,20 @@ fi
vidfile="/usr/syno/etc.defaults/pci_vendor_ids.conf" vidfile="/usr/syno/etc.defaults/pci_vendor_ids.conf"
vidfile2="/usr/syno/etc/pci_vendor_ids.conf" vidfile2="/usr/syno/etc/pci_vendor_ids.conf"
reboot_file="${scriptpath}/syno_hdd_reboot.txt"
if [[ ! -f "$reboot_file" ]]; then
echo "Do NOT delete this file!" > "$reboot_file"
echo "It is used to track if DSM has updated." >> "$reboot_file"
synosetkeyvalue "$reboot_file" dsm_build "$buildnumber"
fi
set_writemostly(){ set_writemostly(){
# $1 is writemostly or -writemostly # $1 is writemostly or -writemostly
# $2 is sata1 or sas1 or sda etc # $2 is sata1 or sas1 or sda etc
local model local model
# Show drive model # Show drive model
model="$(cat /sys/block/"${2}"/device/model | xargs)" model="$(xargs < /sys/block/"${2}"/device/model)"
echo -e "${Yellow}$model${Off}" echo -e "${Yellow}$model${Off}"
if [[ ${1::2} == "sd" ]]; then if [[ ${1::2} == "sd" ]]; then
@ -694,8 +732,8 @@ if [[ $restore == "yes" ]]; then
unset IFS unset IFS
echo "" echo ""
if [[ ${#dbbakfiles[@]} -gt "0" ]] || [[ -f ${synoinfo}.bak ]] ||\ if [[ ${#dbbakfiles[@]} -gt "0" || -f ${synoinfo}.bak ||\
[[ -f ${dtb_file}.bak ]] || [[ -f ${adapter_cards}.bak ]] ; then -f ${dtb_file}.bak || -f ${adapter_cards}.bak ]] ; then
# Restore synoinfo.conf from backup # Restore synoinfo.conf from backup
if [[ -f ${synoinfo}.bak ]]; then if [[ -f ${synoinfo}.bak ]]; then
@ -1012,7 +1050,7 @@ getdriveinfo(){
# Get drive GB size # Get drive GB size
size_gb=$(get_size_gb "$1") size_gb=$(get_size_gb "$1")
if [[ -n "$size_gb" ]]; then # PR #187 if [[ -n "$size_gb" ]]; then # PR #187
if [[ $hdmodel ]] && [[ $fwrev ]]; then if [[ $hdmodel && $fwrev ]]; then
if /usr/syno/bin/synodisk --enum -t cache | grep -q /dev/"$(basename -- "$1")"; then if /usr/syno/bin/synodisk --enum -t cache | grep -q /dev/"$(basename -- "$1")"; then
# Is SATA M.2 SSD # Is SATA M.2 SSD
nvmelist+=("${hdmodel},${fwrev},${size_gb}") nvmelist+=("${hdmodel},${fwrev},${size_gb}")
@ -1039,7 +1077,7 @@ getm2info(){
# Get drive GB size # Get drive GB size
size_gb=$(get_size_gb "$1") size_gb=$(get_size_gb "$1")
if [[ $nvmemodel ]] && [[ $nvmefw ]]; then if [[ $nvmemodel && $nvmefw ]]; then
nvmelist+=("${nvmemodel},${nvmefw},${size_gb}") nvmelist+=("${nvmemodel},${nvmefw},${size_gb}")
drivelist+=("${nvmemodel}") drivelist+=("${nvmemodel}")
fi fi
@ -1086,7 +1124,7 @@ m2_drive(){
# Check if is NVMe or SATA M.2 SSD # Check if is NVMe or SATA M.2 SSD
if /usr/syno/bin/synodisk --enum -t cache | grep -q /dev/"$(basename -- "$1")"; then if /usr/syno/bin/synodisk --enum -t cache | grep -q /dev/"$(basename -- "$1")"; then
if [[ $2 == "nvme" ]] || [[ $2 == "nvc" ]]; then if [[ $2 == "nvme" || $2 == "nvc" ]]; then
# Fix unknown vendor id if needed. GitHub issue #161 # Fix unknown vendor id if needed. GitHub issue #161
# "Failed to get disk vendor" from synonvme --vendor-get # "Failed to get disk vendor" from synonvme --vendor-get
# causes "Unsupported firmware version" warning. # causes "Unsupported firmware version" warning.
@ -1118,7 +1156,7 @@ is_ssd(){
brand="$(cat /sys/block/"$1"/device/vendor)" brand="$(cat /sys/block/"$1"/device/vendor)"
if grep -q "$1" /proc/mdstat | grep -E 'raid5|raid6'; then if grep -q "$1" /proc/mdstat | grep -E 'raid5|raid6'; then
if [[ $show_trim_warning != "yes" ]] && [[ $brand != "Synology" ]]; then if [[ $show_trim_warning != "yes" && $brand != "Synology" ]]; then
show_trim_warning="yes" show_trim_warning="yes"
fi fi
fi fi
@ -1212,7 +1250,7 @@ fi
# Exit if no drives found # Exit if no drives found
if [[ ${#hdds[@]} -eq "0" ]] && [[ ${#nvmes[@]} -eq "0" ]]; then if [[ ${#hdds[@]} -eq "0" && ${#nvmes[@]} -eq "0" ]]; then
ding ding
echo -e "\n${Error}ERROR${Off} No drives found!" && exit 2 echo -e "\n${Error}ERROR${Off} No drives found!" && exit 2
fi fi
@ -1747,7 +1785,7 @@ enable_card(){
# $1 is the file # $1 is the file
# $2 is the section # $2 is the section
# $3 is the card model and mode # $3 is the card model and mode
if [[ -f $1 ]] && [[ -n $2 ]] && [[ -n $3 ]]; then if [[ -f $1 && -n $2 && -n $3 ]]; then
backupdb "$adapter_cards" long backupdb "$adapter_cards" long
backupdb "$adapter_cards2" long backupdb "$adapter_cards2" long
@ -1788,7 +1826,7 @@ dts_m2_card(){
sed -i '/^};/d' "$2" sed -i '/^};/d' "$2"
# Append PCIe M.2 card node to dts file # Append PCIe M.2 card node to dts file
if [[ $1 == E10M20-T1 ]] || [[ $1 == M2D20 ]]; then if [[ $1 == E10M20-T1 || $1 == M2D20 ]]; then
cat >> "$2" <<EOM2D cat >> "$2" <<EOM2D
$1 { $1 {
@ -2084,7 +2122,7 @@ if [[ $ssd == "yes" ]]; then
done done
# Set HDDs to writemostly if there's also internal SSDs # Set HDDs to writemostly if there's also internal SSDs
if [[ $internal_ssd_qty -gt "0" ]] && [[ ${#internal_hdds[@]} -gt "0" ]]; then if [[ $internal_ssd_qty -gt "0" && ${#internal_hdds[@]} -gt "0" ]]; then
# There are internal SSDs and HDDs # There are internal SSDs and HDDs
echo -e "\nSetting internal HDDs state to write_mostly" echo -e "\nSetting internal HDDs state to write_mostly"
for idrive in "${internal_hdds[@]}"; do for idrive in "${internal_hdds[@]}"; do
@ -2137,7 +2175,7 @@ smc=support_memory_compatibility
setting="$(/usr/syno/bin/synogetkeyvalue $synoinfo $smc)" setting="$(/usr/syno/bin/synogetkeyvalue $synoinfo $smc)"
settingbak="$(/usr/syno/bin/synogetkeyvalue $synoinfo.bak $smc)" settingbak="$(/usr/syno/bin/synogetkeyvalue $synoinfo.bak $smc)"
if [[ -z $settingbak ]] || [[ -z $setting ]]; then if [[ -z $settingbak || -z $setting ]]; then
# For older models that don't use "support_memory_compatibility" # For older models that don't use "support_memory_compatibility"
memcheck="/usr/lib/systemd/system/SynoMemCheck.service" memcheck="/usr/lib/systemd/system/SynoMemCheck.service"
memcheck_value="$(/usr/syno/bin/synosetkeyvalue "$memcheck" ExecStart)" memcheck_value="$(/usr/syno/bin/synosetkeyvalue "$memcheck" ExecStart)"
@ -2193,7 +2231,7 @@ fi
# Optionally set mem_max_mb to the amount of installed memory # Optionally set mem_max_mb to the amount of installed memory
if [[ $dsm -gt "6" ]]; then # DSM 6 as has no dmidecode if [[ $dsm -gt "6" ]]; then # DSM 6 as has no dmidecode
if [[ $ram == "yes" ]] && [[ -f /usr/sbin/dmidecode ]]; then if [[ $ram == "yes" && -f /usr/sbin/dmidecode ]]; then
# Get total amount of installed memory # Get total amount of installed memory
#IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory | grep "[Ss]ize") # GitHub issue #86, 87 #IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory | grep "[Ss]ize") # GitHub issue #86, 87
IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory |\ IFS=$'\n' read -r -d '' -a array < <(dmidecode -t memory |\
@ -2235,7 +2273,7 @@ if [[ $dsm -gt "6" ]]; then # DSM 6 as has no dmidecode
echo -e "\n${Error}ERROR${Off} Failed to change max memory!" echo -e "\n${Error}ERROR${Off} Failed to change max memory!"
fi fi
elif [[ $setting -gt "$ramtotal" ]] && [[ $setting -gt "$settingbak" ]]; # GitHub issue #107 elif [[ $setting -gt "$ramtotal" && $setting -gt "$settingbak" ]]; # GitHub issue #107
then then
# Fix setting is greater than both ramtotal and default in syninfo.conf.bak # Fix setting is greater than both ramtotal and default in syninfo.conf.bak
/usr/syno/bin/synosetkeyvalue "$synoinfo" mem_max_mb "$settingbak" /usr/syno/bin/synosetkeyvalue "$synoinfo" mem_max_mb "$settingbak"
@ -2457,9 +2495,9 @@ fi
# Enable creating pool on drives in M.2 adaptor card # Enable creating pool on drives in M.2 adaptor card
if [[ -f "$strgmgr" ]] && [[ $buildnumber -gt 42962 ]]; then if [[ -f "$strgmgr" && $buildnumber -gt 42962 ]]; then
# DSM 7.1.1 and later # DSM 7.1.1 and later
if [[ ${#m2cards[@]} -gt "0" ]] || [[ $forcepci == "yes" ]]; then if [[ ${#m2cards[@]} -gt "0" || $forcepci == "yes" ]]; then
if grep -q 'notSupportM2Pool_addOnCard' "$strgmgr"; then if grep -q 'notSupportM2Pool_addOnCard' "$strgmgr"; then
# Backup storage_panel.js" # Backup storage_panel.js"
@ -2601,15 +2639,26 @@ done
# Show TRIM warning if required # Show TRIM warning if required
if [[ $show_trim_warning == "yes" ]]; then if [[ $show_trim_warning == "yes" ]]; then
ding ding
echo -e "\n${Warning}WARNING${Off} Enabling SSD TRIM on drives in RAID 5, 6 or SHR with 3 more drives can" echo -e "\n${Warn}WARNING${Off} Enabling SSD TRIM on drives in RAID 5, 6 or SHR with 3 more drives can"
echo "result in data loss if the SSD/NVMe drives marks trimmed blocks as released." echo "result in data loss if the SSD/NVMe drives marks trimmed blocks as released."
echo "SSDs that use Method 1 are okay. Do NOT enable TRIM for SSDs that use Method 2." echo "SSDs that use Method 1 are okay. Do NOT enable TRIM for SSDs that use Method 2."
echo "See Why_is_SSD_TRIM_available_only_for_SSDs_in_the_compatibility_list here:" echo "See Why_is_SSD_TRIM_available_only_for_SSDs_in_the_compatibility_list here:"
echo "https://tinyurl.com/ssd-trim" echo "https://tinyurl.com/ssd-trim"
fi fi
# Show reboot message or reboot cleanly once if needed
if [[ $do_reboot == "yes" && $sch_task == "yes" ]];then
# Reboot cleanly after DSM update if needed
previous_build="$(synogetkeyvalue "$reboot_file" dsm_build)"
if [[ $buildnumber -gt "$previous_build" ]]; then
synosetkeyvalue "$reboot_file" dsm_build "$buildnumber" # Update buildnumber
echo -e "\nDSM has updated from build $previous_build to $buildnumber"
echo "Rebooting..."
synoshutdown --reboot # Reboot cleanly
exit
fi
elif [[ $dsm -eq "6" || $rebootmsg == "yes" ]]; then
# Show reboot message if required # Show reboot message if required
if [[ $dsm -eq "6" ]] || [[ $rebootmsg == "yes" ]]; then
echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes." echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes."
fi fi

Loading…
Cancel
Save