Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 30 Jul 2014, 15:13
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
ADVANCED pup-5xx /sbin/init
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [23 Posts]   Goto page: 1, 2 Next
Author Message
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 18:35    Post subject:  ADVANCED pup-5xx /sbin/init
Subject description: for FULL-Install
 

2 problems occured for me :
1 . : /lib and /bin,/sbin became more than 14MB
2 . : cp -a /bin copied a symlink to busybox , but not my own compiled busybox , which I symlinked after renaming the original busybox .

busybox itself and e2fsck are the main actors for /sbin/init , which if dynamically compiled need libs from /lib .

find@pup511 needs libm.so.6 -> , while find@pup430 not .
ls@pup430 needs libpthread* ......

While pup430 uses 3,5MB of /lib/lib*.so* , pup5xx are using 9-10MB ....

In this thread I want to discuss possibilities and want to present my solutions until now .

One of the main TODOs is to find out , which libs are essentially needed .

So here's the code to filter , which I am using :
Code:
check_space_func(){
####
####KRG check for enough space ...

###Check for Available Test dev node :
if [ "`ls -l /dev/ram8 | cut -b 1-3`" != "brw" -o "`ls -l /dev/ram8 | cut -f 5,6 -d ' '`" != "1, 8" ] ; then
rm -f /dev/ram8
mknod /dev/ram8 b 1 8
fi

echo -e "\\033[1;34m"'Checking for Compiled RamDisk Size using:'"\\033[0;39m"
MAXSIZEdevRAM1=`mkfs.ext2 -v -b 1024 -i 1024 /dev/ram8 | grep 'blocks' | grep 'inodes' | tr -s ' ' | cut -f 3 -d ' '`
SIZEdevRAMdisk1=$(($MAXSIZEdevRAM1 * 93 / 100))  ###KRG 0.93 is precaution
echo
KERNV=`uname -r`

###Check for /lib/lib*.so* sizes :
echo -e "\\033[1;34m"'Checking Size of /lib/lib*.so* and /lib/ld*.so* ...'
echo -e "\\033[0;39m"
SPACElib=0
LLS=`ls -l /lib/* | grep -o '/lib/.*\->.*' | grep 'firefox' | cut -f 1 -d ' '`
[ "$DebugVal" -ge "2" ] && echo -e "\\033[0;31m"'firefox-libs: '$LLS && echo
LF=`find /lib -maxdepth 1 -name "lib*.so*" -o -name "ld*.so*"`
#Filter not needed files :
LIBF=`echo "$LF" | grep -v "$LLS" | grep -v -E 'libuClibc.*|ld\-uClibc.*|libthread.*|libm\.so\.0|libm\-0.*' | sort`
for i in $LIBF ; do
SiZElib=`ls -s $i | cut -f 1 -d ' '`
SPACElib=$(($SPACElib + $SiZElib))
[ "$DebugVal" -ge "2" ] && echo -n "$i"'='"$SiZElib "  ###DBG
[ "$DebugVal" -eq "1" ] && [ "$SiZElib" -ne "0" ] && echo -n "$i"'='"$SiZElib "
done
[ "$DebugVal" -ge "2" ] && echo && echo 'total /lib='"$SPACElib"  ###DBG
[ "$DebugVal" -ge "1" ] && echo

echo  -e "\\033[1;34m"'Checking for available RAM ...'
echo -e "\\033[0;39m"
RAM=`free | grep -i 'mem' | sed 's#^[[:blank:]]*##' | tr -s ' ' | cut -f 2 -d ' '`
FREERAM=`free | grep -i 'mem' | sed 's#^[[:blank:]]*##' | tr -s ' ' | cut -f 4 -d ' '`
RAMLIMITdevRAM2=$(($MAXSIZEdevRAM1 * 2))
echo '                  free counted total RAM:'"$RAM"  ###DBG
echo 'Available RAM (minus Kernel and modules):'"$FREERAM"  ###DBG
echo '     Minimum available free RAM required:'"$RAMLIMITdevRAM2"' ... '  ###DBG

if [ "$SPACElib" -gt "$SIZEdevRAMdisk1" -o "$RAMLIMITdevRAM2" -ge "$FREERAM" ] ; then  #1
echo
echo ";)"
echo -e "\\033[1;31m"
if [ "$RAMLIMITdevRAM2" -ge "$FREERAM" ] ; then                         #1.1
echo "Needed free RAM is $RAMLIMITdevRAM2 , but free RAM is $FREERAM"
else                                                                 #1.1
echo "/lib/lib*.so* is $SPACElib in KB and larger than the RamDisk compiled for"
echo -e "\\033[1;32m" 
echo "kernel $KERNV with $SIZEevRAMdisk1 / $MAXSIZEevRAM1 in KB"
fi  #1.1
echo -e "\\033[0;39m"
echo -e "\\033[1;31m" 
echo 'fsck omitted !!!'
echo -e "\\033[1;32m" 
echo 'please do the filesystemcheck via Live CD'
echo -e "\\033[1;33m" 
echo 'or booting another Puppy or Linux'
echo -e "\\033[1;36m" 
echo 'type [ reboot ] to reboot'
echo 'eventually you need to press CTRL+ALT+DELETE to reboot'
echo 'you may need to check BIOS bootorder also before booting LiveCD'
echo -e "\\033[0;39m"
echo 
echo 'dropping to console now , partition still mounted !'
cd /
sleep 2
##BUG-1:15JUN2011##exit
exec chroot . sh  ##BUG-1 fix##
fi  #1

echo -e "\\033[1;32m"
echo -e '                                 ... OK :'"\\033[0;39m"$(( $RAM - $FREERAM + $RAMLIMITdevRAM2 ))"\\033[1;32m"' required of '"\\033[0;39m"$RAM
echo -e "\\033[0;39m"
#####
}
check_space_func

