FreeNAS Startup script?

m4rv1n

Explorer
Joined
Oct 10, 2014
Messages
51
SSDs are most certainly not affected, as they're not hampered by dubious controllers.

People have had luck with good USB drives, so a spare SATA port is not an absolute necessity. That doesn't mean it's reasonable to insist on trying to use stuff that has been known not to work (like SD cards).

SSD, like every disk chip based (SDcard or usb key), is affected by limited number of writes. Sure a good controller help it, but the technology is different than a mechanical disk. I wait for a technical answer about my previous post.
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
SSD, like every disk chip based (SDcard or usb key), is affected by limited number of writes. Sure a good controller help it, but the technology is different than a mechanical disk. I wait for a technical answer about my previous post.

The problem isn't NAND. It's crummy controllers that are not designed to handle random workloads. Read or write.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
If you have free sata port, sure this is better, but if you use SD, maybe is because you don't have free port. Anyway you have to consider that SSD are affected by same problem with random write, so this is not the solution is we talk about technology.

Read up on SSD random write workloads, then read up on SD card random write workloads. There are at least 4 orders of magnitude difference.

I'm done with this conversation. I've told you all I need to tell you. SD cards are not acceptable. If you don't want to take this advice, then don't. But I'm not going to sit here and rehash what I've known for years, discussed years ago, and the answer to your problem is to not use it. If you want to understand why, read my previous posts on SD cards.
 

m4rv1n

Explorer
Joined
Oct 10, 2014
Messages
51
Read up on SSD random write workloads, then read up on SD card random write workloads. There are at least 4 orders of magnitude difference.

I'm done with this conversation. I've told you all I need to tell you. SD cards are not acceptable. If you don't want to take this advice, then don't. But I'm not going to sit here and rehash what I've known for years, discussed years ago, and the answer to your problem is to not use it. If you want to understand why, read my previous posts on SD cards.

I understand what you told about SD card, but the question was, if you have not other sata port to use ssd or mechanical disk, how you can damage the partition if it's read only. Is like you say "if you use you car over 200mph for 200 hours, you will damage you 1988's car" while talking about a 2015's car that is in a closed garage and is used 2 hours a months. Sure you are done, but it's clear that you don't really answer question, not in this case and not technically. However, also I'm done with this conversation. Thank you for your time.
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
FreeNAS 9.3 system partition is not read only :)
 

m4rv1n

Explorer
Joined
Oct 10, 2014
Messages
51

norbs

Explorer
Joined
Mar 26, 2013
Messages
91
FreeNAS 9.3 system partition is not read only :)
Whoa! Chill out with answers that make sense and actually educate people... Soon people who ask questions are going to leave knowing stuff and not feeling degraded. ;)
 

ZiggyGT

Contributor
Joined
Sep 25, 2017
Messages
125
I believe there's an option for this. Have you checked the manual?
The manual is a little thin on how to check for errors. I installed my script (for bridge creation). It must not have run because the bridge was not created. typing the commands in manually everything works. The gui asks where the name and the location of the script. If it is pre or post. I am guessing the place I put it was not available on boot. Is there a place the scripts should be placed?
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
There's a log for that. Dmesg might be a good starting point, but I frequently end up resorting to listing the contents of /var/log/ and opening files that sound relevant.

In any case, I think the scripts are run petty much as one of the last steps of the startup process (I hesitate to even call "boot process" at that stage), well after everything is mounted. So any location should work, as long as the permissions are right.
 

Adrian

Contributor
Joined
Jun 29, 2011
Messages
166
Are you using full path names for the commands the script calls?
A cron job's environment is different, and PATH may not contain all the directories you need.
 

ZiggyGT

Contributor
Joined
Sep 25, 2017
Messages
125
There's a log for that. Dmesg might be a good starting point, but I frequently end up resorting to listing the contents of /var/log/ and opening files that sound relevant.

In any case, I think the scripts are run petty much as one of the last steps of the startup process (I hesitate to even call "boot process" at that stage), well after everything is mounted. So any location should work, as long as the permissions are right.
Found the logs you suggested. No joy there. rummaged around and did not se anything that looked like what I looking for.

