DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#76 2009-02-13 20:07:29

silversurfer
Member
Registered: 2008-07-20
Posts: 95

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

I always shut the box down with "touch /tmp/shutdown". I believe that this is the same thing that the button on the front panel does.

I also get ext2 warnings but these are normal.

Code:

EXT2-fs warning: maximal mount count reached, running e2fsck is recommended

I would need to do a manual check to get rid of them.

Offline

 

#77 2009-03-02 11:03:33

craig
Member
Registered: 2009-02-25
Posts: 18

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

Is there some general pseudo-code for what cleanboot does? As I start adding different programs, funplugs, optware, and so forth, how can I be sure that cleanboot will properly close everything?

Offline

 

#78 2009-03-29 13:11:46

sobriquet
New member
Registered: 2009-03-29
Posts: 1

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

fonz wrote:

There's another thing that would be great on shutdown/reboot (haven't seen that in your scripts):

Code:

chmod 0777 /mnt/HD_a2
chmod 0777 /mnt/HD_b2  (if present)

This has bitten me several times. See also
http://dns323.kood.org/forum/t407-Runni … THIS..html

Note tehres a small bug in cleanboot.sh - you check for existence of /mnt/HD_b2, and if it exists you chmod 0777 /mnt/HD_a2, not _b2.

Cheers
Sobriquet

Offline

 

#79 2009-04-30 19:21:07

LuckyBlack
Member
Registered: 2009-04-30
Posts: 51

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

Hi , I have a DNS-323 with firmware 1.07, fun_plug 0.5 and a 1 HD 500 GB, I read when you shutdown the system from front button or from the WebUI , the disk isn't unmounted in the right way if you have funplug installed... so i installed cleanboot 2.05 for ffp 0.5 to prevent problem.... but i have an issue.

executing the command shutdown via telnet the system isn't shutdown but i does a reboot... why this happens ?? how can i solve ??

thanks

Offline

 

#80 2009-05-01 01:24:41

talkingRock
Member
Registered: 2009-03-26
Posts: 100

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

I could not get cleanboot working on my machine either.   In fact, I got locked out of the machine and it took a while to figure out how to break back in.   

In the end, I ended up writing some scripts of my own to provide similar functionality.

Offline

 

#81 2009-05-01 10:40:58

LuckyBlack
Member
Registered: 2009-04-30
Posts: 51

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

talkingRock wrote:

I could not get cleanboot working on my machine either.   In fact, I got locked out of the machine and it took a while to figure out how to break back in.   

In the end, I ended up writing some scripts of my own to provide similar functionality.

can you post your script thanks

Offline

 

#82 2009-05-01 12:42:29

knireis
Member
Registered: 2007-12-10
Posts: 231

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

LuckyBlack wrote:

talkingRock wrote:

I could not get cleanboot working on my machine either.   In fact, I got locked out of the machine and it took a while to figure out how to break back in.   

In the end, I ended up writing some scripts of my own to provide similar functionality.

can you post your script thanks

Yeah, would be nice to have a look at them

Offline

 

#83 2009-05-02 01:48:03

talkingRock
Member
Registered: 2009-03-26
Posts: 100

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

Sure, I'm happy to share and have your suggestions.
At the moment, the scripts are embarrassingly hackerish, but they do work for my purposes.
The basic idea is to have a fake-up of run levels.

I'll try to clean up/pull together, ... over the next couple of days and post them to this thread, but I can describe the basic elements so you can decide if it's really all that interesting for your purposes.

There are four pieces to this solution:

i) the utelnetd telnet daemon is tiny enough to live on the ram disk and not hurt anyone.
ii) fun_plug copies utelnetd onto the the ram disk and starts it.   
iii) There is a user, toor, which has root privledges,
     uses /bin/sh as its shell and has only the ramdisk in its path.
iv) Finally, there are scripts, rc.lowest, rc.reboot and rc.shutdown that are also copied to the ramdisk
    at startup and try to fake-up the idea of run-levels.   lowest should be like single, ...
    rc.lowest brings the machine into an approximation of single user mode with all of the disks   
    unmounted if possible.   At that point, you can log in as toor using telnet and fsck or whatever
    other low level tasks to your hearts delight.   You can then remount the ffp stuff read-only and
    run smarttools, ...
    The reboot and shutdown scripts try as hard as they can to kill everything, unmount, ..., but
    if they fail, they go into the pseudo single user mode to let you manually unmount.

Right now, going into single user mode is pretty reliable, but complete shutdown and reboot without manually entering the single user mode is a little flakey, but works most of the time.

Offline

 

#84 2009-05-02 09:50:08

LuckyBlack
Member
Registered: 2009-04-30
Posts: 51

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

talkingRock the idea is good...

Offline

 

#85 2009-05-05 06:30:25

