Skip to content

Commit

Permalink
Merge pull request #11 from 007revad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
007revad authored Mar 23, 2023
2 parents 37de9e1 + 3482405 commit c178199
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 66 deletions.
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v1.1.4
- Now only creates the RAID array and storage pool. Volume creation can now be done in DSM.
- Because you now create the volume in DSM you can set the volume size.
- Changed to create pool volume and volume group like Synology does.
- Added instructions to create the volume in DSM.

v1.0.3
Changed 'latest version check' to download to /tmp and extract files to the script's location.

Expand Down
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,38 @@

### Description

Easily create an M.2 volume on Synology NAS without a lot of typing and no need for any how-to guides.
Easily create an M.2 volume on Synology NAS without a lot of typing and no need for any how-to guides.

This script will create a volume on your NVMe drive(s) for you. All you have to do is run the script and type yes and 1, 2, 3 or 4 to answer some simple questions.
This script will create the RAID and storage pool on your NVMe drive(s) for you so you can then create the volume in the DSM GUI.

All you have to do is run the script and type yes and 1, 2, 3 or 4 to answer some simple questions. Then reboot, go to Storage Manager, Online Assemable and Create Volume.

```YAML
sudo /volume1/scripts/create_m2_volume.sh
```

**Note:** Replace /volume1/scripts/ with the path to where the script is located.

It also has a dry run mode so you can see what it would have done had you run it for real.

<p align="center"><img src="/images/create_m2_volume_dryrun.png"></p>
<p align="center"><img src="/images/create-volume0.png"></p>

### What to do after running the script

1. Restart the Synology NAS.
2. Go to Storage Manager and select online assemble:
2. Go to Storage Manager and select Online Assemble:
- Storage Pool > Available Pool > Online Assemble
3. Optionally enable TRIM:
3. Create the volume:
- Select the new Storage Pool > Create > Create Volume
4. Set the allocated size to max, or 7% less for overprovisioning.
5. Optionally enter a volume description. Be creative :)
- Click Next
6. Select the file system: Btrfs or ext4.
- Click Next and you've finished creating your volume.
7. Optionally enable and schedule TRIM:
- Storage Pool > ... > Settings > SSD TRIM

<p align="center">Available Storage Pool</p>
<p align="center">Storage Pool available for online assembly</p>
<p align="center"><img src="/images/create_m2_volume_available_pool.png"></p>

<p align="center">Online Assemble step 1</p>
Expand All @@ -30,8 +45,20 @@ It also has a dry run mode so you can see what it would have done had you run it
<p align="center">Online Assemble step 2</p>
<p align="center"><img src="/images/create_m2_volume_online_assemble2.png"></p>

<p align="center">Create volume</p>
<p align="center"><img src="/images/create-volume1.png"></p>

<p align="center">Allocate volume capacity</p>
<p align="center"><img src="/images/create-volume2.png"></p>

<p align="center">Volume description</p>
<p align="center"><img src="/images/create-volume3.png"></p>

<p align="center">Select file system</p>
<p align="center"><img src="/images/create-volume4.png"></p>

<p align="center">Success!</p>
<p align="center"><img src="/images/create_m2_volume_success.png"></p>
<p align="center"><img src="/images/create-volume5.png"></p>

<p align="center">Enable TRIM</p>
<p align="center"><img src="/images/create_m2_volume_enable_trim.png"></p>
Expand Down
Binary file added images/create-volume0.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/create-volume1.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/create-volume2.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/create-volume3.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/create-volume4.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/create-volume5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 45 additions & 59 deletions syno_create_m2_volume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,32 @@
# Resources:
# https://academy.pointtosource.com/synology/synology-ds920-nvme-m2-ssd-volume/amp/
# https://www.reddit.com/r/synology/comments/pwrch3/how_to_create_a_usable_poolvolume_to_use_as/
#
# Over-Provisioning unnecessary on modern SSDs (since ~2014)
# https://easylinuxtipsproject.blogspot.com/p/ssd.html#ID16.2
#-----------------------------------------------------------------------------------


# TODO
# Better detection if DSM is uisng the drive.
# Show drive names the same as DSM does
# Support SATA M.2 drives
# Maybe add logging
# Add option to repair damaged array

# DONE
# Allow specifying the size of the volume to leave unused space for drive wear management.
#
# Instead of creating the filesystem directly on the mdraid device, you can use LVM to create a PV on it,
# and a VG, and then use the UI to create volume(s), making it more "standard" to what DSM would do
# https://systemadmintutorial.com/how-to-configure-lvm-in-linuxpvvglv/
#
# Physical Volume (PV): Consists of Raw disks or RAID arrays or other storage devices.
# Volume Group (VG): Combines the physical volumes into storage groups.
# Logical Volume (LV): VG's are divided into LV's and are mounted as partitions.
#
# Support SATA M.2 drives
# Maybe add logging
# Add option to repair damaged array


scriptver="v1.0.3"
scriptver="v1.1.4"
script=Synology_M2_volume
repo="007revad/Synology_M2_volume"