Is the ifconfig commands part of the OS or are they stored somewhere as executables. It was suggested byhttps://www.ixsystems.com/community/members/adrian.1268/ that the environment of the script and of the shell are different. That might explain why the commands are failing in the script but work in the shell. how do I set up the script environment to be the same as the shell? I have not used command line stuff since my Data General RDOS and AOS days.
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
Is the ifconfig commands part of the OS or are they stored somewhere as executables.
Well, both, unless you follow Linux's bizarre position that the OS is the kernel without all the things around it. ifconfig is an executable in directory [path]/sbin/[/path].

It was suggested byhttps://www.ixsystems.com/community/members/adrian.1268/ that the environment of the script and of the shell are different. That might explain why the commands are failing in the script but work in the shell. how do I set up the script environment to be the same as the shell? I have not used command line stuff since my Data General RDOS and AOS days.
Well, what part of the environment? Present working directory? cd into wherever you need to be. Some environment variable? You might want to set it, but that's going to depend on what you want to accomplish and and you're missing.
 

ZiggyGT

Contributor
Joined
Sep 25, 2017
Messages
125
Well, both, unless you follow Linux's bizarre position that the OS is the kernel without all the things around it. ifconfig is an executable in directory [path]/sbin/[/path].


Well, what part of the environment? Present working directory? cd into wherever you need to be. Some environment variable? You might want to set it, but that's going to depend on what you want to accomplish and and you're missing.
My script is located in /mnt/MicroNAS/Store/vol1
I point the post init script to run bridgescript.sh in that directory
when the system starts up I get errors that it does not understand the commands (mostly ifconfig commands)
I can go to the shell and type all the commands and the work perfectly
If I cd to the directory ifconfig is in I can execute the macro with ./mnt/MicroNAS/Store/vol1/bridgescript.sh
I get the same errors as boot up.
Please help me understand what is happening.
 

Adrian

Contributor
Joined
Jun 29, 2011
Messages
166
UNIX-like systems search for executables in a list of ":" separated directories in the environment variable PATH. If the directory containing the executable is not on the path you have to specify the full name for each executable you run, e.g. /sbin/ifconfig or include these two lines near the top of your script
Code:
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
export PATH

People developing code often finish their path in their .profile (or equivalent) with these two elements:
  • ${HOME}/bin to search the directory bin in their home directory.
  • . (a literal ".") to search the current working directory
People sometimes include the following in their .profile, which adds the above two to whatever the system supplies.
Code:
PATH=${PATH}:${HOME}/bin:.
export PATH


Others omit . and look in the current working directory by calling thing as ./thing

What looks like a good Bourne (sh) shell programming primer is http://www.grymoire.com/Unix/Sh.html

Reading, and comprehending, the sh man page (man sh) is worthwhile. Every word counts, as do those that are absent.

A shell is a somewhat hostile programming language, with very picky syntax and very little error checking. For well written examples look at the scripts in /etc/rc.d which perform the system start up.
 

ZiggyGT

Contributor
Joined
Sep 25, 2017
Messages
125
UNIX-like systems search for executables in a list of ":" separated directories in the environment variable PATH. If the directory containing the executable is not on the path you have to specify the full name for each executable you run, e.g. /sbin/ifconfig or include these two lines near the top of your script
Code:
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
export PATH

People developing code often finish their path in their .profile (or equivalent) with these two elements:
  • ${HOME}/bin to search the directory bin in their home directory.
  • . (a literal ".") to search the current working directory
People sometimes include the following in their .profile, which adds the above two to whatever the system supplies.
Code:
PATH=${PATH}:${HOME}/bin:.
export PATH


Others omit . and look in the current working directory by calling thing as ./thing

What looks like a good Bourne (sh) shell programming primer is http://www.grymoire.com/Unix/Sh.html

Reading, and comprehending, the sh man page (man sh) is worthwhile. Every word counts, as do those that are absent.

A shell is a somewhat hostile programming language, with very picky syntax and very little error checking. For well written examples look at the scripts in /etc/rc.d which perform the system start up.
Adrian,
Thanks. I am making progress with your help. Hard to understand the entire sh docs. I could not get the Path command as you described to work. Got an error "bad variable name" so I put the /sbin/ path if front of the commands. But it seems like the script is not liking the mxlen0-5 arguments. I wondered if these dev names would be in the /dev/ directory like the tty0 stuff is and also would need a path to find those. I cannot find where they are? When do the devices get created?. I used the "echo $PATH" at the shell to see it is exactly the same as you proposed. This is not in effect when the script runs, I used "echo $PATH" in the script to see "/sbin:/bin:/user/sbin:/usr/bin"