talkingRock
Member
Registered: 2009-03-26
Posts: 100

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

Here are the scripts as requested:

This stuff is at the "it works on my system, but it's otherwise untested." state.   

First, you will need the utelnetd binary from the how-to telnet page.
This stuff does not work without it.

Second, you will need a user with root privleges which uses the /bin/sh
shell.   (recall you need the "secret code" 5784468 to get a prompt).
Mine is called "toor"
--------------------------------------------------------------------------
adduser toor
usermod -u 0 -g 0 -o -s /bin/sh -d /root toor
--------------------------------------------------------------------------

Third, you need to have ffp installed and accessible through /ffp

You will need a symlink /custom which points to a directory on disk with bin and log subdirectories.
Put chlevel into /custom/bin
You will need a symlink /local pointing to a directory on disk with a bin subdirectory.
Put utelnetd in /local/bin

Note that all of the directories should be changable by variables in the
fun_plug or chlevel scripts.

Here is a fun_plug script derived from ffp version 0.5 with minimum changes necessary to get this to work.

----------------------------------------------------------------------------------------------
#!/bin/sh
##########################################################################
##########################################################################

##########################################################################
# FFP_DRIVE  is where the ffp main directory lives
# HOME_DRIVE is where the home directories go
#########################################################################$
FFP_DRIVE=/mnt/HD_a4
HOME_DRIVE=/mnt/HD_a4
utelnetd=$HOME_DRIVE/local/bin/utelnetd
# switch to safe working directory on ramdisk
cd /

ln -s $FFP_DRIVE/custom /custom
ln -s $FFP_DRIVE/local  /local
/bin/cp $utelnetd /sbin/utelnetd;
/bin/mknod /dev/ptyp0 c 2 0
/bin/chmod 0666 /dev/ptyp0
/bin/mknod /dev/ttyp0 c 3 0
/bin/chmod 0666 /dev/ttyp0
/sbin/utelnetd -d -l /bin/login > /tmp/utelnetd.log 2>&1
/bin/cp /custom/bin/chlevel /sbin/chlevel

# write a log, in case sth goes wrong
# FFP_LOG=$HOME_DRIVE/ffp.log
FFP_LOG=/dev/null
exec >>$FFP_LOG 2>&1

# real path to ffp
FFP_PATH=$FFP_DRIVE/ffp

# where to search for the install tarball
FFP_TARBALL=$FFP_DRIVE/fun_plug.tgz

# setup script (used for ffp on USB disk)
FFP_SETUP_SCRIPT=$FFP_DRIVE/.bootstrap/setup.sh

# rc file path
FFP_RC=/ffp/etc/rc


echo "**** fun_plug script for DNS-323 (2008-08-11 tp@fonz.de) ****"
date


# check for setup script. an example use for this is to load USB
# kernel modules and mount a USB storage device. The script is
# sourced, that means you can change variables, e.g. FFP_PATH to point
# to the USB device.
if [ -x $FFP_SETUP_SCRIPT ]; then
    echo "* Running $FFP_SETUP_SCRIPT ..."
    . $FFP_SETUP_SCRIPT
fi

# create /ffp link
echo "ln -snf $FFP_PATH /ffp"
ln -snf $FFP_PATH /ffp

# install tarball
if [ -r $FFP_TARBALL ]; then
    echo "* Installing $FFP_TARBALL ..."
    mkdir -p $FFP_PATH && tar xzf $FFP_TARBALL -C $FFP_PATH && /ffp/bin/tar xzf $FFP_TARBALL -C $FFP_PATH
    if [ $? -eq 0 ]; then
        echo "* OK"
    fi
    rm $FFP_TARBALL
fi

# suid busybox
if [ -x /ffp/bin/busybox ]; then
    chown root.root /ffp/bin/busybox
    chmod 0755 /ffp/bin/busybox
    chmod u+s /ffp/bin/busybox
fi

# run fun_plug.init, if present
if [ -x /ffp/etc/fun_plug.init ]; then
    echo "* Running /ffp/etc/fun_plug.init ..."
    /ffp/etc/fun_plug.init
fi

# run fun_plug.local, if present
if [ -x /ffp/etc/fun_plug.local ]; then
    echo "* Running /ffp/etc/fun_plug.local ..."
    /ffp/etc/fun_plug.local
fi

# run commands
if [ -x $FFP_RC ]; then
    echo "* Running $FFP_RC ..."
    $FFP_RC
    echo "*  OK"
else
    echo "$FFP_RC: Not found or not executable"
fi

---------------------------------------------------------------------------------------

Finally, here is the chlevel script which will reboot, shutdown or go to single user, all with clean umounts.

