Register for the iXsystems Community to get an ad-free experience and exclusive discounts in our eBay Store.

Checking for TLER, ERC, etc. support on a drive

Joined
Jul 3, 2018
Messages
3
Thanks
0
@jbernie51 : this subject presupposes a great deal of knowledge on your part, e.g., setting up datasets, setting up shell access for logging on to the FreeNAS server, mastery of basic UNIX commands, writing shell scripts, etc. It sounds like you may not be familiar with some of these items, so you may have to do some studying to get going. That said...

You will need to remove the directory you created from the command line (/mnt/tank/sysadmin) -- we always use the FreeNAS GUI to create datasets, as this is how FreeNAS is designed to be used. I created my system admin dataset using the FreeNAS GUI under 'Storage' on the main menu. This is where you create datasets to be used as shares and so forth. On my system, I named my pool 'tank' and my system admin dataset 'sysadmin', but you can use any names that strike your fancy. FreeNAS always mounts your pool in the 'mnt' directory on the boot drive, so this is where the path /mnt/tank/sysadmin came from in my earlier post. Again, your system may differ from mine, depending on your pool name and so forth.

Once your dataset is configured, you can log on the FreeNAS server with a shell session and create your script. Many folks use a Windows program called PuTTY for this purpose, but there are numerous ways of establishing a shell session with your FreeNAS server. You will want to execute the smartctl -l scterc,70,70 /dev/??? command on each of the drives for which you wish to specify a TLER/ERC value. To get a list of the drives on your system, you can run smartctl --scan. Your drive list will almost certainly differ from mine, which is why I used the ??? earlier.
I know just enough of basic commands, shell scripts and using PuTTY to get by and can follow when someone more knowledgeable lays down some instructions. This is my first foray into FreeNAS, hence me asking for instruction. ;)

I guess I was getting confused as I thought 'tank' was a folder created under the FreeNAS filesystem and not a dataset.
I was trying to avoid creating a dataset on my volume of four 8TB drives just because I like things neat and clean, and giving the volume the name 'Media' was my intention to store all Music/Photo/Video on there, and nothing else...
In my setup, I have a single SSD I've used to create a volume called 'Jails' which I've configured as the Jail Root. Would creating a second dataset here be better?

Although, now that I just finsihed typing above, I realized that this script would benefit from living in the Media volume as those are the drives I am trying to make sure are TLER enabled, and the script should be moved along with the drives, ex: moving to another or upgraded FreeNAS system..
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
1,937
Thanks
807
I know just enough of basic commands, shell scripts and using PuTTY to get by and can follow when someone more knowledgeable lays down some instructions. This is my first foray into FreeNAS, hence me asking for instruction. ;)

I guess I was getting confused as I thought 'tank' was a folder created under the FreeNAS filesystem and not a dataset.
I was trying to avoid creating a dataset on my volume of four 8TB drives just because I like things neat and clean, and giving the volume the name 'Media' was my intention to store all Music/Photo/Video on there, and nothing else...
In my setup, I have a single SSD I've used to create a volume called 'Jails' which I've configured as the Jail Root. Would creating a second dataset here be better?

Although, now that I just finsihed typing above, I realized that this script would benefit from living in the Media volume as those are the drives I am trying to make sure are TLER enabled, and the script should be moved along with the drives, ex: moving to another or upgraded FreeNAS system..
I'm the first to admit that the ZFS/FreeNAS nomenclature can be confusing... :)

On my system, I have several pools, one of which is named 'tank'. Pools may contain one or more datasets. Again, on my system I created a dataset named 'sysadmin' on my 'tank' pool. Since pools are all mounted in the '/mnt' directory, the full path to my system administration dataset is therefore /mnt/tank/sysadmin.

You can configure your system however you please, of course. It sounds like you have a volume (aka 'pool') named 'Media', and there's no reason not to store your scripts there. Presumably you've already created one (or more) datasets on this volume. You could create another dataset on it -- perhaps named 'sysadmin' -- and store your script there, or just store it in one the datasets you've already created. It's up to you.
 

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
Good stuff! Checked all my HDDs and fount that only two of them had this enabled (out of six). I'd love to see FreeNAS check for drives with this capability and give me a yellow warning light if it's not enabled when it could be.

Prune away!
3 years later and this post is still kinda relevant.
 

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
So I've always had trouble executing scripts, I have no idea how to do it.

Firstly, is this the current latest TLER script for FreeNAS?
https://github.com/Spearfoot/FreeNAS-scripts/blob/master/set_hdd_erc.sh

Second, I tried like ./set_erc_tler.sh 7 7 that didn't work.
I chmod to 777, I dunno, I'm not smart enough.