Here is the script with my debug echoes in it. I used the echo to disable the commands that were not working
echo "Here goes the Bridge Post Init Hope this works"
echo "********************************************************************************************"
echo "********************************************************************************************"
echo "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
echo "export PATH"
PAUSE="8"
echo "Getting Ready to Create Bridge and Add Members set to UP and asign IP addresses"
echo $PATH
PAUSE="4"
/sbin/ifconfig bridge create bridge0
PAUSE="4"
/sbin/ifconfig bridge0 addm mlxen0 addm mlxen1 addm mlxen2 addm mlxen3 addm mlxen4 addm mlxen5
PAUSE="4"
/sbin/ifconfig mlxen0 up
/sbin/ifconfig mlxen1 up
/sbin/ifconfig mlxen2 up
/sbin/ifconfig mlxen3 up
/sbin/ifconfig mlxen4 up
/sbin/ifconfig mlxen5 up
echo "set IP address"
/sbin/ifconfig bridge0 inet 192.168.0.9/24
PAUSE="8"
/sbin/ifconfig mlxen0 mtu 9000
/sbin/ifconfig mlxen1 mtu 9000
/sbin/ifconfig mlxen2 mtu 9000
/sbin/ifconfig mlxen3 mtu 9000
/sbin/ifconfig mlxen4 mtu 9000
/sbin/ifconfig mlxen5 mtu 9000

errors are:
bridge0: Ethernet address: 02:16:86:1a:5f:00 - so bridge is created
bad valueridge0
bridge0
No such file or directory
bad valuep
bad valuep
bad valuep
bad valuep
bad valuep
bad valuep
not foundAS/Store/vol1/bridgescript.sh:
set IP address
bad value (width invalid)

Still puzzled as to what is going on
 

Adrian

Contributor
Joined
Jun 29, 2011
Messages
166
It is best to start sh scripts with
Code:
#!/bin/sh
to force the (Bourne) shell to be used.
I am not knowledgeable about bridges and am puzzled too.
 

ZiggyGT

Contributor
Joined
Sep 25, 2017
Messages
125
I don't think the issue is with the bridge but with my unfamiliarity with the shell or something in my installation. I reduced the script to these simple commands.
echo "Here goes the Bridge Post Init Hope this works"
echo "********************************************************************************************"
echo "********************************************************************************************"
echo $PATH
#!/bin/sh
echo $SHELL
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
PAUSE="8"
echo "Getting Ready to Create Bridge and Add Members set to UP and asign IP addresses"
echo $PATH

Results:
PATH is displayed
then : bad variable name
the shell is not reported

PS: also tried
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
export PATH
 

Adrian

Contributor
Joined
Jun 29, 2011
Messages
166
#!/bin/sh must be the very first line of the script. It causes the system to run the specified program (the Bourne shell) on the script.
The variant #!/bin/sh -xv will provide an execution trace of your script.
Confusingly, SHELL is not set in the environment of a cron job.
Even more confusingly given the errors you see the root cron job default shell appears to be /bin/sh and default path seems to contain /sbin.

You are running this cron job as root?

Can you try running this as a root cron job:
Code:
#!/bin/sh -xv
ps -p $$
env
id
echo $SHELL
ifconfig

Which for me produces
Code:
#!/bin/sh -xv
ps -p $$
+ ps -p 81778
  PID TT  STAT    TIME COMMAND
81778  -  S    0:00.00 /bin/sh -xv /root/temp.sh
env
+ env
UWSGI_RELOADS=0
LANG=en_US.UTF-8
MAIL=/var/mail/$
DJANGO_SETTINGS_MODULE=freenasUI.settings
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin
PWD=/root
HOME=/
UWSGI_ORIGINAL_PROC_NAME=/usr/local/bin/uwsgi
MM_CHARSET=UTF-8
LC_ALL=en_US.UTF-8
BLOCKSIZE=K
RC_PID=25
id
+ id
uid=0(root) gid=0(wheel) groups=0(wheel)
echo $SHELL
+ echo

ifconfig
+ ifconfig
igb0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=6403bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6>
        ether d0:50:99:d0:f8:34
        hwaddr d0:50:99:d0:f8:34
        nd6 options=9<PERFORMNUD,IFDISABLED>
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
igb1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=6403bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6>
        ether d0:50:99:d0:f8:34
        hwaddr d0:50:99:d0:f8:35
        nd6 options=9<PERFORMNUD,IFDISABLED>
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
        inet 127.0.0.1 netmask 0xff000000
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
        groups: lo
