Skip to content

Commit

Permalink
Merge pull request #19 from 007revad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
007revad authored Jul 15, 2023
2 parents 5a296ea + 23d3701 commit a4efbe1
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 87 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v1.0.5
- Changed RAID-F1 references to RAID-Group.
- Changed to reload the script after it updates itself to a new version.
- Changed to restore settings from backup instead of replacing synoinf.conf with the backup.
- Minor fixes and improvements.

v1.0.4
- Removed Restore menu choice as it was not needed.
- And was dangerous to restore synoinfo.conf from a backup in case it was made while using an older DSM version.
Expand Down
35 changes: 10 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
# Synology RAID-F1 SHR switch
# Synology RAID-Group SHR switch

<a href="https://github.com/007revad/Synology_RAID-F1_SHR_switch/releases"><img src="https://img.shields.io/github/release/007revad/Synology_RAID-F1_SHR_switch.svg"></a>
<a href="https://hits.seeyoufarm.com"><img src="https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2F007revad%2FSynology_RAID-F1_SHR_switch&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false"/></a>
[![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/007revad)

### Description

Easily switch between SHR and RAID F1
Easily switch between SHR and RAID Group

This script allows you to switch from SHR to RAID F1, or from RAID F1 to SHR. It backs up the synoinfo.conf first, so you can restore it later if needed.

**Notes:**

1. You need 3 or more SSD drives to be able to user RAID F1.

2. Changing to RAID F1 disables SHR, and changing to SHR disables RAID F1.
- I would ***not*** change from SHR to RAID F1 if you already have a storage pool containg data setup as SHR.
- I would ***not*** change from RAID F1 to SHR if you already have a storage pool containg data setup as RAID F1.

### What is RAID F1

RAID F1 is Synology's RAID 5 for all flash (SSD) storage pools that tries to ensure that multiple SSD drives don't reach the end of thier life at the same time. F stands for flash, and 1 stands for 1-disk resiliency and 1-parity.

See Synology's <a href="https://global.download.synology.com/download/Document/Software/WhitePaper/Firmware/DSM/All/enu/Synology_RAID_F1_WP.pdf">RAID F1 whitepaper</a>

Also see: <a href="https://www.insight.com/en_US/content-and-resources/2017/01112017-rethinking-raid-in-all-flash-environments.html">Synology RAID F1: Rethinking RAID in all-Flash Environments</a>
This script allows you to switch from SHR to RAID Group, or from RAID Group to SHR. It backs up the synoinfo.conf first, so you can restore it later if needed.

## Download the script

Expand All @@ -48,14 +32,15 @@ sudo -i /volume1/scripts/syno_raidf1_shr_switch.sh

## Screenshots

<p align="center">Switch to RAID F1</p>
<p align="center"><img src="/images/raidf1_shr-switch_raidf12.png"></p>
<p align="center">Check currently set RAID type</p>
<p align="center"><img src="/images/raidgroup_shr-switch_check.png"></p>

<p align="center">Switch to SHR</p>
<p align="center"><img src="/images/raidf1_shr-switch_shr.png"></p>
<p align="center"><img src="/images/raidgroup_shr-switch_shr.png"></p>

<p align="center">Switch to RAID Group</p>
<p align="center"><img src="/images/raidgroup_shr-switch_raidgroup.png"></p>

<p align="center">Restore from the backup</p>
<p align="center"><img src="/images/raidf1_shr-switch_restored2.png"></p>
<p align="center"><img src="/images/raidgroup_shr-switch_restored.png"></p>

<p align="center">Check currently set RAID type</p>
<p align="center"><img src="/images/raidf1_shr-switch_check.png"></p>
Binary file added images/raidgroup_shr-switch_check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/raidgroup_shr-switch_raidgroup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/raidgroup_shr-switch_restored.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/raidgroup_shr-switch_shr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
161 changes: 99 additions & 62 deletions syno_raidf1_shr_switch.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Enables using non-Synology NVMe drives so you can create a storage pool
# and volume on any M.2 drive(s) entirely in DSM Storage Manager.
# Switch between SHR and RAID Group for models that have SHR & SHR-2 disabled
#
# Github: https://github.com/007revad/Synology_RAID-F1_SHR_switch
# Script verified at https://www.shellcheck.net/
#
# To run in a shell (replace /volume1/scripts/ with path to script):
# sudo /volume1/scripts/syno_raidf1_shr_switch.sh
#
# https://kb.synology.com/en-ro/DSM/tutorial/Which_Synology_NAS_models_support_RAID_F1
#------------------------------------------------------------------------------

scriptver="v1.0.4"
scriptver="v1.0.5"
script=Synology_RAID-F1_SHR_switch
repo="007revad/Synology_RAID-F1_SHR_switch"

# Check BASH variable is is non-empty and posix mode is off, else abort with error.
[ "$BASH" ] && ! shopt -qo posix || {
printf >&2 "This is a bash script, don't run it with sh\n"
scriptshow=Synology_RAID-Group_SHR_switch

# Check BASH variable is bash
if [ ! "$(basename "$BASH")" = bash ]; then
echo "This is a bash script. Do not run it with $(basename "$BASH")"
printf \\a
exit 1
}
fi

#echo -e "bash version: $(bash --version | head -1 | cut -d' ' -f4)\n" # debug

Expand All @@ -39,7 +39,7 @@ Off='\e[0m' # ${Off}

usage(){
cat <<EOF
$script $scriptver - by 007revad
$scriptshow $scriptver - by 007revad
Usage: $(basename "$0") [options]
Expand All @@ -49,41 +49,46 @@ Options:
-v, --version Show the script version
EOF
exit 0
}

scriptversion(){
cat <<EOF
$script $scriptver - by 007revad
$scriptshow $scriptver - by 007revad
See https://github.com/$repo
EOF
exit 0
}


# Save options used
args=("$@")


# Check for flags with getopt
if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \
-l check,help,version,log,debug -- "$@")"; then
if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \
check,help,version,log,debug -- "$@")"; then
eval set -- "$options"
while true; do
case "${1,,}" in
-c|--check) # Show current raid type
check=yes
;;
-h|--help) # Show usage options
usage
exit
;;
-v|--version) # Show script version
scriptversion
exit
;;
-l|--log) # Log
log=yes
;;
-d|--debug) # Show and log debug info
debug=yes
;;
-c|--check) # Show current raid type
check=yes
break
;;
--)
shift
break
Expand All @@ -97,7 +102,6 @@ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -a \
done
else
usage
exit
fi