-----------------------------------------------------------------------------------------
#!/bin/sh
logfilebase=chlevel.$$
logfile=/tmp/$logfilebase
#
# put the whole thing in a log
#
# make the log really detailed by setting the shell tracing on
#
# we will be killing a bunch of processes
# try to make sure that we don't die if we make a mistake.
trap ""  1  2  3  4  5  6  7  8    10 11 12 13 14 15 16

##########################################
# beginning of configuration section
##########################################
# These partitions do not have programs or data we
# need for this script or to log in.
# once programs are killed, we should be able to unmount
regularPartitions="/dev/sdb2 /dev/sdb4 /dev/sda2"
#
# We expect /custom and /ffp to point into this partitions mount point
# Therefore, we need to be more careful unmounting
specialPartition="/dev/sda4"
specialMountPoint="/mnt/HD_a4"
#
# These are expected to shutdown nicely with a stop command
stoppable="/usr/bin/smb /ffp/etc/rc"
#
# These are expected to be running and must be explicitly killed
explicitKills="atd crond webs op_server pure-ftpd"

#
# These are expected to be running and we do not want to kill them.
protected="utelnetd fancontrol chkbutton"
#
#
savedLogsDir=/custom/log

utelnetd_exec=/local/bin/utelnetd
#
# Here are some programs we use
# It should be possible to do this only using box builtin stuff
# but it would be a bit more effort.   For now, we need some ffp stuff too.
goodps=/ffp/bin/ps
killall=/ffp/bin/killall
lsof=/ffp/bin/lsof
nativeps=/bin/ps
grep=/bin/grep
cp=/bin/cp
rm=/bin/rm
chmod=/bin/chmod
date=/bin/date
mknod=/bin/mknod
pidof=/bin/pidof
sleep=/bin/sleep
mount=/bin/mount
umount=/bin/umount

##########################################
# end  of configuration section
##########################################

do_kills_v2 ()
{
   #
   # get some special pids
   utelnetd_pid=`$pidof utelnetd`
   my_ppid=$PPID
   my_pid=$$
   protectedPids="$my_pid $utelnetd_pid"
   protectedPids="$protectedPids $protectedByArg"
   for q in $protected; do
      protectedPids="$protectedPids `$pidof $q`"
   done
   #
   # This little bit of hackery makes sure that the basic system processes
   # are protected except for the ones we kill explicitly.
   lowest_pid=1000

   deathfile=/tmp/deathlist.$$
   if [ -e $deathfile ]; then $rm $deathfile; fi
   #
   # if it has a nice way to kill it, like ffp or opt run programs, do that
   for s in $stoppable; do
     if [ -x $s ]; then
       $s stop
     fi
   done
   $sleep 5
   #
   # kill some known stuff we don't want in our single user mode
   for p in $explicitKills; do
     $killall -q -9 $p
   done
   #
   # log how we are doing so far
   $nativeps
   $goodps -o pid,ppid | ( read crap; while read the_pid the_ppid; do
   #
   # kill it using signal 15 unless
   #    it's one of the builtins below the low water mark
   #    it is me.
   #    it is my child process.
   #    it is one of the protected processes
   # there is a slight problem here that should eventually be fixed.
   # If the parent shell is being run off of the ramdisk with a cwd on the
   # ramdisk, there is no reason to kill it and force a relogin.
   # I'm just not sure how to easily detect that case.
     if test \( $the_pid -gt $lowest_pid \) \
         -a \( $the_pid  -ne $$ \) \
         -a \( $the_ppid -ne $my_pid \) ; then
       killit=1;
       for q in $protectedPids; do
         if test $the_pid -eq $q ; then
            killit=0;
         fi
       done
       if [ $killit -eq 1 ]; then
         kill $the_pid
         echo $the_pid >> $deathfile
       fi
     fi
   done )
   $nativeps
   #
   # go through the stuff we killed with 15 and make sure it is dead with 9
   # doublecheck that we're not killing anything protected.
   if [ -e $deathfile ]; then
     for the_pid in `cat $deathfile`; do
       if [ \( -n "`$goodps -o pid | grep $the_pid`" \) ]; then
         killit=1;
         for q in $protectedPids; do
           if test "$the_pid" -eq "$q" ; then
              killit=0;
           fi
         done
         if [ $killit -eq 1 ]; then
           kill -9 $the_pid
         fi
       fi
     done
     $rm $deathfile
   fi
   $nativeps
}


start_utelnetd ()
{
# utelnetd appears to be the smallest and least intrusive telnetd
# available for the 323.   Other options would be overwriting busybox
# or compiling a full telnet client.  This seems like the best way to go.
  if [ \! -x /sbin/utelnetd ]; then
    $cp $utelnetd_exec /sbin/utelnetd;
  fi
  if [ \! -e /dev/ptyp0 ]; then
    $mknod /dev/ptyp0 c 2 0
    $chmod 0666 /dev/ptyp0
  fi
  if [ \! -e /dev/ttyp0 ]; then
    $mknod /dev/ttyp0 c 3 0
    $chmod 0666 /dev/ttyp0
  fi
  /sbin/utelnetd -d -l /bin/login > /tmp/utelnetd.log 2>&1
}

