Feature Request: unRAID Safe Mode option


Recommended Posts

@limetech:

Can I make a very small suggestion? On /etc/rc.d/rc.local add at top:

 

if grep -wq unraidsafemode /proc/cmdline ; then
  /usr/local/sbin/emhttp &
  exit 0
fi

# Install any extra packages
...

 

Then we can set unraidsafemode boot option (and I guess worth also add an option for that on syslinux menu?) and no extras, plugins and custom go file will be loaded, just emhttpd as stock. I guess this may be very useful for many users getting in trouble with plugins or doing tests, etc...

 

I know that you are trying to not add anything new at all... but this is really very simple to add and can't really cause any new problems (there are even similar checks for other boot options made exactly the same way on rc.S and rc.M).

Link to comment

This a great idea. In fact I was working on some ideas myself.

I unpacked the bzroot and used the following code to test some ideas out.

 

Your idea is simpler then mine.

 


#!/bin/sh
#
# /etc/rc.d/rc.local:  Local system initialization script.
#
# Put any local startup commands in here.  Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.


# Install any extra packages
if ! /bin/egrep -wq 'safe|noextra' /proc/cmdline ;then
if [ -d /boot/extra ]; then
  ( cd /boot/extra ; find -maxdepth 1 -type f -exec installpkg {} \; )
fi
fi