[edit=15Jun2011]First BUG , which would not occur with more than Kernel+Ramdisk size of RAM >100MB :
The dropping to console by using "exit" is only possible with busybox init running . The exit here in that state would lead to kernel panic . As long as init is not head of all processes , it has to be "exec sh" or "exec chroot . sh" . Bash by default compiles with a PATH that only includes "*/bin" executables and busybox ash both : "*/bin" and "*/sbin" . Calling /sbin executables using "#!/bin/bash" can olny be done by calling the whole path like "exec /sbin/chroot . sh" .
Solutions for this might be "#!/bin/bash --login" , "#!/bin/ash" or setting the PATH variable in the script , which had always worked for me .
Because of some Linux distributions like Debian or Ubuntu put the executables into "/usr/bin:/usr/sbin" it is actually a security feature to not invoke a command by the whole path . One example would be "chroot" which I recognized to be located in some development isos
in "/usr/sbin" like luma-001 by playdayz or dpup-003 by iguleder .[/edit]

The filtering part is this :
################################
###Check for /lib/lib*.so* sizes :
echo -e "\\033[1;34m"'Checking Size of /lib/lib*.so* and /lib/ld*.so* ...'
echo -e "\\033[0;39m"
SPACElib=0
LLS=`ls -l /lib/* | grep -o '/lib/.*\->.*' | grep 'firefox' | cut -f 1 -d ' '`
[ "$DebugVal" -ge "2" ] && echo -e "\\033[0;31m"'firefox-libs: '$LLS && echo
LF=`find /lib -maxdepth 1 -name "lib*.so*" -o -name "ld*.so*"`
#Filter not needed files :
LIBF=`echo "$LF" | grep -v "$LLS" | grep -v -E 'libuClibc.*|ld\-uClibc.*|libthread.*|libm\.so\.0|libm\-0.*' | sort`
for i in $LIBF ; do
SiZElib=`ls -s $i | cut -f 1 -d ' '`
SPACElib=$(($SPACElib + $SiZElib))
[ "$DebugVal" -ge "2" ] && echo -n "$i"'='"$SiZElib " ###DBG
[ "$DebugVal" -eq "1" ] && [ "$SiZElib" -ne "0" ] && echo -n "$i"'='"$SiZElib "
done
[ "$DebugVal" -ge "2" ] && echo && echo 'total /lib='"$SPACElib" ###DBG
[ "$DebugVal" -ge "1" ] && echo
################################

There is a interactive menu for the "DebugVal" , and several functions and lines for splitting /lib into a second ramdisk , which I will post another time .

This box should collect Ideas , on how to work with the huge amount of libs , which I suppose to become more than 13MB in future . I must say , that I had heard about raid arrays but don't know , if one single directory can be splitted over several partitions .

Last edited by Karl Godt on Wed 15 Jun 2011, 13:35; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 18:44    Post subject:  

Here now the debug-menu :
Code:
ask_debug_func(){
DebugVal=0
echo -e "\\033[0;39m"
echo "Do you think $0 DEBUG MODE is required ?"
echo -e -n "\\033[1;34m"
echo "If so , press [ y ] and [ Enter ] for normal debug incl. 'fsck -v' ,"
echo -e -n "\\033[0;39m""\\033[6;7;32m"
echo "    or  press [ Y ] and [ Enter ] for extensive output ,"
echo -e -n "\\033[0;39m"
echo -e -n "\\033[1;36m" 
echo "which may confuse muchly first and second time ;)"
echo -e "\\033[1;35m"
echo "If not wait 60sec. or press any other key and or simply [ Enter ]"
echo -e "\\033[7;39m"
echo -n -e '->'"\\033[0;39m"
read -t 60 K
if [ "$K" = "y" ] ; then
DebugVal=1
echo
echo -e "\\033[0;33m"
echo 'Debug Mode '"$DebugVal"' turned on'
echo 'Have FUN !'
echo
[ "$DebugVal" -ge "1" ] && echo -n 'DebugVal='"$DebugVal "
elif [ "$K" = "Y" ] ; then
DebugVal=2
echo -e "\\033[0;31m"
echo 'Debug Mode '"$DebugVal"' turned on'
echo 'Have FUN !'
echo
[ "$DebugVal" = "2" ] && echo -n 'DebugVal='"$DebugVal "
else
echo -e "\\033[0;35m"
echo 'Keeping in Silent Screen Mode'
DebugVal=0
echo 'DebugVal='"$DebugVal "  ###DBG
fi
TimeOut=$(( ($DebugVal + 1) * 60 ))
[ "$DebugVal" -ge "1" ] && echo -e "\\033[0;33m"'TimeOut='"$TimeOut"
echo -e "\\033[0;39m"
}
ask_debug_func