ensure_utelnetd ()
{
  b=`$pidof utelnetd`
  if [ -z "$b" ]; then
    start_utelnetd
  fi
}

umount_regular ()
{
  #
  # that old black magic
  /bin/sync;/bin/sync;/bin/sync;
  umount_clean=1
  for p in $regularPartitions; do
  #
  # if it's not in mtab, it's not currently mounted.
    if [ -n "`$grep $p /etc/mtab`" ]; then
      $umount $p
  # if you can't get it unmounted, at least sync and go read only
      if [ $? -ne 0 ]; then
          echo "open files follow:"
          $lsof  | $grep /mnt
          umount_clean=0;
          /bin/sync;/bin/sync;/bin/sync;
          $mount -o remount,ro $p
      fi
    fi
  done
  return $umount_clean
}

ensure_bg ()
{
  procname=$1
  shift
  echo command is "$*"
  b=`$pidof $procname`
  if [ "$b" = "" ]; then
    $* &
  fi
}

ensure ()
{
  procname=$1
  shift
  echo command is "$*"
  b=`$pidof $procname`
  if [ "$b" = "" ]; then
    $*
  fi
}

toLowest () {
  cd /
  do_kills_v2
  sleep 5
  umount_regular
  toLowest_clean=$?
  datestamp=`$date +%Y%m%d%H%M`
  # copy the this script's log  and system logs to the last filesystem
  $cp $logfile $savedLogsDir/$logfilebase.$datestamp
  $cp -a /var/log $savedLogsDir/var.log.$datestamp

  if [ -n "`$grep $specialPartition /etc/mtab`" ]; then
    /bin/sync;/bin/sync;/bin/sync;
    $umount $specialPartition
  #
  # if we can't get it unmounted, at least give some help on why and go to read-only
    if [ $? -ne 0 ]; then
     toLowest_clean=0
     $lsof | $grep /mnt
     # since we failed to unmount, we should be able to copy the log again
     # this time with the open file information
     $cp $logfile /custom/log/$logfilebase.$datestamp
     $cp -af /var/log/ /custom/log/var.log.$datestamp
     $mount -o remount,ro $specialPartition $specialMountPoint
    fi
  fi
  return $toLowest_clean
}

protectedByArg=
if [ -n "$2" ]; then
  protectedByArg="$2"
fi

case $1 in
reboot)
  exec > $logfile 2>&1
  set -x
  toLowest
  clean=$?
  if [ $clean -eq 1 ]; then
    /sbin/reboot
  fi
  ;;
shutdown)
  exec > $logfile 2>&1
  set -x
  toLowest
  clean=$?
  if [ $clean -eq 1 ]; then
    /bin/touch /tmp/shutdown
    sleep 60
  fi

  ;;
single)
  exec > $logfile 2>&1
  set -x
  toLowest
  ;;
*)
  echo "chlevel attempts to fake up the single reboot and shutdown run levels"
  echo "usage: $0 [ single | reboot | shutdown ]"
  exit
  ;;
esac
ensure_utelnetd
ensure_bg fancontrol /usr/sbin/fancontrol '>' /dev/null '2&1'
ensure_bg chkbutton /usr/sbin/chkbutton
-------------------------------------------------------------------------------------------

Offline

 

#86 2009-05-10 04:52:27

talkingRock
Member
Registered: 2009-03-26
Posts: 100

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

I completely redid my script so that it implements something that looks alot like system V run levels with
names instead of numbers.    I can bring the machine down to a mode where only fancontrol and utelnetd are running with the kernel processes and all disks are unmounted.   From there, I can do whatever I want and get back to a fully running system.   Here is the new script.   It's much simpler, more robust and more easily customized than the old one.     At some point, I'd like to add a pseudo "run level" that implements Fonz's tmpfs for system maintenance idea.

Code:

#!/bin/sh
##################################################
# This script imitates sysV style of moving through
# run levels, kind of like debian, but instead
# of directories for run levels and scripts
# for actions, we will have functions for
# run levels and functions for actions
##################################################
# I'm pretty sure we only have to trap 1 which is HUP and 15
trap ""  1  2  3  4  5  6  7  8    10 11 12 13 14 15 16

#
# lsof=/ffp/bin/lsof
ps=/bin/ps
grep=/bin/grep
cp=/bin/cp
chmod=/bin/chmod
mkdin=/bin/mkdir
mknod=/bin/mknod
pidof=/bin/pidof
sleep=/bin/sleep
mount=/bin/mount
umount=/bin/umount