So how do I run this on my system just to mess with it.
 

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
Anyone?

I have got my NAS close to ready to start using. My whites are in there.
I'd like to confirm, firstly that TLER is off via CLI.
Then I want to enable TLER via a script.
Then I want to confirm it's on, via CLI

Really want to be comfortable before I use this sucker full time :)


EDIT:
Solved, for others, it's smartctl -l scterc /dev/???? to check
I've set mine with the command at the top of this page (google wasn't finding it cause it was hidden inside a 'read more' pane)

Now to find the 'at boot' script for it.
 
Last edited:

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
1,937
Thanks
807
Anyone?

I have got my NAS close to ready to start using. My whites are in there.
I'd like to confirm, firstly that TLER is off via CLI.
Then I want to enable TLER via a script.
Then I want to confirm it's on, via CLI

Really want to be comfortable before I use this sucker full time :)
The very first post in this thread tells how to query a drive for its SCTETC/TLER setting... :D

First you need to check your system to see how your drives are named, the command for this is smartctl --scan. Your drives will most likely be either /dev/ada0 or /dev/da0, depending on how they're attached to your system. In either case, use these device names below.

The command to query the SCTERC/TLER setting is smartctl -l scterc /dev/ada0 -- again, use the device names you discovered above.

To set the value, using the same command with 2 extra parameters -- the read and write timeout values, in tenths of a second. This command sets both to 8 seconds: smartctl -l scterc,80,80 /dev/ada0.

My script above does all of this for you. You can edit it to change the read and write values to whatever better suits your needs. There are no command-line parameters to the script; you just execute it.

Good luck!
 

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
1,937
Thanks
807

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
I'm sorry, I can't figure this out.
I chmod the file to 777, I've +x the file

I've set it to run on boot in pre init, no luck

If I try to run manually.

Code:
root@freenasnew[~]# /mnt/ARRAY/media/set_erc.sh
zsh: /mnt/ARRAY/media/set_erc.sh: bad interpreter: /bin/sh^M: no such file or directory
root@freenasnew[~]#



I didn't read initially, have now and commented out section 3, still no luck?

Code:
#!/bin/sh

# https://www.smartmontools.org/wiki/FAQ#WhatiserrorrecoverycontrolERCandwhyitisimportanttoenableitfortheSATAdisksinRAID

# ERC timeout values, in tenths of a second. The defaults below are 7 seconds for both reads and writes:

readsetting=70
writesetting=70

# We need a list of the SMART-enabled drives on the system. Choose one of these
# three methods to provide the list. Comment out the two unused sections of code.

# 1. A string constant; just key in the devices you want to report on here:
drives="ada0 ada1 ada2 ada3 ada4 ada5"

# 2. A systcl-based technique suggested on the FreeNAS forum:
#drives=$(for drive in $(sysctl -n kern.disks); do \
#if [ "$(/usr/local/sbin/smartctl -i /dev/${drive} | grep "SMART support is: Enabled" | awk '{print $3}')" ]
#then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')

# 3. A smartctl-based function:
#get_smart_drives()
#{
#  gs_drives=$(/usr/local/sbin/smartctl --scan | grep "dev" | awk '{print $1}' | sed -e 's/\/dev\///' | tr '\n' ' ')
#
#  gs_smartdrives=""
#
#  for gs_drive in $gs_drives; do
#	gs_smart_flag=$(/usr/local/sbin/smartctl -i /dev/"$gs_drive" | grep "SMART support is: Enabled" | awk '{print $4}')
#	if [ "$gs_smart_flag" = "Enabled" ]; then
#	  gs_smartdrives=$gs_smartdrives" "${gs_drive}
#	fi
#  done
#
#  eval "$1=\$gs_smartdrives"
#}
#
#
#drives=""
#get_smart_drives drives
#
# end of method 3.

set_erc()
{
  echo "Drive: /dev/$1"
  /usr/local/sbin/smartctl -q silent -l scterc,"${readsetting}","${writesetting}" /dev/"$1"
  /usr/local/sbin/smartctl -l scterc /dev/"$1" | grep "SCT\|Write\|Read"
}

for drive in $drives; do
  set_erc "$drive"
done


(Opted for plain old method 1, looks simple)

EDIT: I've tried post-init also, still not running.
 
Last edited:

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
I've tried all 3 methods, post and pre AND I've tried this.

https://i.imgur.com/hJ5uQLH.jpg