lagg0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=6403bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6>
        ether d0:50:99:d0:f8:34
        inet6 fe80::d250:99ff:fed0:f834%lagg0 prefixlen 64 scopeid 0x4
        inet6 <global address censored> prefixlen 64 autoconf
        inet 192.168.2.2 netmask 0xffffff00 broadcast 192.168.2.255
        nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
        media: Ethernet autoselect
        status: active
        groups: lagg
        laggproto failover lagghash l2,l3,l4
        laggport: igb0 flags=5<MASTER,ACTIVE>
        laggport: igb1 flags=0<>
 

ZiggyGT

Contributor
Joined
Sep 25, 2017
Messages
125
#!/bin/sh must be the very first line of the script. It causes the system to run the specified program (the Bourne shell) on the script.
The variant #!/bin/sh -xv will provide an execution trace of your script.
Confusingly, SHELL is not set in the environment of a cron job.
Even more confusingly given the errors you see the root cron job default shell appears to be /bin/sh and default path seems to contain /sbin.

You are running this cron job as root?

Can you try running this as a root cron job:
Code:
#!/bin/sh -xv
ps -p $$
env
id
echo $SHELL
ifconfig

Which for me produces
Code:
#!/bin/sh -xv
ps -p $$
+ ps -p 81778
  PID TT  STAT    TIME COMMAND
81778  -  S    0:00.00 /bin/sh -xv /root/temp.sh
env
+ env
UWSGI_RELOADS=0
LANG=en_US.UTF-8
MAIL=/var/mail/$
DJANGO_SETTINGS_MODULE=freenasUI.settings
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin
PWD=/root
HOME=/
UWSGI_ORIGINAL_PROC_NAME=/usr/local/bin/uwsgi
MM_CHARSET=UTF-8
LC_ALL=en_US.UTF-8
BLOCKSIZE=K
RC_PID=25
id
+ id
uid=0(root) gid=0(wheel) groups=0(wheel)
echo $SHELL
+ echo

ifconfig
+ ifconfig
igb0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=6403bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6>
        ether d0:50:99:d0:f8:34
        hwaddr d0:50:99:d0:f8:34
        nd6 options=9<PERFORMNUD,IFDISABLED>
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
igb1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=6403bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6>
        ether d0:50:99:d0:f8:34
        hwaddr d0:50:99:d0:f8:35
        nd6 options=9<PERFORMNUD,IFDISABLED>
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
        inet 127.0.0.1 netmask 0xff000000
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
        groups: lo
lagg0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=6403bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6>
        ether d0:50:99:d0:f8:34
        inet6 fe80::d250:99ff:fed0:f834%lagg0 prefixlen 64 scopeid 0x4
        inet6 <global address censored> prefixlen 64 autoconf
        inet 192.168.2.2 netmask 0xffffff00 broadcast 192.168.2.255
        nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
        media: Ethernet autoselect
        status: active
        groups: lagg
        laggproto failover lagghash l2,l3,l4
        laggport: igb0 flags=5<MASTER,ACTIVE>
        laggport: igb1 flags=0<>
Adrian, I was using the FREENAS GUI option to run the script with post init option., so I did not try the test you suggest. The good news is that the script is working properly and my 3 x 2channel Melanox cards are behaving as a bridge. I took your advice to get the path correct and some advice from a unix friend. He realized that since I am familiar with Windows and not unix I was probably using windows tools to create the file. The issue was the way text files are stored in these two different operating systems. I tried to use vi to edit the files but I lost those skills in the DEC PDP 11 days. So I found the windows tool ConTEXT http://www.contexteditor.org/index.php it allows you to select the LF vs windows CR/LF in the text output. I imported the file, and saved it in the unix compatible format. On the next FREENAS boot everthing was a go. I can transfer between all the systems using the 10Gb links. Now I will try to compare transfer rates between the systems through the FREENAS bridge and compare to transfer rates between the 2x10Gb switch ports I have.
I really appreciate the help you and others have provided. I am excited to see the network finally working.
 

Adrian

Contributor
Joined
Jun 29, 2011
Messages
166
I am glad that you have solved the problem and can get on with the main task.
While it is my editor of choice, vi is not an easy editor for casual intermittent use.
FreeNAS does have an easy editor - ee. Much simpler with on screen hints. man ee
 
Top