Expand Down Expand Up @@ -231,10 +235,14 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
if [[ $copyerr != 1 ]] && [[ $permerr != 1 ]]; then
echo -e "\n$tag and changes.txt downloaded to:"\
"$scriptpath"
echo -e "${Cyan}Do you want to stop this script"\
"so you can run the new one?${Off} [y/n]"
read -r reply
if [[ ${reply,,} == "y" ]]; then exit; fi
#echo -e "${Cyan}Do you want to stop this script"\
# "so you can run the new one?${Off} [y/n]"
#read -r reply
#if [[ ${reply,,} == "y" ]]; then exit; fi

# Reload script
printf -- '-%.0s' {1..79}; echo # print 79 -
exec "$0" "${args[@]}"
fi
fi
else
Expand All @@ -257,11 +265,12 @@ synoinfo="/etc.defaults/synoinfo.conf"
#----------------------------------------------------------
# Check currently enabled RAID type

# Enable RAID F1
# Set the following SHR line to "no":
# Enable SHR
# support_syno_hybrid_raid="yes"
# supportraidgroup="no"
#
# Enable RAID Group
# support_syno_hybrid_raid="no"
#
# Then add this line to enable RAID F1:
# supportraidgroup="yes"

# Set short variables
Expand All @@ -271,13 +280,13 @@ srg=supportraidgroup
# Check current setting
checkcurrent(){
settingshr="$(get_key_value $synoinfo ${sshr})"
settingf1="$(get_key_value $synoinfo ${srg})"
if [[ $settingshr == "yes" ]] && [[ $settingf1 != "yes" ]]; then
settingraidgrp="$(get_key_value $synoinfo ${srg})"
if [[ $settingshr == "yes" ]] && [[ $settingraidgrp != "yes" ]]; then
echo -e "${Cyan}SHR${Off} ${1}enabled.\n" >&2
enabled="shr"
elif [[ $settingshr != "yes" ]] && [[ $settingf1 == "yes" ]]; then
echo -e "${Cyan}RAID F1${Off} ${1}enabled.\n" >&2
enabled="raidf1"
elif [[ $settingshr != "yes" ]] && [[ $settingraidgrp == "yes" ]]; then
echo -e "${Cyan}RAID Group${Off} ${1}enabled.\n" >&2
enabled="raidgrp"
fi
}

Expand All @@ -293,14 +302,14 @@ fi