simple , I thing bug-free until now ...
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 18:50    Post subject:  

first lines of code of my /sbin/init :
Code:
/bin/busybox mount -t proc none /proc  ###KRG put here for additional df check (wary094 frugal had written /initrd into full install) ###KRG
/bin/busybox mount -o remount,rw /

busybox_init_func(){  ###KRG
/bin/busybox mount -o remount,ro /
/bin/busybox umount /proc
exec /bin/busybox init
}

if [ -d /initrd -a -n "`/bin/busybox df | grep '/initrd'`" ] ; then  ###KRG
echo "$0: Not a full install, continuing with '/bin/busybox init ...'"
busybox_init_func
fi  ###KRG

also simple ....
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 18:58    Post subject:  

I did not like the name fsckme.err , which had changed to fsckme.flg but in my opinion shoud be located in /boot or /etc and be a hidden file , like /etc/.XLOADED .
This function looks for any *FsCkMe.file* using "find -maxdepth 3 -iname ..." :
Code:
errflag_func() {  ###KRG
echo -n -e "\\033[1;33m"'Searching for *fsckme* file 3 levels deep ... '"\\033[0;39m"
ErrFlag=`/bin/busybox find / -maxdepth 3 -type f -iname '*fsckme*' | head -n1`  ###KRG 3 deep for fsckme.file@etc @boot @$HOME ..etc..
if [ -z "$ErrFlag" ] ; then
echo -e "\\033[1;32m" 'No'
echo -e "\\033[0;39m"
busybox_init_func
fi
echo -e "\\033[7;31m" 'YES :'"\\033[0;33m"" $ErrFlag"
echo -e "\\033[0;39m"

}
errflag_func  ###KRG

simple ...
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 19:05    Post subject:  

for interactive menus needed USB keyboard kernelmodules + fbcon
Code:
#####KRG for USB keyboards
modprobe ehci_hcd
modprobe uhci_hcd
modprobe ohci_hcd
modprobe usbhid
###KRG loading fbcon :
fbcon_func() {
if [ -n "`modprobe -l | grep 'fbcon'`" ]; then
if [ "`cat /proc/cmdline | grep -E 'vga=ask|vga=0x3[0-9a-fA-F][0-9a-fA-F]|vga=7[0-9][0-9]'`" != "" ]; then
modprobe fbcon  ###modprobe fbcon scrollback:1024K ###for larger scrollback buffer  ###KRG
fi
fi
}
fbcon_func  ###COMMENT if required ; fbcon makes colors little greyish  ###KRG

simple ...
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 19:19    Post subject:  

if youre swithing between IDE and SATA kernels , entries @fsckme.flg might be wrong :
Code:
check_dev_nodes_func(){
#####KRG
###KRG updating fsckme file case switching kernels sda|hda
ROOTDRIVE=`basename $(/bin/busybox rdev | cut -f 1 -d ' ')`  ### | cut -f 1 -d ' ' | sed 's#/dev/##'`
ROOTBLOCKDRIVE=${ROOTDRIVE:0:3}
[ "$DebugVal" -ge "1" ] && echo 'rootdrive='"$ROOTDRIVE"  ###DBG
FS=`mount | grep -w '/' | grep '/dev' | tr -s ' ' | cut -f 5 -d ' '`
PDEV1="$ROOTDRIVE"
DEV1FS="$FS"
[ "$DebugVal" -eq "2" ] && echo $ROOTDRIVE $ROOTBLOCKDRIVE $FS ',' $PDEV1 $DEV1FS
DMESG=`dmesg | grep 'Mounted root' | grep -o 'device.*' | cut -f 2 -d ' ' | sed 's#[[:alpha:][:punct:]]$##`
MAJ=`echo $DMESG | cut -f 1 -d ':'`
Min=`echo $DMESG | cut -f 2 -d ':'`
CATPP=`cat /proc/partitions | sed 's#^[a-zA-Z].*##g ; s#^[[:blank:]][a-zA-Z]##g ; /^$/d' | tr -s ' ' | sed 's#^ ##'`
MAJBL=`echo "$CATPP" | grep -w "$ROOTBLOCKDRIVE" | cut -f 1 -d ' '`
MinBL=`echo "$CATPP" | grep -w "$ROOTBLOCKDRIVE" | cut -f 2 -d ' '`
[ "$DebugVal" -eq "2" ] && echo $DMESG $MAJ $Min ',' $MAJBL $MinBL ',' $CATPP
}
check_dev_nodes_func

