Browse Source

Update script version to v3.6.120 and add reboot option

Added a new option to reboot the NAS after DSM updates if the build number has changed, specifically for NVMe volumes or PCIe cards requiring a second reboot.
pull/560/head
Dave Russell 3 weeks ago
committed by GitHub
parent
commit
a9da09fc89
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 111
      syno_hdd_db.sh

111
syno_hdd_db.sh

@ -29,7 +29,7 @@
# /var/packages/StorageManager/target/ui/storage_panel.js
scriptver="v3.6.119"
scriptver="v3.6.120"
script=Synology_HDD_db
repo="007revad/Synology_HDD_db"
scriptname=syno_hdd_db
@ -90,6 +90,9 @@ Options:
recent model IronWolf and IronWolf Pro drives.
For NAS with x86_64 CPUs only
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
-v, --version Show the script version
@ -113,7 +116,8 @@ args=("$@")
# Check for flags with getopt
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
eval set -- "$options"
while true; do
@ -181,6 +185,9 @@ if options="$(getopt -o SIabcdefghijklmnopqrstuvwxyz0123456789 -l \
delay="0"
fi
;;
--reboot) # Reboot once more after major DSM update
do_reboot="yes"
;;
-h|--help) # Show usage options
usage
;;
@ -238,6 +245,7 @@ if [[ $color != "no" ]]; then
Cyan='\e[0;36m' # ${Cyan}
#White='\e[0;37m' # ${White}
Error='\e[41m' # ${Error}
Warn='\e[47;31m' # ${Warn}
Off='\e[0m' # ${Off}
else
echo "" # For task scheduler email readability
@ -251,6 +259,18 @@ if [[ $( whoami ) != "root" ]]; then
exit 1
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
dsm=$(/usr/syno/bin/synogetkeyvalue /etc.defaults/VERSION majorversion)
if [[ $dsm -gt "6" ]]; then
@ -306,7 +326,7 @@ fi
# Get StorageManager version
storagemgrver=$(/usr/syno/bin/synopkg version StorageManager)
# Show StorageManager version
if [[ $storagemgrver ]]; then echo -e "StorageManager $storagemgrver"; fi
if [[ $storagemgrver ]]; then echo -e "- StorageManager $storagemgrver"; fi
# Get SynoOnlinePack version
if [[ $dsmversion -gt "72" ]]; then
@ -321,19 +341,20 @@ if [[ $dsmversion -gt "72" ]]; then
SOPinfo="/var/packages/SynoOnlinePack/INFO"
fi
SOPpkgver="$(/usr/syno/bin/synogetkeyvalue $SOPinfo version)"
echo -e "SynoOnlinePack$v2 version $SOPpkgver\n"
else
echo ""
#echo -e "SynoOnlinePack$v2 version $SOPpkgver\n"
echo "- SynoOnlinePack$v2 version $SOPpkgver"
#else
# echo ""
fi
# Show host drive db version
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"
echo -e "\n"
fi
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"
echo -e "\n"
fi
@ -361,7 +382,7 @@ pause(){
# Check latest release with GitHub API
syslog_set(){
if [[ ${1,,} == "info" ]] || [[ ${1,,} == "warn" ]] || [[ ${1,,} == "err" ]]; then
if [[ ${1,,} == "info" || ${1,,} == "warn" || ${1,,} == "err" ]]; then
if [[ $autoupdate == "yes" ]]; then
# Add entry to Synology system log
/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 "Current version: ${scriptver}\nLatest version: $tag"
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
echo "You have the latest version downloaded but are using an older version"
sleep 10
@ -457,7 +478,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
sleep 10
else
if [[ $autoupdate == "yes" ]]; then
if [[ $age -gt "$delay" ]] || [[ $age -eq "$delay" ]]; then
if [[ $age -gt "$delay" || $age -eq "$delay" ]]; then
echo "Downloading $tag"
reply=y
else
@ -557,7 +578,7 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
cleanup_tmp
# 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"
syslog_set info "$script successfully updated to $tag"
@ -585,6 +606,16 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
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
get_script_vol() {
local script_root vol_num vg_name
@ -644,13 +675,20 @@ fi
vidfile="/usr/syno/etc.defaults/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(){
# $1 is writemostly or -writemostly
# $2 is sata1 or sas1 or sda etc
local model
# Show drive model
model="$(cat /sys/block/"${2}"/device/model | xargs)"
model="$(xargs < /sys/block/"${2}"/device/model)"
echo -e "${Yellow}$model${Off}"
if [[ ${1::2} == "sd" ]]; then
@ -694,8 +732,8 @@ if [[ $restore == "yes" ]]; then
unset IFS
echo ""
if [[ ${#dbbakfiles[@]} -gt "0" ]] || [[ -f ${synoinfo}.bak ]] ||\
[[ -f ${dtb_file}.bak ]] || [[ -f ${adapter_cards}.bak ]] ; then
if [[ ${#dbbakfiles[@]} -gt "0" || -f ${synoinfo}.bak ||\
-f ${dtb_file}.bak || -f ${adapter_cards}.bak ]] ; then
# Restore synoinfo.conf from backup
if [[ -f ${synoinfo}.bak ]]; then
@ -1012,7 +1050,7 @@ getdriveinfo(){
# Get drive GB size
size_gb=$(get_size_gb "$1")
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
# Is SATA M.2 SSD
nvmelist+=("${hdmodel},${fwrev},${size_gb}")
@ -1039,7 +1077,7 @@ getm2info(){
# Get drive GB size
size_gb=$(get_size_gb "$1")
if [[ $nvmemodel ]] && [[ $nvmefw ]]; then
if [[ $nvmemodel && $nvmefw ]]; then
nvmelist+=("${nvmemodel},${nvmefw},${size_gb}")
drivelist+=("${nvmemodel}")
fi
@ -1086,7 +1124,7 @@ m2_drive(){
# Check if is NVMe or SATA M.2 SSD
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
# "Failed to get disk vendor" from synonvme --vendor-get
# causes "Unsupported firmware version" warning.
@ -1118,7 +1156,7 @@ is_ssd(){
brand="$(cat /sys/block/"$1"/device/vendor)"
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"
fi
fi
@ -1212,7 +1250,7 @@ fi
# Exit if no drives found
if [[ ${#hdds[@]} -eq "0" ]] && [[ ${#nvmes[@]} -eq "0" ]]; then
if [[ ${#hdds[@]} -eq "0" && ${#nvmes[@]} -eq "0" ]]; then
ding
echo -e "\n${Error}ERROR${Off} No drives found!" && exit 2
fi
@ -1747,7 +1785,7 @@ enable_card(){
# $1 is the file
# $2 is the section
# $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_cards2" long
@ -1788,7 +1826,7 @@ dts_m2_card(){
sed -i '/^};/d' "$2"
# 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
$1 {
@ -2084,7 +2122,7 @@ if [[ $ssd == "yes" ]]; then
done
# 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
echo -e "\nSetting internal HDDs state to write_mostly"
for idrive in "${internal_hdds[@]}"; do
@ -2137,7 +2175,7 @@ smc=support_memory_compatibility
setting="$(/usr/syno/bin/synogetkeyvalue $synoinfo $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"
memcheck="/usr/lib/systemd/system/SynoMemCheck.service"
memcheck_value="$(/usr/syno/bin/synosetkeyvalue "$memcheck" ExecStart)"
@ -2193,7 +2231,7 @@ fi
# Optionally set mem_max_mb to the amount of installed memory
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
#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 |\
@ -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!"
fi
elif [[ $setting -gt "$ramtotal" ]] && [[ $setting -gt "$settingbak" ]]; # GitHub issue #107
elif [[ $setting -gt "$ramtotal" && $setting -gt "$settingbak" ]]; # GitHub issue #107
then
# Fix setting is greater than both ramtotal and default in syninfo.conf.bak
/usr/syno/bin/synosetkeyvalue "$synoinfo" mem_max_mb "$settingbak"
@ -2457,9 +2495,9 @@ fi
# 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
if [[ ${#m2cards[@]} -gt "0" ]] || [[ $forcepci == "yes" ]]; then
if [[ ${#m2cards[@]} -gt "0" || $forcepci == "yes" ]]; then
if grep -q 'notSupportM2Pool_addOnCard' "$strgmgr"; then
# Backup storage_panel.js"
@ -2601,15 +2639,26 @@ done
# Show TRIM warning if required
if [[ $show_trim_warning == "yes" ]]; then
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 "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 "https://tinyurl.com/ssd-trim"
fi
# Show reboot message if required
if [[ $dsm -eq "6" ]] || [[ $rebootmsg == "yes" ]]; then
# 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
echo -e "\nYou may need to ${Cyan}reboot the Synology${Off} to see the changes."
fi

Loading…
Cancel
Save