PS3="Select the RAID type: "
if [[ $enabled == "shr" ]]; then
#options=("RAID F1" "Restore" "Quit")
options=("RAID F1" "Quit")
elif [[ $enabled == "raidf1" ]]; then
#options=("SHR" "Restore" "Quit")
options=("SHR" "Quit")
options=("RAID Group" "Restore" "Quit")
#options=("RAID Group" "Quit")
elif [[ $enabled == "raidgrp" ]]; then
options=("SHR" "Restore" "Quit")
#options=("SHR" "Quit")
else
#options=("SHR" "RAID F1" "Restore" "Quit")
options=("SHR" "RAID F1" "Quit")
#options=("SHR" "RAID Group" "Restore" "Quit")
options=("SHR" "RAID Group" "Quit")
fi
select raid in "${options[@]}"; do
case "$raid" in
Expand All @@ -313,11 +322,11 @@ select raid in "${options[@]}"; do
break
fi
;;
"RAID F1")
raidf1="yes"
echo -e "You selected ${Cyan}RAID F1${Off}"
if [[ $enabled == "raidf1" ]]; then
echo -e "${Cyan}RAID F1${Off} is already enabled."
"RAID Group")
raidgrp="yes"
echo -e "You selected ${Cyan}RAID Group${Off}"
if [[ $enabled == "raidgrp" ]]; then
echo -e "${Cyan}RAID Group${Off} is already enabled."
else
break
fi
Expand All @@ -332,7 +341,7 @@ select raid in "${options[@]}"; do
echo -e "You selected ${Cyan}Quit${Off}"
exit
;;
*)
*)
echo -e "${Red}Invalid answer!${Off} Try again."
;;
esac
Expand All @@ -345,26 +354,54 @@ done
if [[ $restore == "yes" ]]; then
if [[ -f ${synoinfo}.bak ]]; then
# Restore from backup
if cp "$synoinfo".bak "$synoinfo" ; then
echo -e "\nSuccessfully restored from backup.\n"
checkcurrent "is now "
exit
#if cp -p "$synoinfo".bak "$synoinfo" ; then
# echo -e "\nSuccessfully restored from backup.\n"
# checkcurrent "is now "
# exit
#else
# echo -e "\n${Error}ERROR ${Off} Restore from backup failed!"
# exit 1
#fi

# Get default key values from backup
defaultsrg=$(synogetkeyvalue "$synoinfo".bak "$srg")
defaultsshr=$(synogetkeyvalue "$synoinfo".bak "$sshr")

# Set key values to defaults
if [[ $defaultsrg ]]; then
#echo -e "\nset support_raid_group $defaultsrg" # debug

synosetkeyvalue "$synoinfo" "$srg" "$defaultsrg"
else
#echo -e "\nset support_raid_group no" # debug

synosetkeyvalue "$synoinfo" "$srg" "no"
fi
if [[ $defaultsshr ]]; then
#echo "set support_syno_hybrid_raid $defaultsshr" # debug

synosetkeyvalue "$synoinfo" "$sshr" "$defaultsshr"
else
echo -e "\n${Error}ERROR ${Off} Restore from backup failed!"
exit 1
#echo "set support_syno_hybrid_raid no" # debug

synosetkeyvalue "$synoinfo" "$sshr" "no"
fi

echo
checkcurrent "is "
else
echo -e "\n${Error}ERROR ${Off} Backup synoinfo.conf not found!"
exit 1
fi
exit
fi


#----------------------------------------------------------
# Backup synoinfo.conf

if [[ ! -f ${synoinfo}.bak ]]; then
if cp "$synoinfo" "$synoinfo".bak ; then
if cp -p "$synoinfo" "$synoinfo".bak ; then
echo -e "\nsynoinfo.conf backed up."
else
echo -e "\n${Error}ERROR ${Off} synoinfo.conf backup failed!"
Expand All @@ -378,9 +415,9 @@ fi
#----------------------------------------------------------
# Edit synoinfo.conf

# Enable RAID F1
if [[ $raidf1 == "yes" ]]; then
if [[ ! $settingf1 ]]; then
# Enable RAID Group
if [[ $raidgrp == "yes" ]]; then
if [[ ! $settingraidgrp ]]; then
# Add supportraidgroup="yes"
echo 'supportraidgroup="yes"' >> "$synoinfo"
else
Expand All @@ -394,13 +431,13 @@ if [[ $raidf1 == "yes" ]]; then
synosetkeyvalue "$synoinfo" "$sshr" no
fi

# Check if we enabled RAID F1
# Check if we enabled RAID Group
settingshr="$(get_key_value $synoinfo ${sshr})"
settingf1="$(get_key_value $synoinfo ${srg})"
if [[ $settingshr != "yes" ]] && [[ $settingf1 == "yes" ]]; then
echo -e "\n${Cyan}RAID F1${Off} has been enabled.\n"
settingraidgrp="$(get_key_value $synoinfo ${srg})"
if [[ $settingshr != "yes" ]] && [[ $settingraidgrp == "yes" ]]; then
echo -e "\n${Cyan}RAID Group${Off} has been enabled.\n"
else
echo -e "\n${Error}ERROR${Off} Failed to enable RAID F1!"
echo -e "\n${Error}ERROR${Off} Failed to enable RAID Group!"
fi
fi

Expand All @@ -423,8 +460,8 @@ if [[ $shr == "yes" ]]; then

# Check if we enabled SHR
settingshr="$(get_key_value $synoinfo ${sshr})"
settingf1="$(get_key_value $synoinfo ${srg})"
if [[ $settingshr == "yes" ]] && [[ $settingf1 != "yes" ]]; then
settingraidgrp="$(get_key_value $synoinfo ${srg})"
if [[ $settingshr == "yes" ]] && [[ $settingraidgrp != "yes" ]]; then
echo -e "\n${Cyan}SHR${Off} has been enabled.\n"
else
echo -e "\n${Error}ERROR${Off} Failed to enable SHR!"
Expand Down

0 comments on commit a4efbe1

Please sign in to comment.