--- init_org	2013-12-25 23:40:15.000000000 +0100
+++ init	2013-12-26 17:54:07.000000000 +0100
@@ -0,0 +1,178 @@
+#!/bin/sh
+#(c) Copyright Barry Kauler 2010, bkhome.org
+#Lesser GPL license v2 (/usr/share/doc/legal/lgpl-2.1.txt
+#note, 3builddistro (in Woof) renames rootfs-skeleton/sbin/initNEW to init.
+#perform a f.s. check if file /fsckme.flg exits, otherwise normal startup.
+#/etc/rc.d/rc.sysinit creates /fsckme.flg at bootup, rc.shutdown deletes it.
+#this script is /sbin/init in the main Puppy f.s., which is the very first to run.
+#in the case of not a full hd install, this script just passes execution to busybox init.
+#100911 fsckme.err filename changed to fsckme.flg. see also init (initramfs), rc.sysinit, rc.shutdown.
+#101020 no longer have /etc/modprobe.conf.
+#120408 support minit
+#120516 gentoo: libgcc_s.so.1 in wrong place.
+#120627 check ramdisk big enough.
+#120716 revert 120627, /sys not yet loaded. do it a different way. fix for weird 'tr' missing.
+#120716 raspi: no battery-backed hardware clock, so date is wrong, workaround. fixes for rc.sysinit in ramdisk.
+#120717 f.s. maximal mount count reached, perform f.s. check.
+#120718 try force unmount.
+#120729 needed to unmount /old_root/dev, as raspi kernel configured to automount fs on /dev.
+#130203 /bin/probedisk2 now /bin/probedisk only.
+#130418 support kmod (replaces module-init-tools).
+#131207 quirky6: boot param "qfix=fsck", see also rc.sysinit. support f2fs.
+#131217 fixed remounting for non-f2fs.
+#131225 Original quirky-6.0.1 /sbin/init adapted by MHHP for use as /sbin/init in initrd in QUIRKMODE=8.
+
+####################### QUIRKMODE=8 #########################
+# Kernel line boot parameter: qfsimg=home_partition_file_system,home_parttition_device or UUID/path_to/quirky_file_system_image
+# ex.: qfsimg=ext2,/dev/sdb5/quirky-6.0.1/quirky-6.0.1.2fs (home_partition_file_system, can be omitted)
+#        qfsimg=ext2,/dev/UUID="041f7529-1e5d-4217-8185-57337034f8c6"/quirky-6.0.1/quirky-6.0.1.2fs
+#        qfsimg=ext2,/dev/UUID=041f7529-1e5d-4217-8185-57337034f8c6/quirky-6.0.1/quirky-6.0.1.2fs
+#
+#        HOME_PARTITION=sdb5
+#        HOME_FS=ext2
+#        QFS=/quirky-6.0.1/quirky-6.0.1.2fs
+#        QFS_FS=ext2
+#
+# Supported filesystems: ext2|ext3|ext4|f2fs|(reiserfs)
+#
+# rdsh=something drops you out to ramdisk shell (though, cannot continue with chrooting and booting from there ...).
+#
+##########################################################
+
+fsckme_func() {
+  [ ! ${PDEV1} ] && PDEV1="${HOME_PARTITION}"
+  [ ! ${DEV1FS} ] && DEV1FS="${HOME_FS}"
+  ln -s /proc/mounts /etc/mtab #resize2fs,e2fsck need this.
+  umount /mnt/qfs/mnt/$HOME_PARTITION
+  if [ "$CHECK" == "REQ" ];then
+    echo "Performing filesystem check of ${PDEV1}, on request" > /dev/console
+  else
+    if [ "$CHECK" == "MAXIMAL" ];then
+      echo "Performing filesystem check of ${PDEV1}, maximal mount count" > /dev/console
+    else
+      echo "Performing filesystem check of ${PDEV1} after improper shutdown" > /dev/console
+    fi
+  fi
+  echo "fsck messages logged to (/initrd0)/var/QM8_fsck.log"
+  # Do the $HOME_PARTITION fscking here
+  [ "${DEV1FS}" = "f2fs" ] && echo "/sbin/fsck.f2fs /dev/${PDEV1}" > /dev/console && /sbin/fsck.f2fs /dev/${PDEV1} 2>&1 > /var/QM8_fsck.log
+  [ "${DEV1FS/[0-9]/}" = "ext" ] && echo "/sbin/e2fsck -p -f /dev/${PDEV1}" > /dev/console && /sbin/e2fsck -p -f /dev/${PDEV1} 2>&1 > /var/QM8_fsck.log
+  # [ "${DEV1FS}" = "reiserfs" ] && echo "/sbin/reiserfsck|fsck.reiser --fix-fixable -y -f /dev/${PDEV1}" > /dev/console && /sbin/reiserfsck|fsck.reiser --fix-fixable -y -f /dev/${PDEV1} 2>&1 > /var/QM8_fsck.log
+  echo "Filesystem check of HOME_PARTITION ${PDEV1} completed!" > /dev/console
+  # And, of course, there could be some checks of return status ...
+  mount -t $HOME_FS /dev/$HOME_PARTITION /mnt/qfs/mnt/$HOME_PARTITION # Mount again what was previously unmounted ...
+  rm -f /mnt/qfs/mnt/$HOME_PARTITION/fsckme.flg # Remove the fsckme flag
+  # sleep 20
+  # Do the $QFS fscking here
+  if [ "${QFS_FSCK}" != "no" ]; then
+    if [ "$CHECK" == "REQ" ]; then
+      echo "Performing filesystem check of quirky file system image ${QFS}, on request" > /dev/console
+    else
+      if [ "$CHECK" == "MAXIMAL" ]; then
+        echo "Performing filesystem check of quirky file system image ${QFS}, maximal mount count" > /dev/console
+      else
+        echo "Performing filesystem check of quirky file system image ${QFS} after improper shutdown" > /dev/console
+      fi
+    fi
+    LOOPDEV="`losetup -f`"
+    losetup "${LOOPDEV}" /mnt/qfs/mnt/$HOME_PARTITION$QFS
+    [ "${QFS_FS}" = "f2fs" ] && echo "/sbin/fsck.f2fs ${LOOPDEV}" > /dev/console && /sbin/fsck.f2fs ${LOOPDEV} 2>&1 >> /var/QM8_fsck.log
+    [ "${QFS_FS/[0-9]/}" = "ext" ] && echo "/sbin/e2fsck -p -f ${LOOPDEV}" > /dev/console && /sbin/e2fsck -p -f ${LOOPDEV} 2>&1 >> /var/QM8_fsck.log
+    # [ "${QFS_FS}" = "reiserfs" ] && echo "/sbin/reiserfsck|fsck.reiser --fix-fixable -y -f ${LOOPDEV}" > /dev/console && /sbin/reiserfsck|fsck.reiser --fix-fixable -y -f ${LOOPDEV} 2>&1 >> /var/QM8_fsck.log
+    echo "Filesystem check of quirky file system image ${QFS} completed!" > /dev/console
+    losetup -d  "${LOOPDEV}"
+    # And, of course, there could be some checks of return status ...
+    #sleep 20
+  fi
+}
+
+PATH='/bin:/sbin'
+export LANG=C
+
+QFSCK=0
+[ "$qfix" ] && QFIX="$qfix"
+for AFIX in `echo -n "$QFIX" | tr ',' ' '`
+do
+  case $AFIX in
+    fsck|FSCK)  #don't know letters of boot drv (see further down).
+    #   DEV1FS='f2fs' #MARK_DEV1FS_LINE ...leave this symbol here, when do a hd install, can edit this line.
+    QFSCK=1
+    CHECK="REQ"
+    ;;
+  esac
+done
+
+busybox mount -t proc none /proc
+mount -t rootfs -o remount,rw rootfs /
+# ln -s /proc/mounts /etc/mtab #resize2fs,e2fsck need this. ##¤## Linked in fsckme_func.
+mkdir /sys 2>/dev/null
+busybox mount -t sysfs none /sys 
+HOME_PARTITION=${qfsimg#*dev/}
+HOME_PARTITION=${HOME_PARTITION%%/*}
+if [ `echo "${HOME_PARTITION}"|grep -i 'UUID'` ]; then
+  HOME_PARTITION=${HOME_PARTITION#*=}
+  HP=`busybox blkid|grep "${HOME_PARTITION}"`
+  HP=${HP%%:*}
+  HP=${HP#*dev/}
+  qfsimg=${qfsimg/[UuIiDd=]*${HOME_PARTITION}/${HP}}
+  HOME_PARTITION=${HP}
+fi
+[ ! `echo ${qfsimg}|grep ','` ] || HOME_FS=${qfsimg%%,*}
+if [ ! $HOME_FS ]; then
+  HOME_=`busybox blkid|grep ${HOME_PARTITION}`
+  HOME_F=${HOME_##*TYPE=\"}
+  HOME_FS=${HOME_F%\"*}
+fi
+QFS_FS=${qfsimg##*.}
+QFS=${qfsimg#*$HOME_PARTITION}
+[ $QFS_FS == "2fs" ] && QFS_FS=ext2
+[ $QFS_FS == "3fs" ] && QFS_FS=ext3
+[ $QFS_FS == "4fs" ] && QFS_FS=ext4
+[ $QFS_FS == "rfs" ] && QFS_FS=reiserfs
+echo "qfsimg=$qfsimg"
+echo "HOME_PARTITION=$HOME_PARTITION"
+echo "HOME_FS=$HOME_FS"
+echo "QFS=$QFS"
+echo "QFS_FS=$QFS_FS"
+echo "qfsimg=$qfsimg" > /etc/rc.d/QUIRKMODE_8_vars
+echo "HOME_PARTITION=$HOME_PARTITION" >> /etc/rc.d/QUIRKMODE_8_vars
+echo "HOME_FS=$HOME_FS" >> /etc/rc.d/QUIRKMODE_8_vars
+echo "QFS=$QFS" >> /etc/rc.d/QUIRKMODE_8_vars
+echo "QFS_FS=$QFS_FS" >> /etc/rc.d/QUIRKMODE_8_vars
+mkdir -p /mnt/qfs
+mkdir -p /mnt/qfs/mnt/$HOME_PARTITION
+mount -t $HOME_FS /dev/$HOME_PARTITION /mnt/qfs/mnt/$HOME_PARTITION
+
+if [ $QFSCK -eq 0 ]; then
+  if [ -e /mnt/qfs/mnt/$HOME_PARTITION/fsckme.flg ]; then
+    PDEV1="`cat /mnt/qfs/mnt/$HOME_PARTITION/fsckme.flg | cut -f 1 -d ','`" #file format: sda1,ext3,/path_to/quirky_file_system_image
+    DEV1FS="`cat /mnt/qfs/mnt/$HOME_PARTITION/fsckme.flg | cut -f 2 -d ','`"
+    QFS_FSCK="`cat /mnt/qfs/mnt/$HOME_PARTITION/fsckme.flg | cut -f 3 -d ','`"
+    [ "${QFS_FSCK}" != "${QFS}" ] && QFS_FSCK="no" # If the quirky_file_system_image from the fsckme.flg does not correspond to that of the boot parameter, then do not fsck the quirky_file_system_image.
+    CHECK="`cat /mnt/qfs/mnt/$HOME_PARTITION/fsckme.flg | cut -f 4 -d ','`" #120717 see rc.shutdown. MHHP 4 instead of 3.
+    QFSCK=1
+  fi
+fi
+
+[ $QFSCK -eq 1 ] && fsckme_func
+
+[ ! $rdsh ] && echo 'Performing a pivot_root to the quirky file system image...'  >/dev/console
+mount -t $QFS_FS -o loop,rw /mnt/qfs/mnt/$HOME_PARTITION$QFS /mnt/qfs
+##¤##  busybox mount /dev/root -o remount,ro /
+ln -snf ../bin/busybox /sbin/chroot          #must match
+ln -snf ../bin/busybox /mnt/qfs/sbin/chroot #must match
+[ ! -d /mnt/qfs/dev/ ] && mkdir -p /mnt/qfs/dev/
+cd /mnt/qfs
+[ ! -d initrd ] && mkdir initrd
+[ ! -e var ] && [ ! -L var ] && mkdir var
+[ $rdsh ] && echo 'Dropping out to ramdisk shell ...' && exec /bin/sh >/dev/console 2>&1
+busybox umount /proc
+busybox umount /sys
+pivot_root . initrd
+echo 'Performing a chroot to the quirky file system image...'  >/dev/console
+exec chroot . sh -c "exec /bin/busybox init" ## Will do the fscking routine here in initrd, so might as well skip /sbin/init and directly execute /bin/busybox init
+#<dev/console >dev/console 2>&1
+exec /bin/sh >/dev/console 2>&1
+# exit
+###END###
+