Expand Down Expand Up @@ -205,6 +212,8 @@ echo -e "Unused M.2 drives found: ${#m2list[@]}\n"
#echo -e "NVMe list: '${m2list[@]}'\n" # debug
#echo -e "NVMe qty: ${#m2list[@]}\n" # debug

if [[ ${#m2list[@]} == "0" ]]; then exit; fi


#--------------------------------------------------------------------
# Select RAID type (if multiple M.2 drives found)
Expand Down Expand Up @@ -385,38 +394,14 @@ if [[ $single != "yes" ]]; then
fi


#--------------------------------------------------------------------
# Select file system

PS3="Select the file system: "
select filesys in "btrfs" "ext4"; do
case "$filesys" in
btrfs)
#echo -e "\nYou selected btrfs" # debug
format="btrfs"
break
;;
ext4)
#echo -e "\nYou selected ext4" # debug
format="ext4"
break
;;
*)
echo -e "${Red}Invalid answer${Off}! Try again."
;;
esac
done
echo


#--------------------------------------------------------------------
# Let user confirm their choices

if [[ $m22 ]]; then
echo -e "Ready to create ${Cyan}RAID $raidtype $format${Off} volume"\
"using ${Cyan}$m21${Off} and ${Cyan}$m22${Off}"
echo -e "Ready to create ${Cyan}RAID $raidtype ${Off} volume"\
"group using ${Cyan}$m21${Off} and ${Cyan}$m22${Off}"
else
echo -e "Ready to create ${Cyan}$format${Off} volume on ${Cyan}$m21${Off}"
echo -e "Ready to create volume group on ${Cyan}$m21${Off}"
fi

if [[ $haspartitons == "yes" ]]; then
Expand Down Expand Up @@ -519,47 +504,48 @@ done


#--------------------------------------------------------------------
# Format the array
# Create Physical Volume and Volume Group with LVM

# Ensure mkfs.btrfs and mkfs.ext4 sees raid as SSD and optimises file system for SSD
# Create a physical volume (PV) on the partition
echo -e "\nCreating a physical volume (PV) on md$nextmd partition"
if [[ $dryrun == "yes" ]]; then
echo "pvcreate /dev/md$nextmd" # dryrun
else
pvcreate /dev/md$nextmd
fi

if [[ $format == "btrfs" ]]; then
if [[ $dryrun == "yes" ]]; then
echo "echo 0 > /sys/block/md${nextmd}/queue/rotational" # dryrun
echo "mkfs.btrfs -f /dev/md${nextmd}" # dryrun
else
# Ensure mkfs.btrfs sees raid as SSD and optimises file system for SSD
echo 0 > /sys/block/md${nextmd}/queue/rotational
mkfs.btrfs -f /dev/md${nextmd}
fi
elif [[ $format == "ext4" ]]; then
if [[ $dryrun == "yes" ]]; then
echo "echo 0 > /sys/block/md${nextmd}/queue/rotational" # dryrun
echo "mkfs.ext4 -f /dev/md${nextmd}" # dryrun
else
# Ensure mkfs.ext4 sees raid as SSD and optimises file system for SSD
echo 0 > /sys/block/md${nextmd}/queue/rotational # Is this valid for mkfs.ext4 ?
mkfs.ext4 -F /dev/md${nextmd}
fi
# Create a volume group (VG)
echo -e "\nCreating a volume group (VG) on md$nextmd partition"
if [[ $dryrun == "yes" ]]; then
echo "vgcreate vg$nextmd /dev/md$nextmd" # dryrun
else
echo "What file system did you select!?"; exit
vgcreate vg$nextmd /dev/md$nextmd
fi


#--------------------------------------------------------------------
# Notify of remaining steps

echo -e "\nAfter the restart go to Storage Manager and select online assemble:"
echo -e " ${Cyan}Storage Pool > Available Pool > Online Assemble${Off}"

echo -e "Then, optionally, enable TRIM:"
echo -e " ${Cyan}Storage Pool > ... > Settings > SSD TRIM${Off}"
echo -e "\n${Cyan}Remaining steps you need to do${Off}"
cat <<EOF
1. After the restart go to Storage Manager and select online assemble:
Storage Pool > Available Pool > Online Assemble
2. Create the volume:
Select the new Storage Pool > Create > Create Volume
3. Set the allocated size to max, or 7% less for overprovisioning.
4. Optionally enter a volume description. Be creative :)
Click Next
5. Select the file system: Btrfs or ext4.
Click Next and you've finished creating your volume.
6. Then, optionally, enable TRIM:
Storage Pool > ... > Settings > SSD TRIM
EOF


#--------------------------------------------------------------------
# Reboot

echo -e "\nThe Synology needs to restart."
echo -e "\n${Cyan}The Synology needs to restart.${Off}"
echo -e "Type ${Cyan}yes${Off} to reboot now."
echo -e "Type anything else to quit (if you will restart it yourself)."
read -r answer
Expand Down

0 comments on commit c178199

Please sign in to comment.