starter () {
  _name=$1;
  _exec=$2;
  shift; shift;
  _args=$*
  if [ -z "`$pidof $_name`" ]; then
    if [ -x $_exec ]; then
        $_exec $_args;
    fi
  fi
}

starter_bg () {
  _name=$1;
  _exec=$2;
  shift; shift;
  _args=$*
  if [ -z "`$pidof $_name`" ]; then
    if [ -x $_exec ]; then
        $_exec $_args &
    fi
  fi
}

stopper () {
  _name=$1
  _pid=`$pidof $1`
  if [ -n "$_pid" ]; then
    kill -15 $_pid
    sleep 5
    _pid=`$pidof $1`
    if [ -n "$_pid" ]; then
      kill -9 $_pid
    fi
  fi
}

kill_except ()
{
   protectedPids=$$
   if [ $1 = "parent" ]; then
     protectedPids="$PPID $protectedPids"
     shift
   fi
   protectedNames=$*
   utelnetd_pid=`$pidof utelnetd`

   protectedPids="$utelnetd_pid $protectedPids"
   for q in $protectedNames; do
      protectedPids="$protectedPids `$pidof $q`"
   done
   lowest_pid=1000
   #
   killlist=`$ps | ( read crap; while read the_pid rest; do
     if test \( $the_pid -gt $lowest_pid \) \
          -a \( $the_pid  -ne $$ \) ; then
       killit=1;
       for q in $protectedPids; do
         if test $the_pid -eq $q ; then
            killit=0;
         fi
       done
       if [ $killit -eq 1 ]; then
         kill $the_pid
         klist="$klist $the_pid"
       fi
     fi
   done; echo "$klist" )`
   #
   # go through the stuff we killed with 15 and make sure it is dead with 9
   # doublecheck that we're not killing anything protected.
   sleep 5
   for the_pid in $killlist; do
     whatever=`$ps | grep $the_pid | grep -v "grep $the_pid"`
     if [ \( -n "$whatever" \) ]; then
        if [ $the_pid -ne $$ ]; then
          kill -9 $the_pid
        fi
     fi
   done
}

utelnetd_exec_on_disk=/local/bin/utelnetd
utelnetd ()
{
  case $1 in
  start)
    if [ \! -x /sbin/utelnetd ]; then
      if [ -e $utelnetd_exec_on_disk ]; then
        $cp $utelnetd_exec_on_disk /sbin/utelnetd;
        $chmod u+x /sbin/utelnetd;
      fi
    fi
    if [ \! -e /dev/ptyp0 ]; then
      $mknod /dev/ptyp0 c 2 0
      $chmod 0666 /dev/ptyp0
    fi
    if [ \! -e /dev/ttyp0 ]; then
      $mknod /dev/ttyp0 c 3 0
      $chmod 0666 /dev/ttyp0
    fi
    if [ -z `$pidof utelnetd` ]; then
      if [ -x /sbin/utelnetd ]; then
        /sbin/utelnetd -d -l /bin/login > /tmp/utelnetd.log 2>&1
      fi
    fi
    ;;
  stop)
    stopper utelnetd
    ;;
  *)
    ;;
  esac
}

fancontrol () {
  case $1 in
  start)
    starter_bg fancontrol /usr/sbin/fancontrol
    ;;
  stop)
    stopper fancontrol
    fanspeed h
    ;;
  *)
    ;;
  esac
}

atd () {
  case $1 in
  start)
    starter atd /usr/bin/atd
    ;;
  stop)
    stopper atd
    ;;
  *)
    ;;
  esac
}

lpd () {
  case $1 in
  start)
    starter lpd /usr/bin/lpd
    ;;
  stop)
    stopper lpd
    ;;
  *)
    ;;
  esac
}

crond () {
  case $1 in
  start)
    starter crond /sbin/crond
    ;;
  stop)
    stopper crond
    ;;
  *)
    ;;
  esac
}

ffp () {
  case $1 in
  start)
    /ffp/etc/rc start
    ;;
  stop)
    /ffp/etc/rc stop
    ;;
  *)
    ;;
  esac
}

smb () {
  case $1 in
  start)
    /usr/bin/smb start
    ;;
  stop)
    /usr/bin/smb stop
    ;;
  *)
    ;;
  esac
}

op_server () {
  case $1 in
  start)
    starter_bg op_server ex_opserver
    ;;
  stop)
    stopper op_server
    ;;
  *)
    ;;
  esac
}

webs () {
  case $1 in
  start)
    starter_bg webs /web/webs
    ;;
  stop)
    stopper webs
    ;;
  *)
    ;;
  esac
}

chkbutton () {
  case $1 in
  start)
    starter chkbutton /usr/sbin/chkbutton
    ;;
  stop)
    stopper chkbutton
    ;;
  *)
    ;;
  esac
}