Look at all 6 of those commands (!!!) and none of them work. And yes, I know the command /actually totally really works/ in the CLI when I just SSH in normally? :(
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
1,937
Thanks
807
I'm sorry, I can't figure this out.
I chmod the file to 777, I've +x the file

I've set it to run on boot in pre init, no luck

If I try to run manually.

Code:
root@freenasnew[~]# /mnt/ARRAY/media/set_erc.sh
zsh: /mnt/ARRAY/media/set_erc.sh: bad interpreter: /bin/sh^M: no such file or directory
root@freenasnew[~]#



I didn't read initially, have now and commented out section 3, still no luck?

Code:
#!/bin/sh

# https://www.smartmontools.org/wiki/FAQ#WhatiserrorrecoverycontrolERCandwhyitisimportanttoenableitfortheSATAdisksinRAID

# ERC timeout values, in tenths of a second. The defaults below are 7 seconds for both reads and writes:

readsetting=70
writesetting=70

# We need a list of the SMART-enabled drives on the system. Choose one of these
# three methods to provide the list. Comment out the two unused sections of code.

# 1. A string constant; just key in the devices you want to report on here:
drives="ada0 ada1 ada2 ada3 ada4 ada5"

# 2. A systcl-based technique suggested on the FreeNAS forum:
#drives=$(for drive in $(sysctl -n kern.disks); do \
#if [ "$(/usr/local/sbin/smartctl -i /dev/${drive} | grep "SMART support is: Enabled" | awk '{print $3}')" ]
#then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')

# 3. A smartctl-based function:
#get_smart_drives()
#{
#  gs_drives=$(/usr/local/sbin/smartctl --scan | grep "dev" | awk '{print $1}' | sed -e 's/\/dev\///' | tr '\n' ' ')
#
#  gs_smartdrives=""
#
#  for gs_drive in $gs_drives; do
#	gs_smart_flag=$(/usr/local/sbin/smartctl -i /dev/"$gs_drive" | grep "SMART support is: Enabled" | awk '{print $4}')
#	if [ "$gs_smart_flag" = "Enabled" ]; then
#	  gs_smartdrives=$gs_smartdrives" "${gs_drive}
#	fi
#  done
#
#  eval "$1=\$gs_smartdrives"
#}
#
#
#drives=""
#get_smart_drives drives
#
# end of method 3.

set_erc()
{
  echo "Drive: /dev/$1"
  /usr/local/sbin/smartctl -q silent -l scterc,"${readsetting}","${writesetting}" /dev/"$1"
  /usr/local/sbin/smartctl -l scterc /dev/"$1" | grep "SCT\|Write\|Read"
}

for drive in $drives; do
  set_erc "$drive"
done


(Opted for plain old method 1, looks simple)

EDIT: I've tried post-init also, still not running.
The ^M character shows that you've been using an editor that converts UNIX newlines into DOS-style carriage-return+linefeed pairs -- which breaks the script. Windows editors are notorious for doing this...

Pull the zip file from the Github repository below by clicking on "Download ZIP" using the "Clone or download" dropdown.

https://github.com/Spearfoot/FreeNAS-scripts

Copy the zip file to your shell script directory on your FreeNAS system. Open a shell on your FreeNAS system (using PuTTY or SSH or whatever your prefer), unzip the zipfile ( unzip -j FreeNAS-scripts-master.zip) and then use vi or nano to edit the set_hdd_erc.sh script. These text editors won't dork the file's newlines.

Good luck!
 

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
Sigh, this is truly painful :/

Yep your script is now working from the CLI, thank you, the formatting was screwed.

However it will NOT work as a pre or post init for me? Are you using RC2? maybe it has issues with pre/post init commands?


Code:
root@freenasnew[~]# /mnt/ARRAY/media/33/FreeNAS-scripts-master/set_hdd_erc.sh
Drive: /dev/ada0
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada1
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada2
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada3
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada4
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada5
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada6
SCT Commands not supported
Drive: /dev/ada7
SCT Commands not supported
root@freenasnew[~]#




I've tried putting it in for init and post init
No luck.
 

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
I have run the script in "script" mode and "command" mode.
I have run it in pre-init and post-init.

I can confirm the file is not only executable, but it works from an SSH prompt, once she's booted.

All that being said.

Code:
root@freenasnew[~]# smartctl -l scterc /dev/ada3
smartctl 6.6 2017-11-05 r4594 [FreeBSD 11.2-STABLE amd64] (local build)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

SCT Error Recovery Control:
		   Read: Disabled
		  Write: Disabled

root@freenasnew[~]#



I've tried all I can at this point, I will need help going forward, because I'm stuck.

(Heck, I even fired up my RC2 VM and put in a command just to /make a directory/ and can confirm that it does seem commands run in the init as intended)

Sorry and thanks for the help, bafflingly complex.

Edit: one last thing, I saw a very old post about another script that does the same thing. Cyber jock was suggesting keeping the .sh file in /data, presumably on the USB key itself.
Unfortunately, the user interface for script running, does not allow you to navigate to the root of the USB key to do this.

I have no idea why this (now) perfectly working script, won't execute on boot.
 
Last edited:

Arwen

FreeNAS Expert
Joined
May 17, 2014
Messages
1,111
Thanks
541
...
I have no idea why this (now) perfectly working script, won't execute on boot.
It may be as simple as the ARRAY pool / volume not being mounted at the time the boot execution is attempted.

I don't know the details, sorry.
 

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
It may be as simple as the ARRAY pool / volume not being mounted at the time the boot execution is attempted.

I don't know the details, sorry.
I agree with you but the interface won't allow me to store the script elsewhere and still run it at boot.

Also you'd think post init means initialised pool anyhow.
 

Kevin Horton

FreeNAS Guru
Joined
Dec 2, 2015
Messages
619
Thanks
220
I agree with you but the interface won't allow me to store the script elsewhere and still run it at boot.

Also you'd think post init means initialised pool anyhow.
A postinit script should work.

Have the script write a date time stamp to a log file before attempting to set TLER, then use
/mnt/ARRAY/media/33/FreeNAS-scripts-master/set_hdd_erc.sh |
tee -a <log file path>
to send the output of smartctl to a log file too. This will let you confirm that the script actually runs, and if it runs, see the output of the smartctl command.
 

Kevin Horton

FreeNAS Guru
Joined
Dec 2, 2015
Messages
619
Thanks
220
It may be as simple as the ARRAY pool / volume not being mounted at the time the boot execution is attempted.
Hmm. That may be it. If so, move the script to a location on the system drive, e.g. in /root/bin. Be sure to put the full path to the script in the postinit task command item.
 

diskdiddler

FreeNAS Guru
Joined
Jul 9, 2014
Messages
2,121
Thanks
125
Hmm. That may be it. If so, move the script to a location on the system drive, e.g. in /root/bin. Be sure to put the full path to the script in the postinit task command item.
That is (arguably) not possible with the UI, it won't let you point to a script file located in the FreeNAS root, only in a mount root.....

BTW I just did "command" mode (not script mode) and it didn't work.
(I did test the command before hand, it did work, wrote the file)

Surely others have had this.
 

Kevin Horton

FreeNAS Guru
Joined
Dec 2, 2015
Messages
619
Thanks
220
That is (arguably) not possible with the UI, it won't let you point to a script file located in the FreeNAS root, only in a mount root.....

BTW I just did "command" mode (not script mode) and it didn't work.
(I did test the command before hand, it did work, wrote the file)

Surely others have had this.
I'm not sure why it works for me, but my postinit task entry points to "/root/bin/my_script_name.pl", and it works, everytime. This was in FN11.1-U6, and now in FN-11.2-RC2 on my test server.
 

Spearfoot

He of the long foot
Moderator
Joined
May 13, 2015
Messages
1,937
Thanks
807
Sigh, this is truly painful :/

Yep your script is now working from the CLI, thank you, the formatting was screwed.

However it will NOT work as a pre or post init for me? Are you using RC2? maybe it has issues with pre/post init commands?


Code:
root@freenasnew[~]# /mnt/ARRAY/media/33/FreeNAS-scripts-master/set_hdd_erc.sh
Drive: /dev/ada0
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada1
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada2
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada3
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada4
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada5
SCT Error Recovery Control:
		   Read:	 70 (7.0 seconds)
		  Write:	 70 (7.0 seconds)
Drive: /dev/ada6
SCT Commands not supported
Drive: /dev/ada7
SCT Commands not supported
root@freenasnew[~]#




I've tried putting it in for init and post init
No luck.
I run it from my startup script, specified in the Tasks -> Init/Shutdown Scripts menu, with these settings:
Type=Script
Script={full path to your script} - mine is /mnt/tank/systems/scripts/startup-script.sh. Use the Browse button to specify yours. If you use a startup script like me, you need to specify full paths to child scripts it calls.
When=Post Init - This causes FreeNAS to run the script after your pools are mounted.

FWIW, I have the permissions set to 770 (owner and group = read/write/execute) on all of my scripts. Here's my startup script:
Code:
#!/bin/sh
/mnt/tank/systems/scripts/send-status-email.sh "booted"
/mnt/tank/systems/scripts/setup-swap.sh
/mnt/tank/systems/scripts/set-hdd-erc.sh
/mnt/tank/systems/scripts/esxi-rescan-datastores.sh
/mnt/tank/systems/scripts/esxi-start-datastore-vms.sh

Hope this helps. Good luck!
 
Top