this copies /dev/* into ramdisk :
Quote:
cp -a -r /dev /mnt/ram0/

Code:
check_dev_nodes_funcII(){
  ###KRG: check for existance and correct MAJ Min numbers of absolutely essential devices
  [ ! -b /mnt/ram0/dev/${ROOTBLOCKDRIVE} ] && mknod /mnt/ram0/dev/${ROOTBLOCKDRIVE} b $MAJBL $MinBL
  [ ! -b /mnt/ram0/dev/${PDEV1} ] && mknod /mnt/ram0/dev/${PDEV1} b $MAJ $Min
  LSRBLDR=`ls -l /mnt/ram0/dev/${ROOTBLOCKDRIVE} | tr -s ' ' | cut -f 5,6 -d ' ' | tr -d ','`
  LSPDEV1=`ls -l /mnt/ram0/dev/${PDEV1} | tr -s ' ' | cut -f 5,6 -d ' ' | tr -d ','`
  MAJLSBLDR=`echo $LSRBLDR | cut -f 1 -d ' '`
  MinLSBLDR=`echo $LSRBLDR | cut -f 2 -d ' '`
  MAJLSPDEV1=`echo $LSPDEV1 | cut -f 1 -d ' '`
  MinLSPDEV1=`echo $LSPDEV1 | cut -f 2 -d ' '`
  [ "$DebugVal" -eq "2" ] && echo  -e "\\033[0;31m"'DRIVES :'$LSRBLDR $MAJLSBLDR $MinLSBLDR ',' $LSPDEV1 $MAJLSPDEV1 $MinLSPDEV1
  if [ "$MAJLSBLDR" != "$MAJBL" -o "$MinLSBLDR" != "$MinBL" ] ; then
  rm /mnt/ram0/dev/${ROOTBLOCKDRIVE} && mknod /mnt/ram0/dev/${ROOTBLOCKDRIVE} b $MAJBL $MinBL
  fi
  if [ "$MAJLSPDEV1" != "$MAJ" -o "$MinLSPDEV1" != "$Min" ] ; then
  rm /mnt/ram0/dev/${PDEV1} && mknod /mnt/ram0/dev/${PDEV1} b $MAJ $Min
  fi
}
  check_dev_nodes_funcII

is not really essential , but in case of corrupted /dev/MAINDRIVE ...
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 19:24    Post subject:  

transfering VARIABLES from post 2 and 6 :
Code:
echo "$ROOTDRIVE"','"$FS"',' > /mnt/ram0/etc/fsckme.err  ###KRG
echo 'DebugVal='"$DebugVal" > /mnt/ram0/etc/initdebug.in  ###KRG
echo 'TimeOut='"$TimeOut" >> /mnt/ram0/etc/initdebug.in  ###KRG

simple ...
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 19:30    Post subject:  

Quote:
#creat a ramdisk...
#note, Puppy kernels are compiled with 13MB ramdisk, so need to be careful not to fill it up...
echo -e "\\033[0;35m"'Creating a ramdisk and populating with a Linux environment...'

checking and creating two ramdisks :
Code:
check_ram0_func(){
  if [ ! -b /dev/ram0 -o "`ls -l /dev/ram0 | cut -b 1-3`" != "brw" -o "`ls -l /dev/ram0 | cut -f 5,6 -d ' '`" != "1, 0" ]; then  ###KRG
  echo  -e "\\033[1;31m"'block /dev/ram0 does not exist'
  rm -f /dev/ram0
  echo -e "\\033[0;39m"'creating now'
  mknod /dev/ram0 b 1 0
  fi
}
  check_ram0_func
 
  mkfs.ext2 -q -m 5 -b 1024 -i 1024 /dev/ram0
 
make_ram9_func(){
  [ ! -b /dev/ram9 -o "`ls -l /dev/ram9 | cut -b 1-3`" != "brw" -o "`ls -l /dev/ram9 | cut -f 5,6 -d ' '`" != "1, 9" ] && rm -f /dev/ram9 && mknod /dev/ram9 b 1 9  ###KRG
  mkfs.ext2 -q -m 5 -b 1024 -i 1024 /dev/ram9
  sleep 2s
}
  make_ram9_func
 
  mkdir -p /mnt/ram0
  mkdir -p /mnt/ram9  ###KRG
 
  busybox mount -t ext2 /dev/ram0 /mnt/ram0
  busybox mount -t ext2 /dev/ram9 /mnt/ram9  ###KRG
  sleep 2s  ###KRG

had been medium difficult , used "mkfs.ext2 -m 5" instead of "-m 0" ....
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 19:51    Post subject:  

Quote:
#populate the ramdisk...
mkdir -p /mnt/ram0/old_root
mkdir /mnt/ram0/bin

my func for checking busybox :
Code:
busybox_func(){
  ###KRG BUSYBOX
  echo -n -e "\\033[1;34m"'Checking if /bin/busybox is a link to "MyBusybox" : '
  RLF=`readlink -f /bin/busybox` 
  LSLBB=`ls -l /bin/busybox | grep -o '\->.*'`  ###KRG if busybox is a symlink to busybox-version
 
  if test "$LSLBB" != "" ; then
  echo -e "\\033[1;32m"'YES'
  echo -e "\\033[0;39m"'Copying '"$RLF"' into RamDisk'
  RLBB=`echo $RLF | sed 's#/bin/##'`
  cp -a /bin/"$RLBB" /mnt/ram0/bin/"$RLBB"
  else
  echo -e "\\033[0;32m"'No'
  fi
  echo -e "\\033[0;39m"
}
  busybox_func

Code:
for ONEBIN in "[" "[[" ash autologinroot basename busybox cat chmod chown clear cp cut date dc dd df dirname dmesg du e3 ed expr false find free grep head kill ln login ls lsmod mkdir mknod more mv nice ntfs-3g pidof pwd readlink rev rm rmdir sed sleep sort stat su sync tail tar touch tr true uname usleep waitmax wc which xargs
  do  ###KRG added e3
   if [ -x /bin/$ONEBIN ] && [ ! -x /mnt/ram0/bin/$ONEBIN ] ;then  ###KRG for symlink busybox
    cp -a /bin/$ONEBIN /mnt/ram0/bin/
    [ "$DebugVal" = "2" ] && echo -n '/bin/'"$ONEBIN "
   else
    if [ "$ONEBIN" != "busybox" -a "`busybox | grep $ONEBIN`" != "" ] ; then  ###KRG
    [ "$DebugVal" = "2" ] && echo -n 'link '"$ONEBIN "
    ln -s busybox /mnt/ram0/bin/$ONEBIN
    fi
   fi
  done
  ln -snf busybox /mnt/ram0/bin/ps ; [ "$DebugVal" = "2" ] && echo -n ' link ps' 
  ln -snf busybox /mnt/ram0/bin/rdev ; [ "$DebugVal" = "2" ] && echo -n ' link rdev'
  ln -snf busybox /mnt/ram0/bin/sh ; [ "$DebugVal" = "2" ] && echo -n ' link sh'
  ln -snf busybox /mnt/ram0/bin/mount ; [ "$DebugVal" = "2" ] && echo -n ' link mount'
  ln -snf busybox /mnt/ram0/bin/umount ; [ "$DebugVal" = "2" ] && echo -n ' link umount'
  [ "$DebugVal" = "2" ] && echo

spend many hours and days on that ...
BB-1.18.3-static+upx.tar.gz
Description  BB-Dotconfig and upxed bin .. Do not replace BB while running X !
gz

 Download 
Filename  BB-1.18.3-static+upx.tar.gz 
Filesize  638.45 KB 
Downloaded  469 Time(s) 
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 19:58    Post subject:  

now copying /lib into second ramdisk :
Code:
###KRG splitting /lib to second RamDisk :
  mkdir /mnt/ram9/lib 
  echo -e "\\033[1;34m"'Copying Libs ... '
  for i in $LIBF ; do  ###KRG to sort unneeded libs out , see further up ###KRG
  [ "$DebugVal" -ge "1" ] && echo -n -e "\\033[0;33m""$i""\\033[0;39m"' , '
  cp -a $i /mnt/ram9/lib/
  done 
  [ "$DebugVal" -ge "1" ] && echo -e "\\033[0;39m"
   
  [ "$DebugVal" = "0" ] && cp -a /lib/e2initrd_helper /mnt/ram9/lib/ 2>/dev/null #dunno what this is.  ###KRG me not either
  [ "$DebugVal" -ge "1" ] && echo -e "\\033[0;33m"'Copying /lib/e2initrd_helper .. ' && cp -a /lib/e2initrd_helper /mnt/ram9/lib/
 
  /bin/busybox ln -s /mnt/ram9/lib /mnt/ram0/lib
  mkdir /mnt/ram0/mnt
  mkdir /mnt/ram0/mnt/ram9

$LIBF see post Nr 1 ....
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 20:09    Post subject:  

Quote:
#pivot_root to the ramdisk...
echo -e "\\033[0;35m"'Performing a pivot_root to the ramdisk...'

the pivot_root part :
Code:
[ "$DebugVal" -ge "1" ] && echo -e "\\033[0;33m"'pivot_root now ...'  ###DBG
pivot_root . old_root
[ "$DebugVal" -ge "1" ] && echo -e "\\033[0;33m"'... pivoted'  ###DBG
 
[ ! -d /mnt/ram9 ] && mkdir -p /mnt/ram9  ###KRG needs to be immediately after pivot_root  ###KRG
/bin/busybox mount -o move /old_root/mnt/ram9 /mnt/ram9
/bin/busybox mount -o move /old_root/proc /proc

echo -e "\\033[1;34m"'Unmounting everything beneath /old_root/* ...'
OR=`mount | grep '/old_root/' | cut -f 3 -d ' ' | sort -r`
for i in $OR ; do
[ "$DebugVal" -ge "1" ] && echo -e "\\033[0;33m"'unmounting '"$i"  ###DBG
/bin/busybox umount $i
Err=$?
if [ "$Err" -ne "0" ] ; then
[ "$DebugVal" -ge "1" ] &&  echo -e "\\033[0;33m"'failed , trying lazy .. '  ###DBG
/bin/busybox umount -l $i
fi
done

I have another /sbin/init that manages the mounting and linking of the second ramdisk slightly different .
The problem is for now , that later "/old_root" gets unmounted but returns an error code of 1 .....
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 20:17    Post subject:  

Menu to drop out into rdsh/rdsh0/rdsh6 like pfix=rdsh parameter for frugal installs :
Code:
####KRG Menu for RamDiskShell
echo 
echo -e "\\033[0;32m"
echo 'Press ANY key and or ENTER to perform fsck'
echo 'Or wait 60s * ($DebugVal + 1)'
echo 'scrolling might be allowed by Shift+PageUP/Down'
echo 'that is cause to have to hit the Enter key'
echo -e "\\033[0;31m"
echo "or [s] or [r] for drop out into simple rdsh"
echo "or [i] or [b] for drop out into rdsh with busybox init on top"
echo -e "\\033[7;39m"
echo -n -e '->'"\\033[0;39m"
read -t $TimeOut K
if [ "$K" = "s" -o "$K" = "S" -o "$K" = "r" -o "$K" = "R" ] ; then
echo
echo -e "\\033[0;32m"
echo 'dropping now into simple rdsh'
echo 'Have FUN !'
echo
echo -e "\\033[0;39m"
login -f root
exec /sbin/chroot . /bin/sh
 
elif [ "$K" = "i" -o "$K" = "I" -o "$K" = "b" -o "$K" = "B" ] ; then
echo
echo -e "\\033[0;32m"
echo 'dropping now into busybox init rdsh'
echo -e "\\033[0;33m"
echo 'Have MORE FUN !'
echo
echo -e "\\033[0;39m"
echo '#DUMMY' > /etc/rc.d/rc.sysinit
chmod 0775 /etc/rc.d/rc.sysinit
 
exec /sbin/chroot . /bin/sh -c "exec /bin/busybox init" <dev/console >dev/console 2>&1
 
else 
exec /sbin/chroot . /bin/sh -c "exec /bin/busybox init" <dev/console >dev/console 2>&1
fi
#...the ramdisk is setup so that /etc/rc.d/rc.sysinit will run, which does the f.s. check.

medium severe ....
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 20:25    Post subject:  

the end of /sbin/init :
Code:
;;
 *)
  echo -e "\\033[1;31m"  #34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black.
  echo -n "Previous improper shutdown, sorry can only do f.s. check of ext2/3/4."
  echo -e "\\033[0;39m"
  sleep 5s
  mount -o remount,ro /  ###KRG
  exec /bin/busybox init  ###should be something like umount -ar ; reboot ###KRG
 ;;
esac

###END###

the original code does not run reboot here ...

To get it going I added this to the "real" /etc/rc.d/rc.sysinit :
Code:
fsckme_func_0() {
FSCKME=`find / -maxdepth 3 -type f -iname "*fsckme*"`  ###KRG, for ADvanced /sbin/init
echo $FSCKME  ###DBG
if [ -n "$FSCKME" ] ; then  ###KRG

modprobe ehci_hcd
modprobe ohci_hcd
modprobe uhci_hcd
modprobe usbhid

echo -e "\\033[1;31m"' ... '"$FSCKME"' still exists !'
echo
echo -e "\\033[0;31m"'Want to boot anyway [ B ],[ b ] and [ Enter ] ?'
echo -e "\\033[1;32m"'Reboot [ R ],[ r ] and [ Enter ] ?'
echo -e "\\033[0;32m"'Poweroff [ P ],[ p ] and [ Enter ] ?'
echo -e "\\033[1;34m"'Or simply exit rc.sysinit [ Enter ],[ any other key and Enter ] ?'
echo -e "\\033[1;33m"'         ( timeout 60 sec ... -> exit ) '
echo -e "\\033[7;39m"
echo -n '->'
read -t 60 K
echo -e "\\033[0;39m"
if [ "$K" = "R" -o "$K" = "r" ] ; then
echo 'Rebooting ...'
/bin/busybox umount -ar
/bin/busybox reboot
fi

if [ "$K" = "P" -o "$K" = "p" ] ; then
echo "Pow'ring off the computer ..."
/bin/busybox umount -ar
/bin/busybox poweroff
fi

if [ "$K" = "B" -o "$K" = "b" ] ; then
echo 'Continuing booting ...'
else
echo 'Exiting /etc/rc.d/rc.sysinit'
exit
fi
fi
}
fsckme_func_0

This goes to the very beginning and might need a "mount -t proc none /proc" ....
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 20:36    Post subject:  

/sbin/init_ramdisk_fsck_/etc/rc.d/rc.sysinit :
Code:
echo '#!/bin/sh
PDEV1=`cat /etc/fsckme.err | cut -f 1 -d ","`  ###KRG
DEV1FS=`cat /etc/fsckme.err | cut -f 2 -d ","`  ###KRG
. /etc/initdebug.in  ###KRG
echo -e "\\033[0;32m"
echo "Now running in ramdisk, preparing for filesystem check of ${PDEV1}..."
echo -e "\\033[0;39m"
[ ! -d /proc ] && mkdir /proc
if [ -z "`mount | grep -o /proc`" ] ; then
[ "$DebugVal" = "0" ] && /bin/busybox mount -t proc none /proc 2>/dev/null  ###KRG added: 2>/dev/null  ###KRG
[ "$DebugVal" -ge "1" ] && /bin/busybox mount -t proc none /proc
fi 
[ "$DebugVal" = "0" ] && /sbin/hwclock --hctosys --localtime 2>/dev/null
[ "$DebugVal" -ge "1" ] && /sbin/hwclock --hctosys --localtime
echo "unmounting the rootdrive ..."   ###KRG
echo
MOR=`mount | grep "/old_root/"`
for i in `echo "$MOR" | cut -f 3 -d " " | sort -r` ; do
[ "$DebugVal" = "0" ] && /bin/busybox umount $i 2>/dev/null || ErrMor=$?  ###KRG
[ "$DebugVal" -ge "1" ] && /bin/busybox umount $i || ErrMor=$?
if [ -n "$ErrMor" ] && [ "$ErrMor" -ne "0" ] ; then
[ "$DebugVal" -ge "1" ] && echo "failed to unmount $i with Error=$ErrMor" && echo
fi
done
if [ -n "`mount | grep -o /old_root`" ] ; then
[ "$DebugVal" = "0" ] && /bin/busybox umount /old_root 2>/dev/null || Err1=$?
[ "$DebugVal" -ge "1" ] && /bin/busybox umount /old_root || Err1=$?  ###KRG
[ "$DebugVal" -ge "1" ] && echo "Unmounting /old_root: ERROR RETURNCODE=$Err1" && mount && echo  ###DBG
sleep 2s
if [ -n "$Err1" ] && [ "$Err1" -ne "0" ] && [ -n "`mount | grep -o /old_root`" ] ; then  ###KRG
echo "Not so good, was unable to unmount ${PDEV1}. trying lazy now..."
sleep 2s
/bin/busybox umount -l /old_root
Err3=$?
sleep 1s
[ "$DebugVal" -ge "1" ] && echo ERROR RETURNCODE="$Err3"
[ "$DebugVal" -ge "1" ] && echo "Still mounted :" && mount && echo
fi
if [ -n "$Err3" ] && [ "$Err3" -ne "0" ] ; then  ###KRG
echo "Not so good, was unable to unmount ${PDEV1}. trying option force ..."
sleep 2s
/bin/busybox umount -f /old_root
Err5=$?
sleep 1s
[ "$DebugVal" -ge "1" ] && echo ERROR RETURNCODE="$Err5"
[ "$DebugVal" -ge "1" ] && echo "Still mounted :" && mount && echo
fi
[ -n "$Err5" ] && [ "$Err5" -ne "0" ] && echo "Not so good, was unable to unmount ${PDEV1}. Continuing with f.s. check..."
fi
if [ -z "`mount | grep -o /old_root`" ] ; then
echo -e "\\033[1;32m""OK.""\\033[0;32m"" Fscking now ... depending on size of installation, might take awhile""\\033[0;39m"
if [ "$DebugVal" -ge "1" ] ; then
/sbin/e2fsck -v -f /dev/${PDEV1}
else
/sbin/e2fsck -f /dev/${PDEV1}
fi
else
echo -e "\\033[0;31m""Whatever cause ... /old_root or $PDEV1 still mounted!"
echo -e "\\033[0;33m""Performing read-only filesystem check ... ""\\033[0;39m"
[ "$DebugVal" -ge "1" ] && /sbin/e2fsck -n -f -v /dev/${PDEV1}
[ "$DebugVal" = "0" ] && /sbin/e2fsck -n -f /dev/${PDEV1}
fi
/bin/busybox sync
echo
echo -e "\\033[7;32m"
echo "Filesystem check completed!"
echo -e "\\033[0;31m"
mkdir -p /mnt/${PDEV1}  ###KRG removing fsckme.file  ###KRG
busybox mount -t ${DEV1FS} /dev/${PDEV1} /mnt/${PDEV1}
ErrFlag=`find /mnt/${PDEV1} -maxdepth 3 -type f -iname "*fsckme*"`
for i in $ErrFlag ; do
[ "$DebugVal" -ge "1" ] && echo "Removing $i"
rm $i
done
[ -f /mnt/${PDEV1}/etc/.XLOADED ] && rm /mnt/${PDEV1}/etc/.XLOADED
[ -f /mnt/${PDEV1}/tmp/bootcnt* ] && rm /mnt/${PDEV1}/tmp/bootcnt*
rm -f /var/log/X*
rm -f /var/lock/LCK*
rm -f /var/run/*.pid
SOCK=`find /mnt/${PDEV1}/var -mount -type s | tr "\n" " "`
for i in $SOCK ; do
[ "$DebugVal" -ge "1" ] && echo -e "\\033[0;33m""removing ""$i"
rm -f $i
done
PIPE=`find /mnt/${PDEV1}/var -mount -type p | tr "\n" " "`
for i in $PIPE ; do
[ "$DebugVal" -ge "1" ] && echo -e "\\033[0;33m""removing ""$i"
rm -f $i
done
sleep 2
/bin/busybox sync
busybox umount /dev/${PDEV1}  ###KRG
echo -e "\\033[0;36m"
echo "The computer now has to be restarted."
echo -e "\\033[0;35m"
echo "Computer will reboot in 1-3  minutes, else press ENTER for immediate reboot."
echo
echo -e "\\033[0;32m"  ###KRG
echo "Press Any key and or simply ENTER to reboot ,"
echo "or wait 60 sec again ."
echo -e "\\033[0;31m" >/dev/console
echo "or [ r ] for dropout into rdsh :"
echo -e "\\033[7;39m"
echo -n -e "->""\\033[0;39m"
read -t $TimeOut K
if [ "$K" = "r" -o "$K" = "R" ] ; then
echo
echo -e "\\033[0;32m"
echo "Dropping now"
echo "Have FUN !"
echo
echo -e "\\033[0;39m"
###exec /sbin/chroot . /bin/sh
exit
else
echo -e "\\033[0;39m"  ###KRG
[ "$DebugVal" = "0" ] && /bin/busybox umount /proc 2>/dev/null
[ "$DebugVal" -ge "1" ] && /bin/busybox umount /proc
/bin/busybox reboot
fi' > /mnt/ram0/etc/rc.d/rc.sysinit
  chmod 0755 /mnt/ram0/etc/rc.d/rc.sysinit

unmounting /old_root made me mad many times ... , especially if /old_root/dev is still mounted or /old_root/ramdisk2 . "umount -l" ( lazy ) is much more effective as far as my experience can tell , than "umount -f" ( force ) . The error message is same at '-l' and '-f' option ( can't forcibly umount ... ) .
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3956
Location: Kiel,Germany

PostPosted: Sat 14 May 2011, 20:51    Post subject:  

Now place for the script . It might differ slightly from the code I posted, which I did little cosmetics here and there . It works for me , so please post bugs and suggestions . I only have one working 10Year old IDE PC since my Laptop froze experimenting with the low-usb-driver "ub" , which is also blacklisted @/etc/rc.d/MODULESCONFIG at several puppies , so I am eager to hear where it works and not.
ADVANCEDpup5_sbin_init.tar.gz
Description  # tar -ztf ADVANCEDpup5_sbin_init.tar.gz
ADVANCEDpup5_sbin_init/
ADVANCEDpup5_sbin_init/init-1.0-1.1.diff
ADVANCEDpup5_sbin_init/KRG-init-v.1.1
ADVANCEDpup5_sbin_init/TODO
ADVANCEDpup5_sbin_init/README
ADVANCEDpup5_sbin_init/KRG-init-v.1.0
gz

 Download 
Filename  ADVANCEDpup5_sbin_init.tar.gz 
Filesize  9.19 KB 
Downloaded  396 Time(s) 
init_deLuxe.gz
Description  covers connection from initrd.gz to rc.sysinit
some puppies wanted /sys mounted (lhpup443)
checks for fsck-intervals
checks if partition is still clean prior to and if it is boots anyway
if fsck then tries to load files from other Puppies on disk
gz

 Download 
Filename  init_deLuxe.gz 
Filesize  13.04 KB 
Downloaded  455 Time(s) 
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 2 [23 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1836s ][ Queries: 13 (0.0181s) ][ GZIP on ]