regularPartitions="/dev/sdb2 /dev/sdb4 /dev/sda2"
data_mounts () {
case $1 in
start)
  # this should work but it doesn't since fstab is not correct.
  # should get around to fixing that, but for now, just run through
  # the partitions manually
  $mount -a
  if [ -n `grep /dev/sda2 /etc/mtab` ]; then
    $mount /dev/sda2 /mnt/HD_a2
  fi
  if [ -n `grep /dev/sdb2 /etc/mtab` ]; then
    $mount /dev/sdb2 /mnt/HD_b2
  fi
  if [ -n `grep /dev/sdb4 /etc/mtab` ]; then
    $mount /dev/sdb4 /mnt/HD_b4
  fi
  ;;
stop)
  /bin/sync;/bin/sync;/bin/sync;
  for p in $regularPartitions; do
    if [ -n "`$grep $p /etc/mtab`" ]; then
      $umount $p
      if [ $? -ne 0 ]; then
#          echo "could not unmount $p open files follow:"
#          $lsof  | $grep /mnt
          /bin/sync;/bin/sync;/bin/sync;
          $mount -o remount,ro $p
      fi
    fi
  done
  ;;
  *)
  ;;
esac
}

config_mounts () {
case $1 in
start)
  if [ -n `grep /dev/sda4 /etc/mtab` ]; then
    mount /dev/sda4 /mnt/HD_a4
  else
    mount -o remount,rw /dev/sda4 /mnt/HD_a4
  fi
  if [ -n `grep /mnt/HD_a4/opt /etc/mtab` ]; then
    if [ -d /mnt/HD_a4/opt ]; then
      if [ \! -e /opt ]; then
        mkdir -p /opt
      fi
      mount --bind /mnt/HD_a4/opt /opt
    fi
  fi
  ;;
stop)
  if [ -n "`$grep /mnt/HD_a4/opt /etc/mtab`" ]; then
    $umount /opt
  fi
  if [ -n "`$grep /dev/sda4 /etc/mtab`" ]; then
    /bin/sync;/bin/sync;/bin/sync;
    $umount /dev/sda4
    if [ $? -ne 0 ]; then
#      echo "could not unmount /dev/sda4 open files follow:"
#      $lsof  | $grep /mnt
      $mount -o remount,ro /dev/sda4 /mnt/HD_a4
    fi
  fi
  ;;
*)
  ;;
esac
}