# Install system plugins
if ! /bin/egrep -wq 'safe|noplugins' /proc/cmdline ;then
if [ -d /boot/plugins ]; then
  for Plugin in /boot/plugins/*.plg ; do
    /usr/local/sbin/installplg $Plugin | logger
  done
fi
root@unRAID2:/mnt/disk1/unRAID/bzroot-515/etc/rc.d# cat rc.local
#!/bin/sh
#
# /etc/rc.d/rc.local:  Local system initialization script.
#
# Put any local startup commands in here.  Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.


# Install any extra packages
if ! /bin/egrep -wq 'safe|noextra' /proc/cmdline ;then
if [ -d /boot/extra ]; then
  ( cd /boot/extra ; find -maxdepth 1 -type f -exec installpkg {} \; )
fi
fi


# Install system plugins
if ! /bin/egrep -wq 'safe|noplugins' /proc/cmdline ;then
if [ -d /boot/plugins ]; then
  for Plugin in /boot/plugins/*.plg ; do
    /usr/local/sbin/installplg $Plugin | logger
  done
fi
fi


# Install user plugins
if ! /bin/egrep -wq 'safe|noplugins' /proc/cmdline ;then
if [ -d /boot/config/plugins ]; then
  for Plugin in /boot/config/plugins/*.plg ; do
    /usr/local/sbin/installplg $Plugin | logger
  done
fi
fi


# Invoke the 'go' script
if [ -f /boot/config/go ]; then
  fromdos </boot/config/go >/var/tmp/go
  chmod +x /var/tmp/go
  /var/tmp/go
fi

 

 

in my go script I had the following.

It could have easily been done via the rc.local, i.e. bypassing the go script there.

It's a work in progress for me.

 


if /bin/egrep -wq 'noautostart' /proc/cmdline ;then
   sed -i -e 's#startArray=.*#startArray="no"#g' /boot/config/disk.cfg
fi


if /bin/egrep -wq 'safe|nogo' /proc/cmdline ;then exit; fi

 

I have not fully tested out the noautostart function.

In my particular case, I wanted a no-autostart and a nomount function.

Link to comment

@limetech:

Can I make a very small suggestion? On /etc/rc.d/rc.local add at top:

 

if grep -wq unraidsafemode /proc/cmdline ; then
  /usr/local/sbin/emhttp &
  exit 0
fi

# Install any extra packages
...

 

Then we can set unraidsafemode boot option (and I guess worth also add an option for that on syslinux menu?) and no extras, plugins and custom go file will be loaded, just emhttpd as stock. I guess this may be very useful for many users getting in trouble with plugins or doing tests, etc...

 

I know that you are trying to not add anything new at all... but this is really very simple to add and can't really cause any new problems (there are even similar checks for other boot options made exactly the same way on rc.S and rc.M).

 

And sorry for the off-topic, I'm posting it on this topic as I know you are looking at it.

This has been suggested in the past, and it is a great idea.

 

Your logic is slightly incorrect, as if the safe-mode is not invoked, emhttp would not be started.

 

Should look something like this:

/usr/local/sbin/emhttp &

 

if grep -wq unraidsafemode /proc/cmdline ; then

  exit 0

fi

 

# Install any extra packages

..

 

As mentioned, it also has to have logic added to /etc/rc.local

 

Edit: I thought he was adding logic to the config/go file.  The rc.local file is FAR better, and thus completely ignores any added lines put in the config/go file.

While editing rc.local, it would be a great idea to log the name of the plugin PRIOR to invoking it, as when a plugin mis-behaves, you can look in the log and see which one is blocking the correct start-up easily.

 

Joe L.

 

Link to comment

@WeeboTech:

My idea was to make it as simple as possible, to disable all customizations at once (else we can also just rename extras and plugins folders one at a time to disable them), but surely your idea is more flexible :)

 

And sorry again for the off-topic on the other thread ;)

 

@Joe L.:

emhttpd is started on go file, then I only need to run it on rc.local if I'm aborting it (due to the exit) else emhttpd will run from the go file that is called at end of rc.local.

Link to comment

Great idea's folks, Joe how are you logging the install of the plugin?

Are you familiar with logger?

This way it gets logged in syslog.

 

logger -trc.loca[$$] -s "some message"

 

Joe, let's see your code too.

Together we can all build something nice for unRAID.

Link to comment

 

I thought his logic was correct.

 

 

root@unRAID1:~# cat /proc/cmdline

initrd=bzroot.515 BOOT_IMAGE=bzimage.515

 

root@unRAID1:~# if /bin/grep BOOT_IMAGE /proc/cmdline ; then echo THEN; else echo ELSE ; fi

initrd=bzroot.515 BOOT_IMAGE=bzimage.515

THEN

 

root@unRAID1:~# if /bin/grep SAFE /proc/cmdline ; then echo THEN; else echo ELSE ; fi

ELSE

 

 

Link to comment

I guess the incorrect logic joe refers to is he may be thinking (surely joe replied it without looking at rc.local) I did just moved emhttp line to inside the if then not running it if not in safe mode, but it was not the case and it was intentional, only run it there if we will not run the go file else it runs from the go file for sure.

Link to comment

 

only run it there if we will not run the go file else it runs from the go file for sure.

 

That is how I perceived it.

 

run emhttp from the suggested block (top of rc.local) only in safe mode.

Then exit, not running anything further.

With the suggested code block /boot/config/go would not run.

 

Otherwise.. fall through, run all the other code which installs extras / plugins / and executes the go script.

Link to comment

Exactly. Btw I did tested it, uncompressed bzroot, applied it, recompressed it and tested it with and without boot param and can confirm it works as expected.

 

Also I did tried to put it very very simple exactly trying to make it suitable if possible for next rc and final, surely it may be improved a lot but I guess if much changes are required then Tom may not want to try it for last rc/final fearing some mistake.

Link to comment

@Joe L.:

emhttpd is started on go file, then I only need to run it on rc.local if I'm aborting it (due to the exit) else emhttpd will run from the go file that is called at end of rc.local.

I did not pick up on that...  I thought you were adding the grep to the "go" file.  You are, of course, correct.  (and rc.local is a far better place to put the logic regardless)
Link to comment

Is it possible to add this on the website through a flag? That way if I upgrade or I'm having issues then I just hit the flag and it reboots into safemode. Once I am done I unclick the flag and reboot once more for it to load my plugins. Possiby a message where it diplays next to the flag letting you know its already in safe mode (to reduce number of ppl that unclick the flag but forget to reboot.

Link to comment

It's possible to put a flag on the flash.

Then have the top test block also check for the existence of the flag.

I like how you implemented the unraidsafemode in rc15a.

 

For 5.0-final, Might I ask you change the line you added for safe-mode to also impliment the test for the flag file WeeboTech mentioned.  This would be the syntax that would do it:

if grep -wq unraidsafemode /proc/cmdline || test -f /boot/unraidsafemode ; then

    /usr/local/sbin/emhttp &

  exit 0

fi

 

It will allow a user who is running headless to reboot in safe mode simply by creating the file /boot/unraidsafemode and then rebooting.

 

Joe L.

Link to comment

It's possible to put a flag on the flash.

Then have the top test block also check for the existence of the flag.

I like how you implemented the unraidsafemode in rc15a.

 

For 5.0-final, Might I ask you change the line you added for safe-mode to impliment the test for the flag file WeeboTech mentioned:

if grep -wq unraidsafemode /proc/cmdline || test -f /boot/unraidsafemode ; then

    /usr/local/sbin/emhttp &

  exit 0

fi

 

It will allow a user who is running headless to reboot in safe mode simply by creating the file /boot/unraidsafemode and then rebooting.

 

Joe L.

 

 

This is a good idea. I'm running headless but IPMI and iKVM has me spoiled so I forgot people running headless on non-server equipment would need to hook up a monitor and keyboard to choose safe mode.

Link to comment

For 5.0-final, Might I ask you change the line you added for safe-mode to also impliment the test for the flag file WeeboTech mentioned.  This would be the syntax that would do it:

if grep -wq unraidsafemode /proc/cmdline || test -f /boot/unraidsafemode ; then

    /usr/local/sbin/emhttp &

  exit 0

fi

 

It will allow a user who is running headless to reboot in safe mode simply by creating the file /boot/unraidsafemode and then rebooting.

 

Joe L.

Done.

Link to comment

Also added a notification.  Code looks like this:

 

# If "unraidsafemode" present on kernel command line, or if the
# file /boot/unraidsafemode exists, skip all add-ons
if grep -wq unraidsafemode /proc/cmdline  || test -f /boot/unraidsafemode ; then
  echo "unRAID Safe Mode (unraidsafemode) has been set"
  /usr/local/sbin/emhttp &
  exit 0
fi

Link to comment

Nice.  You're turning this into a pretty nifty option that's been needed for a good while.  I'm convinced a lot of the "problems" folks report aren't issues with UnRAID, but with the various add-ons.    This will make it much simpler to confirm that ... and should make it easier to focus on just where the problems are.

 

Link to comment

I do have a few questions:

1) I use the 'enable_ahci' script in my 'go' file to ensure that one of my SATA interfaces is recognised.  I presume (but haven't tried) that safe mode will fail to enable the interface and, therefore, some of my drives will be missing in safe mde.  Is it possible to have this functionality added to the 'standard' release?

Right this will be a problem for you if you need the functionality of that script.  First perhaps disable the script and see if your controller is recognized, it's possible the it's PCI id has been added to this kernel.  Also if controller is not in "ahci" mode via bios, perhaps see if there's a way to do this via bios - probably you have already done this though.  I did add an enhancement entry for this, but this will not make it into 5.0 final:

http://lime-technology.com/forum/index.php?topic=28111.0

 

Tom, this needs serious thought before implementation. The method you have now ENSURES without any intervention the system boots normally. If a user is trying to enter a safe mode he/she has the ability to now do so. Cudos!

 

For further development several scenario's need to be fleshed out:

 

1. how to get out of safe mode if its created by a file flag? What happens to this file flag after safe mode is booted? remains, deleted??

2. methods to enter into safe mode for headless and non-headless (boot menu and/or webgui?).

3. methods to ensure MUST load options or scripts are run, maybe we need a mustgo.sh file so users with the previously mentioned ahci problem can be worked around. Or perhaps the go file IS called when safemode is called upon but the go file itself has section to test for safemode and run 'x' only ?

 

Lots to go through and i think the community is willing, able, and hoping to help you out with this.

 

 

P.S.

 

15a running perfecto on my sys (see sig). Running ParChk now @ 113MB/sec @2%. seems normal to me.

Link to comment

Tom, might want to add this, otherwise you'll be booting to safe mode indefinitely, unless manual user intervention.

 

 

# If "unraidsafemode" present on kernel command line, or if the

# file /boot/unraidsafemode exists, skip all add-ons

if grep -wq unraidsafemode /proc/cmdline  || test -f /boot/unraidsafemode ; then

  echo "unRAID Safe Mode (unraidsafemode) has been set"

  /usr/local/sbin/emhttp &

  rm /boot/unraidsafemode

  exit 0

fi

 

Link to comment

[ -e "/boot/unraidsafemode" ] && rm /boot/unraidsafemode

 

Better add check to avoid error message if using the boot option as flag file will not exist :)

 

Anyway a permanent safemode until manually disabled could even have advantages... for eg. if someone needs to boot safemode until something is fixed and doesn't want to fix it immediately... well but both ways may have advantages and disadvantages for sure...

Link to comment

Let the flag removal be manual for now.

 

We as a community can make a plugin to put it there or remove it.

 

When Tom has the time, he can put a checkbox next to reboot to enable/disable safe mode.

 

We seem to be really close to a full release.

 

altering the rc.local script with something simple & worked, updating emhttp to do it the right way might mean more change and testing.

 

I know a /.autofsck flag will be removed on boot, but I'm not sure the unraidsafemode should be removed on boot.

While reboot from safe mode to regular mode works for windows. do we need it 'right now' for unRAID?

 

 

I'm sure once 5.0 goes out, there will be a 5.1 around the corner with new features! I see allot of momentum here.

Link to comment