#
# here are the actual run levels
shutdown () {
  crond   stop
  atd     stop
  ffp     stop
  smb     stop
  webs    stop
  op_server stop
  fancontrol stop
  kill_except chkbutton
  sleep 5
  utelnetd start
  data_mounts stop
  config_mounts stop
  $chmod 777 /mnt/*
  chkbutton start
  touch /tmp/shutdown
}

reboot () {
  atd     stop
  crond   stop
  ffp     stop
  smb     stop
  op_server stop
  fancontrol stop
  kill_except chkbutton
  sleep 5
  utelnetd start
  data_mounts stop
  config_mounts stop
  $chmod 777 /mnt/*
  chkbutton start
  /sbin/reboot
}

maintenance () {
  crond stop
  atd   stop
  ffp   stop
  smb   stop
  op_server stop
  kill_except parent e2fsck utelnetd fancontrol chkbutton webs
  sleep 5
  utelnetd start
  data_mounts   stop
  config_mounts stop
  $chmod 777 /mnt/*
}

running () {
  config_mounts start
  data_mounts start
  fancontrol start
  chkbutton start
  webs start
  utelnetd start
  atd start
  crond start
  smb start
  op_server start
  ffp start
}

#maint00 () {
#  atd   stop
#  crond stop
#  ffp   stop
#  smb   stop
#  webs  stop
#  op_server stop
#  kill_except e2fsck utelnetd
#  sleep 5
#  utelnetd start
#  data_mounts   stop
#  config_mounts stop
#  $chmod 777 /mnt/*
#}

case $1 in
running)
  running
  ;;
maintenance)
  maintenance
  ;;
shutdown)
  shutdown
  ;;
reboot)
  reboot
  ;;
*)
  echo "$0 imitates some run levels to
  echo "facilitate clean shutdown, reboot and maintenance mode"
  echo "$0: [ reboot | shutdown | maintenance | running ]"
esac

Offline

 

#87 2009-07-24 12:40:54

castor
Member
Registered: 2007-12-18
Posts: 5

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

excellent work talkingRock ! Thank you!

Offline

 

#88 2009-10-04 03:12:56

BurstDragon
New member
Registered: 2009-10-03
Posts: 3

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

Hey guys,

after installing cleanboot2.0.0 from the first post on my ffp0.5 the box can't be reached anymore. After it restarts it rejects any connection, does anybody knows a way wo to get in again?

EDIT: It seems that cleanboot only purged my hostname, so it had none. Under its regular IP it was rechable. So problem is fixed!


greez Burst

Last edited by BurstDragon (2009-10-04 11:07:45)

Offline

 

#89 2009-11-02 18:10:51

pof
Member
From: Barcelona
Registered: 2008-03-07
Posts: 28
Website

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

New version 2.1 published, basically I've included all fixes in the bugfix releases 2.0.4 & 2.0.5 done by marinalink and SilentException (thanks guys!) plus some suggestions found in other comments.
Should work fine in DNS323 & CH3SNAS using fun_plug 0.5.
First post & wiki updated with instructions.

Offline

 

#90 2009-11-03 12:13:43

knireis
Member
Registered: 2007-12-10
Posts: 231

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

thanks,
i never got the old version to work on my ch3snas, but 2.1 seems to work fine.

Offline

 

#91 2010-02-01 01:56:16

ojosch
Member
Registered: 2010-01-15
Posts: 18

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

pof wrote:

* How to shutdown your box after cleanboot has been installed:

telnet or ssh into your box and issue the command 'shutdown' or 'halt'.

NOTE: at the moment this is the only way to cleanly shutdown, if you do it either via the web panel or by pressing the button, the hard drives will not be cleanly unmounted.

.
.
I have figured out a way to allow the shutdown command to be called from turning off by using the power button. Pushing power button eventually calls the raidstop script which can be manipulated to initiate Cleanboot's shutdown command.

See my new thread here: http://dns323.kood.org/forum/viewtopic.php?id=5346
.
.

Last edited by ojosch (2010-02-01 01:57:51)

Offline

 

#92 2010-04-27 20:10:36

marcaronson408
New member
Registered: 2010-04-27
Posts: 2

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

I am having problems. I have installed the latest version of cleanboot on my DNS-321, but I am now getting "not found" whenever I try to halt, shutdown or reboot from an ssh session:

/mnt/HD_a2/ffp # reboot
/ffp/bin/sh: reboot: not found
/mnt/HD_a2/ffp # halt
/ffp/bin/sh: halt: not found
/mnt/HD_a2/ffp # shutdown
/ffp/bin/sh: shutdown: not found
/mnt/HD_a2/ffp # do_reboot
/ffp/bin/sh: do_reboot: not found

The following shows that I do have the file "do_reboot":

root@dlnas:/usr/sbin# which halt
/sbin/halt
root@dlnas:/usr/sbin# ls -l /sbin/halt
lrwxrwxrwx    1 root     root           19 Apr 27 17:00 /sbin/halt -> /usr/sbin/do_reboot
root@dlnas:/usr/sbin# ls -l /usr/sbin/do_reboot
-rwxr-xr-x    1 root     root         3632 Apr 27 17:00 /usr/sbin/do_reboot
root@dlnas:/usr/sbin# which do_reboot
/usr/sbin/do_reboot
root@dlnas:/usr/sbin# do_reboot
-sh: do_reboot: not found

Any help would be greatly appreciated.

marc

Offline

 

#93 2010-04-27 20:24:20

pof
Member
From: Barcelona
Registered: 2008-03-07
Posts: 28
Website

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

@marcaronson408: make sure /sbin and /usr/sbin are on your $PATH, you can check by typing 'echo $PATH'.

Offline

 

#94 2010-04-28 00:26:29

marcaronson408
New member
Registered: 2010-04-27
Posts: 2

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

pof wrote:

@marcaronson408: make sure /sbin and /usr/sbin are on your $PATH, you can check by typing 'echo $PATH'.

Thank you for that suggestion. Unfortunately, that is not the problem as those two directories are already on my path:

root@dlnas:/mnt/HD_a2/ffp/home/root# echo $PATH
/ffp/sbin:/usr/sbin:/sbin:/ffp/bin:/usr/bin:/bin

I am wondering if I am missing a shared library -- when I execute "file do_reboot" I see the following:

root@dlnas:/usr/sbin# file do_reboot
do_reboot: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), stripped

Offline

 

#95 2010-07-01 02:36:57

nicewei
New member
Registered: 2010-07-01
Posts: 1

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

I have exactly the same problem as marcaronson408 on my new DNS-321. Does anyone know how to get this to work?
Thanks

marcaronson408 wrote:

I am having problems. I have installed the latest version of cleanboot on my DNS-321, but I am now getting "not found" whenever I try to halt, shutdown or reboot from an ssh session:

/mnt/HD_a2/ffp # reboot
/ffp/bin/sh: reboot: not found
/mnt/HD_a2/ffp # halt
/ffp/bin/sh: halt: not found
/mnt/HD_a2/ffp # shutdown
/ffp/bin/sh: shutdown: not found
/mnt/HD_a2/ffp # do_reboot
/ffp/bin/sh: do_reboot: not found

The following shows that I do have the file "do_reboot":

root@dlnas:/usr/sbin# which halt
/sbin/halt
root@dlnas:/usr/sbin# ls -l /sbin/halt
lrwxrwxrwx    1 root     root           19 Apr 27 17:00 /sbin/halt -> /usr/sbin/do_reboot
root@dlnas:/usr/sbin# ls -l /usr/sbin/do_reboot
-rwxr-xr-x    1 root     root         3632 Apr 27 17:00 /usr/sbin/do_reboot
root@dlnas:/usr/sbin# which do_reboot
/usr/sbin/do_reboot
root@dlnas:/usr/sbin# do_reboot
-sh: do_reboot: not found

Any help would be greatly appreciated.

marc

Offline

 

#96 2010-07-21 06:05:17

kenlau
Member
Registered: 2010-07-21
Posts: 7

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

I am using DNS-323 with latest firmware 1.09. After installing Cleanboot 2.1, I cannot browse Volume_1 and Volume_2 folder from Windows Explorer. Moreover, I also cannot get other installs, i.e., Transmission 2.1 and OpenVPN to work either. I either have permissions errors, or in the case of OpenVPN, the start-up script starts only after I type the reboot or shutdown command. As a result, the shutdown process is interrupted and it does not shutdown unless I use the Web UI.

I am using to WD 2TB drives in standard configuration, i.e., standalone drives, no RAID.

Offline

 

#97 2010-07-22 10:08:49

bscott
Member
Registered: 2007-07-13
Posts: 48

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

Howdy - I've got a DNS-323 with two drives running independently, and currently they both seem to need a fsck as they fail the scandisk check...  I've had FFP installed for years and installed Cleanboot some while ago, but I forget to use it or the DNS will crash on occasion, or just lose power, etc. so it's not hard to figure out why.

Anyway I've been looking into the various ways to do a fsck, but with 2 small kids in the house nowadays I just don't have time to sit down and even read the instructions properly!  I'm wondering if there's any reason why I can't just pull out the drive, pop it into a SATA-USB docking station and connect it to a Linux machine, and run a standard fsck that way?

Back when I ran RAID there would be the occasional problem with connecting the drives to another system and then putting them back into place, and so on, but I don't think that would be a problem now?  I'm running firmware v1.08 and the fun_plug script is marked with the date 2008_4_13 for what that's worth.

I use one 320GB drive to store files and a larger, 1TB drive, to back up both the smaller drive and the various desktop machines around the house via NFS links and a Time-machine-like rsync script I cobbled together back when I had more than a few brain cells to rub together... I could back up each drive before running rsync by just cloning it (the SATA dock I use has two ports and can do cloning even easier than a dd) but I also recall the DNS-323 somehow keeps track of drive serial numbers so I hesitate before even considering a direct clone of a drive as an effective plug-in backup solution (even though I know the files themselves would be recoverable enough).

So anyway, I throw myself on the mercy of those who have more reliable knowledge of the 323 than I do - can I just shut down the server, pull out the drive and attach it to my Linux system to fix up whatever little bits of cruft that have crept in, then plug it back in without any hassle? (provided all the errors are minor and fixable)

Offline

 

#98 2010-12-23 13:18:32

jamieburchell
Member
Registered: 2010-03-25
Posts: 37

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

I'm a little confused with the progress of this now. Does the box cleanly shutdown when pressing the button on the front or not? There are posts here where people say they've worked out how...
Also, does it cleanly shutdown/restart from the web UI?

Is issuing the "halt/reboot" commands the same as using the web UI - even without cleanboot installed?

Offline

 

#99 2011-02-15 00:14:52

jboo
New member
Registered: 2011-02-14
Posts: 1

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

I installed cleanboot-2.1-ffp05 for my DNS-321 and found out the binary wasn't compatible (executing it would give me a "not found" error message).

After seeing the source code is only calling the cleanboot.sh script, I basically bypassed it by renaming /ffp/share/cleanboot.sh to do_reboot and editing it to handle the appropriate args.  That, and some tweaks to the startup script to address the changes seems to be working for me, and I think will be more compatible w/ future firmware since it doesn't have a compiled piece to worry about.

To test,  restarted and shutdown via "restart" and "shutdown" links, and also utilized the web based shutdown and restart.  In all cases, after bringing up the NAS, I didn't get any new e2fsck errors from dmesg.  Is this the only way to see that the umount was done properly?

Offline

 

#100 2012-03-05 18:51:51

koobs
New member
Registered: 2012-03-05
Posts: 1

Re: cleanboot 1.0 for DNS-323 / CH3SNAS

jboo, I'm in the same boat could you post some more detailed info about the changes you made to cleanboot.sh script and the startup or post the files themselves so I can take a look. Thanks!

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB