How to create an isolated sysvinit with the script.

Share your own howto's etc. Not for support questions!

How to create an isolated sysvinit with the script.

Postby edbarx » 2014-11-13 10:21

Installing an isolated sysvinit can coexist with systemd. Obviously, booting our concoction boots with init as the parent process of all processes.

Please note the creation of an isolated sysvinit requires one to manually create symbolic links in its rcN.d. It also requires populating its init.d directory with all the necessary scripts/programs, although symbolic links pointing outside our creation, should also be possible to be used. The script takes care of populating dgli/etc/init.d but leaves populating rcN.d for the user.

The Method (you may call it Russian Roulette if you like):
  1. Download and extract the sources for sysvinit for your version of debian. Make sure the debian directory exists and is not empty. Mine is like this:
    Code: Select all
    sysvinit-2.88dsf/debian

    Where sysvinit-2.88dsf is the sources' top directory.
  2. Browse down to sysvinit-2.88dsf/src and open the paths.h file. Edit it or replace it with the following file which is for Jessie. Make sure you edit the same paths I edited.
    Code: Select all
    /*
     * paths.h   Paths of files that init and related utilities need.
     *
     * Version:   @(#) paths.h 2.85-8 05-Nov-2003
     *
     * Author:   Miquel van Smoorenburg, <miquels@cistron.nl>
     *
     *      This file is part of the sysvinit suite,
     *      Copyright (C) 1991-2001 Miquel van Smoorenburg.
     *
     *      This program is free software; you can redistribute it and/or modify
     *      it under the terms of the GNU General Public License as published by
     *      the Free Software Foundation; either version 2 of the License, or
     *      (at your option) any later version.
     *
     *      This program is distributed in the hope that it will be useful,
     *      but WITHOUT ANY WARRANTY; without even the implied warranty of
     *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *      GNU General Public License for more details.
     *
     *      You should have received a copy of the GNU General Public License
     *      along with this program; if not, write to the Free Software
     *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     */
    #define VT_MASTER   "/dev/tty0"      /* Virtual console master */
    #define CONSOLE      "/dev/console"      /* Logical system console */
    #define SECURETTY   "/etc/securetty"   /* List of root terminals */
    #define SDALLOW      "/etc/shutdown.allow"   /* Users allowed to shutdown */
    #define INITTAB      "/dgli/etc/inittab"      /* Location of inittab */
    #define INIT      "/dgli/sbin/init"      /* Location of init itself. */
    #define NOLOGIN      "/run/nologin"      /* Stop user logging in. */
    #define FASTBOOT   "/fastboot"      /* Enable fast boot. */
    #define FORCEFSCK   "/forcefsck"      /* Force fsck on boot */
    #define SDPID      "/var/run/shutdown.pid"   /* PID of shutdown program */
    #define SHELL      "/bin/sh"      /* Default shell */
    #define SULOGIN      "/dgli/sbin/sulogin"      /* Sulogin */
    #define INITSCRIPT   "/dgli/etc/initscript"   /* Initscript. */
    #define PWRSTAT_OLD   "/etc/powerstatus"   /* COMPAT: SIGPWR reason (OK/BAD) */
    #define PWRSTAT      "/var/run/powerstatus"   /* COMPAT: SIGPWR reason (OK/BAD) */

    #if 0
    #define INITLVL      "/etc/initrunlvl"   /* COMPAT: New runlevel */
    #define INITLVL2   "/var/log/initrunlvl"   /* COMPAT: New runlevel */
                /* Note: INITLVL2 definition needs INITLVL */
    #define HALTSCRIPT1   "/etc/init.d/halt"   /* Called by "fast" shutdown */
    #define HALTSCRIPT2   "/etc/rc.d/rc.0"   /* Called by "fast" shutdown */
    #define REBOOTSCRIPT1   "/etc/init.d/reboot"   /* Ditto. */
    #define REBOOTSCRIPT2   "/etc/rc.d/rc.6"   /* Ditto. */
    #endif

  3. cd back to the top source's directory and issue this command to commit your changes.
    Code: Select all
    dpkg-source --commit

    Follow the instructions and give a name to your new patch.
  4. Build the packages as follows:
    Code: Select all
    dpkg-buildpackage

    If the procedure fails, issue this cryptic command:
    Code: Select all
    export  export CFLAGS='-g -O2  -Wformat -Werror=format-security'
  5. Now, you should have these packages created at the parent directory of the sources top directory.
    Code: Select all
    edbarx@edbarx-pc:~/sysv$ ls -l *.deb
    -rw-r--r-- 1 edbarx edbarx  58520 Nov 12 14:32 bootlogd_2.88dsf-57_amd64.deb
    -rw-r--r-- 1 edbarx edbarx  87366 Nov 12 14:32 initscripts_2.88dsf-57_amd64.deb
    -rw-r--r-- 1 edbarx edbarx  99594 Nov 12 14:32 sysvinit_2.88dsf-57_amd64.deb
    -rw-r--r-- 1 edbarx edbarx 131196 Nov 12 14:32 sysvinit-core_2.88dsf-57_amd64.deb
    -rw-r--r-- 1 edbarx edbarx  84082 Nov 12 14:32 sysvinit-utils_2.88dsf-57_amd64.deb
    -rw-r--r-- 1 edbarx edbarx  82942 Nov 12 14:32 sysv-rc_2.88dsf-57_all.deb
  6. Extract their contents into an empty directory named dgli. We will move that directory when we finish. The command is as follows:
    Code: Select all
    dpkg -x bootlogd_2.88dsf-57_amd64.deb dgli

    Do the same for all the other packages.
  7. Populate the dgli/etc/rcN.d with the respective symbolic links. Make sure that the links are not stale.
  8. Copy the following script, save it to a file in the same directory where you have the newly created .deb packages, and make it executable. Check whether there are any daemons you use that are not listed. Please note, that the standard daemons included in sysvinit are NOT listed as EXTRA DAEMONS. Check the script for this step and follow the syntax.
    Code: Select all
    #!/bin/bash

    # Humbly created by edbarx for the cause of choice and software freedom.


    origpath=`pwd`

    function getExtraDaemons()
    {
      for j in \
    #   ENTRA DAEMONS
    #   IF YOU HAVE ANY DAEMONS NOT LISTED HERE, LIST THEM SO THAT THEY WILL BE INCLUDED
        "hdparm" "stop-bootlogd-single" "acpi-support" "procps" "console-setup" \
        "keyboard-setup" "network-manager" "acpi-fakekey" "slim" "arno-iptables-firewall" \
        "kmod" "anacron" "acpid" "bootlogd" "saned" "rpcbind" "x11-common" "rsyslog" \
        "dbus" "bluetooth" "cron" "cgproxy" "cgmanager" "hwclock.sh" "networking" \
        "dev-finish" "privoxy" "alsa-utils" "stop-bootlogd" "pppd-dns" "udev" \
        "kdm" "sudo" "kbd" "openvpn"; do
       
        if [ -f "/etc/init.d/"$j ]; then
          cp -a "/etc/init.d/"$j $1"/"$j
        fi
      done
    }

    function modify_paths()
    {
      resstr=""
      fname=$1
      if [ -d $fname ]; then
        resstr=$(ls -1 $1)
        cd $1
      else
        resstr=$1
      fi
     
      #echo $resstr
      #return 1

      for i in $resstr; do
    # check if $i is the running script (not done) or a directory (done) and skip accordingly
        if [ -d $i ]; then
          continue
        fi

        #cp $i file001
          # path replacement instructions
          sed -i 's|/lib/init/vars.sh|/dgli/lib/init/vars.sh|g' $i
          sed -i 's|/lib/lsb/init-functions|/dgli/lib/lsb/init-functions|g' $i
          sed -i 's|/lib/init/mount-functions.sh|/dgli/lib/init/mount-functions.sh|g' $i
          sed -i 's|/lib/init/swap-functions.sh|/dgli/lib/init/swap-functions.sh|g' $i
          sed -i 's|/lib/init/tmpfs.sh|/dgli/lib/init/tmpfs.sh|g' $i
          sed -i 's|/lib/init/bootclean.sh|/dgli/lib/init/bootclean.sh|g' $i
          sed -i 's|/etc/default/devpts|/dgli/etc/default/devpts|g' $i
          sed -i 's|/etc/default/halt|/dgli/etc/default/halt|g' $i
          sed -i 's|/etc/default/rcS|/dgli/etc/default/rcS|g' $i
          sed -i 's|/etc/default/tmpfs|/dgli/etc/default/tmpfs|g' $i
          sed -i 's|/bin/mountpoint|/dgli/bin/mountpoint|g' $i
          sed -i 's|/bin/pidof|/dgli/bin/pidof|g' $i
          sed -i 's|/usr/bin/last|/dgli/usr/bin/last|g' $i
          sed -i 's|/usr/bin/lastb|/dgli/usr/bin/lastb|g' $i
          sed -i 's|/usr/bin/mesg|/dgli/bin/mesg|g' $i
          sed -i 's|/usr/include/initreq.h|/dgli/usr/include/initreq.h|g' $i
          sed -i 's|/usr/sbin/invoke-rc.d|/dgli/usr/sbin/invoke-rc.d|g' $i
          sed -i 's|/usr/sbin/service|/dgli/usr/sbin/service|g' $i
          sed -i 's|/usr/sbin/update-rc.d|/dgli/usr/sbin/update-rc.d|g' $i
    #     
          sed -i 's|/usr/share/lintian/overrides/bootlogd|/dgli/usr/share/lintian/overrides/bootlogd|g' $i
          sed -i 's|/usr/share/lintian/overrides/initscripts|/dgli/usr/share/lintian/overrides/initscripts|g' $i
          sed -i 's|/usr/share/lintian/overrides/sysvinit-core|/dgli/usr/share/lintian/overrides/sysvinit-core|g' $i
          sed -i 's|/usr/share/lintian/overrides/sysv-rc|/dgli/usr/share/lintian/overrides/sysv-rc|g' $i
          sed -i 's|/usr/share/sysvinit/inittab|/dgli/usr/share/sysvinit/inittab|g' $i
          sed -i 's|/usr/share/sysvinit/update-rc.d|/dgli/usr/share/sysvinit/update-rc.d|g' $i
          sed -i 's|/usr/share/sysv-rc/saveconfig|/dgli/usr/share/sysv-rc/saveconfig|g' $i
    #     
          sed -i 's|/lib/init/init-d-script|/dgli/lib/init/init-d-script|g' $i
          sed -i 's|/lib/sysvinit/init|/dgli/lib/sysvinit/init|g' $i
          sed -i 's|/lib/sysvinit/telinit|/dgli/lib/sysvinit/telinit|g' $i
          sed -i 's|/network/if-up.d/mountnfs|/dgli/network/if-up.d/mountnfs|g' $i
          sed -i 's|/sbin/bootlogd|/dgli/sbin/bootlogd|g' $i
          sed -i 's|/sbin/fsck.nfs|/dgli/sbin/fsck.nfs|g' $i
          sed -i 's|/sbin/fstab-decode|/dgli/sbin/fstab-decode|g' $i
          sed -i 's|/sbin/halt|/dgli/sbin/halt|g' $i
          sed -i 's|/sbin/init|/dgli/sbin/init|g' $i
          sed -i 's|/sbin/killall5|/dgli/sbin/killall5|g' $i
          sed -i 's|/sbin/poweroff|/dgli/sbin/poweroff|g' $i
          sed -i 's|/sbin/reboot/|/dgli/sbin/reboot|g' $i
          sed -i 's|/sbin/runlevel|/dgli/sbin/runlevel|g' $i
          sed -i 's|/sbin/shutdown|/dgli/sbin/shutdown|g' $i
          sed -i 's|/sbin/sulogin|/dgli/sbin/sulogin|g' $i
          sed -i 's|/sbin/telinit|/dgli/sbin/telinit|g' $i
          sed -i 's|/etc/inittab|/dgli/etc/inittab|g' $i
     #     
          sed -i 's|/etc/init.d|/dgli/etc/init.d|g' $i
          sed -i 's|/etc/default/rc|/dgli/etc/default/rc|g' $i
          sed -i 's|/etc/rc|/dgli/etc/rc|g' $i     
        #file001 > file002; cp file002 $i;
        echo $i
        echo $i": processed"
      done

      #rm file001 file002  ENABLE this line GAHAN
      cd $origpath
    }


    if [ -f $1"/scriptsmodified" ]; then
      echo "Protective Failure: running this script more than once will insert '\dgli' the corresponding number of times."
      exit 1
    fi

    touch $1"/scriptsmodified"
    echo "Created scriptsmodified in ./dgli to block multiple runs."
    echo "If everything works, you can delete scriptsmodified"

    cp -a $1"/usr/share/sysvinit/inittab" $1"/"etc/inittab"

    spath="etc/init.d"
    getExtraDaemons $1"/"$spath

    initd="etc/init.d"
    modify_paths $1"/"$initd
    rm $1"/bin/pidof"
    ln --symbolic /dgli/sbin/killall5 $1"/bin/pidof"

    spath="etc/inittab"
    modify_paths $1"/"$spath

    spath="etc/network/if-up.d"
    modify_paths $1"/"$spath

    spath="lib/init"
    modify_paths $1"/"$spath

    spath="sbin/fsck.nfs"
    modify_paths $1"/"$spath

    spath="usr/sbin"
    modify_paths $1"/"$spath

    spath="usr/share/lintian"
    modify_paths $1"/"$spath

    spath="usr/share/sysvinit"
    modify_paths $1"/"$spath

    spath="usr/share/sysv-rc"
    modify_paths $1"/"$spath

    mkdir $1"/lib/lsb"
    mkdir $1"/lib/lsb/init-functions.d"

    if [ -f "/lib/lsb/init-functions.d/20-left-info-blocks" ]; then
      cp -a "/lib/lsb/init-functions.d/20-left-info-blocks"  $1"/lib/lsb/init-functions.d/20-left-info-blocks"
    fi

    if [ -f "/lib/lsb/init-functions" ]; then
      cp -a "/lib/lsb/init-functions"  $1"/lib/lsb/init-functions"
    fi

    exit 0
  9. Run the script as follows with root power:
    Code: Select all
    ./link-updater.sh ./dgli

    You will get an output like this:
    Code: Select all
    Created scriptsmodified in the current directory to block multiple runs.
    If everything works, you can delete scriptsmodified
    acpid
    acpid: processed
    acpi-fakekey
    acpi-fakekey: processed
    acpi-support
    acpi-support: processed
    alsa-utils
    alsa-utils: processed
    anacron
    anacron: processed
    arno-iptables-firewall
    arno-iptables-firewall: processed
    bluetooth
    bluetooth: processed
    bootlogd
    bootlogd: processed
    bootlogs
    bootlogs: processed
    bootmisc.sh
    bootmisc.sh: processed
    cgmanager
    cgmanager: processed
    cgproxy
    cgproxy: processed
    checkfs.sh
    checkfs.sh: processed
    checkroot-bootclean.sh
    checkroot-bootclean.sh: processed
    checkroot.sh
    checkroot.sh: processed
    console-setup
    console-setup: processed
    cron
    cron: processed
    dbus
    dbus: processed
    halt
    halt: processed
    hdparm
    hdparm: processed
    hostname.sh
    hostname.sh: processed
    hwclock.sh
    hwclock.sh: processed
    kbd
    kbd: processed
    kdm
    kdm: processed
    keyboard-setup
    keyboard-setup: processed
    killprocs
    killprocs: processed
    kmod
    kmod: processed
    motd
    motd: processed
    mountall-bootclean.sh
    mountall-bootclean.sh: processed
    mountall.sh
    mountall.sh: processed
    mountdevsubfs.sh
    mountdevsubfs.sh: processed
    mountkernfs.sh
    mountkernfs.sh: processed
    mountnfs-bootclean.sh
    mountnfs-bootclean.sh: processed
    mountnfs.sh
    mountnfs.sh: processed
    networking
    networking: processed
    network-manager
    network-manager: processed
    openvpn
    openvpn: processed
    pppd-dns
    pppd-dns: processed
    privoxy
    privoxy: processed
    procps
    procps: processed
    rc
    rc: processed
    rc.local
    rc.local: processed
    rcS
    rcS: processed
    README
    README: processed
    reboot
    reboot: processed
    rmnologin
    rmnologin: processed
    rpcbind
    rpcbind: processed
    rsyslog
    rsyslog: processed
    saned
    saned: processed
    sendsigs
    sendsigs: processed
    single
    single: processed
    skeleton
    skeleton: processed
    slim
    slim: processed
    stop-bootlogd
    stop-bootlogd: processed
    stop-bootlogd-single
    stop-bootlogd-single: processed
    sudo
    sudo: processed
    udev
    udev: processed
    umountfs
    umountfs: processed
    umountnfs.sh
    umountnfs.sh: processed
    umountroot
    umountroot: processed
    urandom
    urandom: processed
    x11-common
    x11-common: processed
    ./dgli/etc/inittab
    ./dgli/etc/inittab: processed
    mountnfs
    mountnfs: processed
    bootclean.sh
    bootclean.sh: processed
    init-d-script
    init-d-script: processed
    mount-functions.sh
    mount-functions.sh: processed
    swap-functions.sh
    swap-functions.sh: processed
    tmpfs.sh
    tmpfs.sh: processed
    vars.sh
    vars.sh: processed
    ./dgli/sbin/fsck.nfs
    ./dgli/sbin/fsck.nfs: processed
    invoke-rc.d
    invoke-rc.d: processed
    service
    service: processed
    update-rc.d
    update-rc.d: processed
    inittab
    inittab: processed
    update-rc.d
    update-rc.d: processed
    saveconfig
    saveconfig: processed
  10. Move dgli to /
  11. Reboot and pass:
    Code: Select all
    init=/dgli/sbin/init

    to the kernel line in GRUB.



=========================================================
Stop here: the following describes how to manually do what the
script does.
=========================================================


The rest of this post is kept only for historical reasons.
  1. Populate the dgli/etc/init.d with all the necessary scripts and programs.
    Mine are as follows (for SID):
    Code: Select all
    root@edbarx-pc:/mnt/sda5/dgli/etc# ls -l init.d
    total 172
    -rwxr-xr-x 1 root root 2327 Nov 10 00:15 bootlogd
    -rwxr-xr-x 1 root root 1281 Nov 10 00:12 bootlogs
    -rwxr-xr-x 1 root root 1253 Nov 10 00:11 bootmisc.sh
    -rwxr-xr-x 1 root root 3827 Nov 10 00:09 checkfs.sh
    -rwxr-xr-x 1 root root 1077 Nov 10 00:06 checkroot-bootclean.sh
    -rwxr-xr-x 1 root root 9315 Nov 10 00:04 checkroot.sh
    -rwxr-xr-x 1 root root 1361 Nov  9 23:59 halt
    -rwxr-xr-x 1 root root 1433 Nov  9 23:56 hostname.sh
    -rwxr-xr-x 1 root root 3931 Nov 10 15:30 hwclock.sh
    -rwxr-xr-x 1 root root 1606 Nov 10 15:32 keyboard-setup
    -rwxr-xr-x 1 root root 1305 Nov  9 23:55 killprocs
    -rwxr-xr-x 1 root root 2005 Nov 10 15:35 kmod
    -rwxr-xr-x 1 root root 1000 Nov 10 13:35 motd
    -rwxr-xr-x 1 root root  682 Nov  9 23:29 mountall-bootclean.sh
    -rwxr-xr-x 1 root root 2173 Nov  9 23:41 mountall.sh
    -rwxr-xr-x 1 root root 1491 Nov 10 13:15 mountdevsubfs.sh
    -rwxr-xr-x 1 root root 1584 Nov  9 23:47 mountkernfs.sh
    -rwxr-xr-x 1 root root  690 Nov  9 23:48 mountnfs-bootclean.sh
    -rwxr-xr-x 1 root root 2471 Nov  9 23:53 mountnfs.sh
    -rwxr-xr-x 1 root root 4452 Nov 10 15:40 networking
    -rwxr-xr-x 1 root root 1212 Nov 10 15:41 procps
    -rwxr-xr-x 1 root root 6338 Nov 10 08:12 rc
    -rwxr-xr-x 1 root root  845 Nov 10 08:08 rc.local
    -rwxr-xr-x 1 root root  127 Nov  9 22:14 rcS
    -rw-r--r-- 1 root root 2427 Jan 27  2014 README
    -rwxr-xr-x 1 root root  666 Nov 10 08:07 reboot
    -rwxr-xr-x 1 root root 1047 Nov 10 08:06 rmnologin
    -rwxr-xr-x 1 root root 3212 Nov 10 08:04 sendsigs
    -rwxr-xr-x 1 root root  613 Nov 10 07:58 single
    -rw-r--r-- 1 root root 1087 Mar 27  2014 skeleton
    -rwxr-xr-x 1 root root  582 Nov 10 07:56 stop-bootlogd
    -rwxr-xr-x 1 root root 1178 Nov  9 23:15 stop-bootlogd-single
    -rwxr-xr-x 1 root root 6582 Nov 10 15:47 udev
    -rwxr-xr-x 1 root root  466 Nov 10 15:49 udev-finish
    -rwxr-xr-x 1 root root 2747 Nov 10 07:53 umountfs
    -rwxr-xr-x 1 root root 2207 Nov 10 07:52 umountnfs.sh
    -rwxr-xr-x 1 root root 1139 Nov 10 07:49 umountroot
    -rwxr-xr-x 1 root root 3121 Nov 10 07:48 urandom

  2. Create inittab. Place it in dgli/etc. The following is mine. This is for SID. Edit where inappropriate. Note the trivial changes that we made:
    Code: Select all
    # /dgli/etc/inittab: init(8) configuration.
    # $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $

    # The default runlevel.
    id:2:initdefault:

    # Boot-time system configuration/initialization script.
    # This is run first except when booting in emergency (-b) mode.
    si::sysinit:/dgli/etc/init.d/rcS

    # What to do in single-user mode.
    ~~:S:wait:/dgli/sbin/sulogin

    # /dgli/etc/init.d executes the S and K scripts upon change
    # of runlevel.
    #
    # Runlevel 0 is halt.
    # Runlevel 1 is single-user.
    # Runlevels 2-5 are multi-user.
    # Runlevel 6 is reboot.

    l0:0:wait:/dgli/etc/init.d/rc 0
    l1:1:wait:/dgli/etc/init.d/rc 1
    l2:2:wait:/dgli/etc/init.d/rc 2
    l3:3:wait:/dgli/etc/init.d/rc 3
    l4:4:wait:/dgli/etc/init.d/rc 4
    l5:5:wait:/dgli/etc/init.d/rc 5
    l6:6:wait:/dgli/etc/init.d/rc 6
    # Normally not reached, but fallthrough in case of emergency.
    z6:6:respawn:/dgli/sbin/sulogin

    # What to do when CTRL-ALT-DEL is pressed.
    ca:12345:ctrlaltdel:/dgli/sbin/shutdown -t1 -a -r now

    # Action on special keypress (ALT-UpArrow).
    #kb::kbrequest:/bin/echo "Keyboard Request--edit /dgli/etc/inittab to let this work."

    # What to do when the power fails/returns.
    pf::powerwait:/dgli/etc/init.d/powerfail start
    pn::powerfailnow:/dgli/etc/init.d/powerfail now
    po::powerokwait:/dgli/etc/init.d/powerfail stop

    # /sbin/getty invocations for the runlevels.
    #
    # The "id" field MUST be the same as the last
    # characters of the device (after "tty").
    #
    # Format:
    #  <id>:<runlevels>:<action>:<process>
    #
    # Note that on most Debian systems tty7 is used by the X Window System,
    # so if you want to add more getty's go ahead but skip tty7 if you run X.
    #
    1:2345:respawn:/sbin/getty 38400 tty1
    2:23:respawn:/sbin/getty 38400 tty2
    3:23:respawn:/sbin/getty 38400 tty3
    4:23:respawn:/sbin/getty 38400 tty4
    5:23:respawn:/sbin/getty 38400 tty5
    6:23:respawn:/sbin/getty 38400 tty6

    # Example how to put a getty on a serial line (for a terminal)
    #
    #T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
    #T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

    # Example how to put a getty on a modem line.
    #
    #T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3
  3. Edit the scripts in dgli/etc/init.d. Paths must agree with what we did in paths.h they must also be such as to call the appropriate scripts/programs now moved to the tree rooted at dgli.
  4. Inspect dgli directory tree for any broken symbolic links. I found only one at:
    Code: Select all
    dgli/bin

    The link is:
    Code: Select all
    pidof -> /sbin/killall5

    which is bad as we are now in dgli. The correct link is as follows:
    Code: Select all
    pidof -> /dgli/sbin/killall5
  5. The completed tree is (for SID):
    Code: Select all
    dgli
    ├── bin
    │   ├── mountpoint
    │   └── pidof -> /dgli/sbin/killall5
    ├── etc
    │   ├── default
    │   │   ├── devpts
    │   │   ├── halt
    │   │   ├── rcS
    │   │   └── tmpfs
    │   ├── init.d
    │   │   ├── bootlogd
    │   │   ├── bootlogs
    │   │   ├── bootmisc.sh
    │   │   ├── checkfs.sh
    │   │   ├── checkroot-bootclean.sh
    │   │   ├── checkroot.sh
    │   │   ├── halt
    │   │   ├── hostname.sh
    │   │   ├── hwclock.sh
    │   │   ├── keyboard-setup
    │   │   ├── killprocs
    │   │   ├── kmod
    │   │   ├── motd
    │   │   ├── mountall-bootclean.sh
    │   │   ├── mountall.sh
    │   │   ├── mountdevsubfs.sh
    │   │   ├── mountkernfs.sh
    │   │   ├── mountnfs-bootclean.sh
    │   │   ├── mountnfs.sh
    │   │   ├── networking
    │   │   ├── procps
    │   │   ├── rc
    │   │   ├── rc.local
    │   │   ├── rcS
    │   │   ├── README
    │   │   ├── reboot
    │   │   ├── rmnologin
    │   │   ├── sendsigs
    │   │   ├── single
    │   │   ├── skeleton
    │   │   ├── stop-bootlogd
    │   │   ├── stop-bootlogd-single
    │   │   ├── udev
    │   │   ├── udev-finish
    │   │   ├── umountfs
    │   │   ├── umountnfs.sh
    │   │   ├── umountroot
    │   │   └── urandom
    │   ├── inittab
    │   ├── network
    │   │   └── if-up.d
    │   │       └── mountnfs
    │   ├── rc0.d
    │   │   ├── K01saned -> ../init.d/saned
    │   │   ├── K01urandom -> ../init.d/urandom
    │   │   ├── K02sendsigs -> ../init.d/sendsigs
    │   │   ├── K03rsyslog -> ../init.d/rsyslog
    │   │   ├── K04hwclock.sh -> ../init.d/hwclock.sh
    │   │   ├── K04umountnfs.sh -> ../init.d/umountnfs.sh
    │   │   ├── K05networking -> ../init.d/networking
    │   │   ├── K06umountfs -> ../init.d/umountfs
    │   │   ├── K07umountroot -> ../init.d/umountroot
    │   │   ├── K08halt -> ../init.d/halt
    │   │   └── README
    │   ├── rc1.d
    │   │   ├── K01saned -> ../init.d/saned
    │   │   ├── K03rsyslog -> ../init.d/rsyslog
    │   │   ├── README
    │   │   ├── S01killprocs -> ../init.d/killprocs
    │   │   ├── S01motd -> ../init.d/motd
    │   │   ├── S03bootlogs -> ../init.d/bootlogs
    │   │   └── S04single -> ../init.d/single
    │   ├── rc2.d
    │   │   ├── README
    │   │   ├── S01motd -> ../init.d/motd
    │   │   ├── S01rsyslog -> ../init.d/rsyslog
    │   │   ├── S02acpid -> ../init.d/acpid
    │   │   ├── S02cron -> ../init.d/cron
    │   │   ├── S02dbus -> ../init.d/dbus
    │   │   ├── S03bootlogs -> ../init.d/bootlogs
    │   │   ├── S03saned -> ../init.d/saned
    │   │   ├── S04rc.local -> ../init.d/rc.local
    │   │   └── S04rmnologin -> ../init.d/rmnologin
    │   ├── rc3.d
    │   │   ├── README
    │   │   ├── S01motd -> ../init.d/motd
    │   │   ├── S01rsyslog -> ../init.d/rsyslog
    │   │   ├── S02acpid -> ../init.d/acpid
    │   │   ├── S02cron -> ../init.d/cron
    │   │   ├── S02dbus -> ../init.d/dbus
    │   │   ├── S03bootlogs -> ../init.d/bootlogs
    │   │   ├── S03saned -> ../init.d/saned
    │   │   ├── S04rc.local -> ../init.d/rc.local
    │   │   └── S04rmnologin -> ../init.d/rmnologin
    │   ├── rc4.d
    │   │   ├── README
    │   │   ├── S01motd -> ../init.d/motd
    │   │   ├── S01rsyslog -> ../init.d/rsyslog
    │   │   ├── S02acpid -> ../init.d/acpid
    │   │   ├── S02cron -> ../init.d/cron
    │   │   ├── S02dbus -> ../init.d/dbus
    │   │   ├── S03bootlogs -> ../init.d/bootlogs
    │   │   ├── S03saned -> ../init.d/saned
    │   │   ├── S04rc.local -> ../init.d/rc.local
    │   │   └── S04rmnologin -> ../init.d/rmnologin
    │   ├── rc5.d
    │   │   ├── README
    │   │   ├── S01motd -> ../init.d/motd
    │   │   ├── S01rsyslog -> ../init.d/rsyslog
    │   │   ├── S02acpid -> ../init.d/acpid
    │   │   ├── S02cron -> ../init.d/cron
    │   │   ├── S02dbus -> ../init.d/dbus
    │   │   ├── S03bootlogs -> ../init.d/bootlogs
    │   │   ├── S03saned -> ../init.d/saned
    │   │   ├── S04rc.local -> ../init.d/rc.local
    │   │   └── S04rmnologin -> ../init.d/rmnologin
    │   ├── rc6.d
    │   │   ├── K01saned -> ../init.d/saned
    │   │   ├── K01urandom -> ../init.d/urandom
    │   │   ├── K02sendsigs -> ../init.d/sendsigs
    │   │   ├── K03rsyslog -> ../init.d/rsyslog
    │   │   ├── K04hwclock.sh -> ../init.d/hwclock.sh
    │   │   ├── K04umountnfs.sh -> ../init.d/umountnfs.sh
    │   │   ├── K05networking -> ../init.d/networking
    │   │   ├── K06umountfs -> ../init.d/umountfs
    │   │   ├── K07umountroot -> ../init.d/umountroot
    │   │   ├── K08reboot -> ../init.d/reboot
    │   │   └── README
    │   └── rcS.d
    │       ├── README
    │       ├── S01hostname.sh -> ../init.d/hostname.sh
    │       ├── S01mountkernfs.sh -> ../init.d/mountkernfs.sh
    │       ├── S02udev -> ../init.d/udev
    │       ├── S03keyboard-setup -> ../init.d/keyboard-setup
    │       ├── S04mountdevsubfs.sh -> ../init.d/mountdevsubfs.sh
    │       ├── S05hwclock.sh -> ../init.d/hwclock.sh
    │       ├── S06checkroot.sh -> ../init.d/checkroot.sh
    │       ├── S07checkfs.sh -> ../init.d/checkfs.sh
    │       ├── S08checkroot-bootclean.sh -> ../init.d/checkroot-bootclean.sh
    │       ├── S08kmod -> ../init.d/kmod
    │       ├── S09mountall.sh -> ../init.d/mountall.sh
    │       ├── S10mountall-bootclean.sh -> ../init.d/mountall-bootclean.sh
    │       ├── S11procps -> ../init.d/procps
    │       ├── S11udev-finish -> ../init.d/udev-finish
    │       ├── S11urandom -> ../init.d/urandom
    │       ├── S12networking -> ../init.d/networking
    │       ├── S13mountnfs.sh -> ../init.d/mountnfs.sh
    │       ├── S14mountnfs-bootclean.sh -> ../init.d/mountnfs-bootclean.sh
    │       ├── S15kbd -> ../init.d/kbd
    │       ├── S16console-setup -> ../init.d/console-setup
    │       ├── S17bootmisc.sh -> ../init.d/bootmisc.sh
    │       └── S17x11-common -> ../init.d/x11-common
    ├── lib
    │   ├── init
    │   │   ├── bootclean.sh
    │   │   ├── init-d-script
    │   │   ├── mount-functions.sh
    │   │   ├── swap-functions.sh
    │   │   ├── tmpfs.sh
    │   │   └── vars.sh
    │   ├── lsb
    │   │   ├── init-functions
    │   │   └── init-functions.d
    │   │       └── 20-left-info-blocks
    │   └── sysvinit
    │       ├── init
    │       └── telinit -> init
    ├── run
    ├── sbin
    │   ├── bootlogd
    │   ├── fsck.nfs
    │   ├── fstab-decode
    │   ├── halt
    │   ├── init
    │   ├── killall5
    │   ├── poweroff -> halt
    │   ├── reboot -> halt
    │   ├── runlevel
    │   ├── shutdown
    │   ├── sulogin
    │   └── telinit -> init
    ├── sys
    ├── usr
    │   ├── bin
    │   │   ├── last
    │   │   ├── lastb -> last
    │   │   └── mesg
    │   ├── include
    │   │   └── initreq.h
    │   ├── sbin
    │   │   ├── invoke-rc.d
    │   │   ├── service
    │   │   └── update-rc.d
    │   └── share
    │       ├── doc
    │       │   ├── bootlogd
    │       │   │   ├── changelog.Debian.gz
    │       │   │   ├── changelog.gz
    │       │   │   └── copyright
    │       │   ├── initscripts
    │       │   │   ├── changelog.Debian.gz
    │       │   │   ├── changelog.gz
    │       │   │   ├── copyright
    │       │   │   ├── NEWS.Debian.gz
    │       │   │   └── README.Debian
    │       │   ├── sysvinit
    │       │   │   ├── changelog.Debian.gz
    │       │   │   ├── changelog.gz
    │       │   │   ├── copyright
    │       │   │   └── NEWS.Debian.gz
    │       │   ├── sysvinit-core
    │       │   │   ├── changelog.Debian.gz
    │       │   │   ├── changelog.gz
    │       │   │   └── copyright
    │       │   ├── sysvinit-utils
    │       │   │   ├── changelog.Debian.gz
    │       │   │   ├── changelog.gz
    │       │   │   ├── copyright
    │       │   │   └── NEWS.Debian.gz
    │       │   └── sysv-rc
    │       │       ├── changelog.Debian.gz
    │       │       ├── changelog.gz
    │       │       ├── copyright
    │       │       ├── NEWS.Debian.gz
    │       │       ├── README.Debian
    │       │       ├── README.invoke-rc.d.gz
    │       │       ├── README.policy-rc.d.gz
    │       │       └── README.runlevels.gz
    │       ├── lintian
    │       │   └── overrides
    │       │       ├── bootlogd
    │       │       ├── initscripts
    │       │       ├── sysvinit-core
    │       │       └── sysv-rc
    │       ├── man
    │       │   ├── man1
    │       │   │   ├── last.1.gz
    │       │   │   ├── lastb.1.gz -> last.1.gz
    │       │   │   ├── mesg.1.gz
    │       │   │   └── mountpoint.1.gz
    │       │   ├── man5
    │       │   │   ├── halt.5.gz
    │       │   │   ├── init-d-script.5.gz
    │       │   │   ├── initscript.5.gz
    │       │   │   ├── inittab.5.gz
    │       │   │   ├── rcS.5.gz
    │       │   │   └── tmpfs.5.gz
    │       │   └── man8
    │       │       ├── bootlogd.8.gz
    │       │       ├── fsck.nfs.8.gz
    │       │       ├── fstab-decode.8.gz
    │       │       ├── halt.8.gz
    │       │       ├── init.8.gz
    │       │       ├── invoke-rc.d.8.gz
    │       │       ├── killall5.8.gz
    │       │       ├── pidof.8.gz
    │       │       ├── poweroff.8.gz -> halt.8.gz
    │       │       ├── reboot.8.gz -> halt.8.gz
    │       │       ├── runlevel.8.gz
    │       │       ├── service.8.gz
    │       │       ├── shutdown.8.gz
    │       │       ├── sulogin.8.gz
    │       │       ├── telinit.8.gz -> init.8.gz
    │       │       └── update-rc.d.8.gz
    │       ├── sysvinit
    │       │   ├── inittab
    │       │   └── update-rc.d
    │       └── sysv-rc
    │           └── saveconfig
    └── var
        ├── lib
        │   ├── initscripts
        │   ├── insserv
        │   └── urandom
        └── log
            └── fsck


    You can now understand why I called it a micro-system, or pejoratively, a rootkit.
  6. Move dgli to the root directory.
  7. At the GRUB screen, press 'e' to enter edit mode. Move down to the kernel line and insert the parameter:
    [code]init=/dgli/sbin/init
  8. If everthing is correct, which usually never is for complex hacks, you should be able to boot.

I am thinking about making these changes into a final binary package, but in the true spirit of open source and freedom, I also gave and will give all the necessary details regarding this hack.

If the forum software allows me, I will also upload the contents of the modified scripts/programs in dgli/etc/init.d.

If you are uncomfortable having something as complex as this installed, without the package management system's knowledge, you can build a package using dpkg -b, but you have to supply a control file, obviously, with correct entries. The other hack, regarding providing an empty package for systemd, can be improved, and that is exactly what I want to achieve, by including a dependency requiring our micro-system, let us call it, born-again-sysv.

I intend to produce these two packages to help those who want to continue using Debian when it decides systemd to become mandatory. Till now, there is no need of these complex hacks, but we have to be prepared for any eventuality.

May the spirit of reciprocal help, promote the cause of free and open source to all.
Attachments
init-microsystem-modified-source.tar.gz
(27.82 KiB) Downloaded 125 times
Last edited by edbarx on 2014-11-18 13:49, edited 9 times in total.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5389
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: How to create an insolated sysvinit.

Postby golinux » 2014-11-13 17:15

WOW! Just WOW!
May the FORK be with you!
User avatar
golinux
 
Posts: 1256
Joined: 2010-12-09 00:56
Location: not a 'buntard!

Re: How to create an insolated sysvinit.

Postby fleabus » 2014-11-14 00:26

You go edbarx! More power to you. :D
User avatar
fleabus
 
Posts: 98
Joined: 2013-08-28 18:36
Location: Winchester, VA, USA

Re: How to create an isolated sysvinit.

Postby edbarx » 2014-11-15 12:50

Note: I am in the process of debugging the script. Till now, the features I tested, work, obviously after correcting some errors.

This is the almost completed shell script to be used to modify the init.d and other shell scripts in my isolated sysvinit. It has to be run in the dgli directory.

This is still in the process of writing. Please, do not use.
Code: Select all
#!/bin/bash

origpath=`pwd`


function modify_paths()
{
  resstr=""
  fname=$1
  if [ -d $fname ]; then
    resstr=$(ls -1 $1)
    cd $1
  else
    resstr=$1
  fi
 
  #echo $resstr
  #return 1

  for i in $resstr; do
# check if $i is the running script (not done) or a directory (done) and skip accordingly 
    if [ -d $i ]; then
      continue
    fi

    #cp $i file001
      # path replacement instructions
      sed -i 's|/lib/init/vars.sh|/dgli/lib/init/vars.sh|g' $i
      sed -i 's|/lib/lsb/init-functions|/dgli/lib/lsb/init-functions|g' $i
      sed -i 's|/lib/init/mount-functions.sh|/dgli/lib/init/mount-functions.sh|g' $i
      sed -i 's|/lib/init/swap-functions.sh|/dgli/lib/init/swap-functions.sh|g' $i
      sed -i 's|/lib/init/tmpfs.sh|/dgli/lib/init/tmpfs.sh|g' $i
      sed -i 's|/lib/init/bootclean.sh|/dgli/lib/init/bootclean.sh|g' $i
      sed -i 's|/etc/default/devpts|/dgli/etc/default/devpts|g' $i
      sed -i 's|/etc/default/halt|/dgli/etc/default/halt|g' $i
      sed -i 's|/etc/default/rcS|/dgli/etc/default/rcS|g' $i
      sed -i 's|/etc/default/tmpfs|/dgli/etc/default/tmpfs|g' $i
      sed -i 's|/bin/mountpoint|/dgli/bin/mountpoint|g' $i
      sed -i 's|/bin/pidof|/dgli/bin/pidof|g' $i
      sed -i 's|/usr/bin/last|/dgli/usr/bin/last|g' $i
      sed -i 's|/usr/bin/lastb|/dgli/usr/bin/lastb|g' $i
      sed -i 's|/usr/bin/mesg|/dgli/bin/mesg|g' $i
      sed -i 's|/usr/include/initreq.h|/dgli/usr/include/initreq.h|g' $i
      sed -i 's|/usr/sbin/invoke-rc.d|/dgli/usr/sbin/invoke-rc.d|g' $i
      sed -i 's|/usr/sbin/service|/dgli/usr/sbin/service|g' $i
      sed -i 's|/usr/sbin/update-rc.d|/dgli/usr/sbin/update-rc.d|g' $i
#     
      sed -i 's|/usr/share/lintian/overrides/bootlogd|/dgli/usr/share/lintian/overrides/bootlogd|g' $i
      sed -i 's|/usr/share/lintian/overrides/initscripts|/dgli/usr/share/lintian/overrides/initscripts|g' $i
      sed -i 's|/usr/share/lintian/overrides/sysvinit-core|/dgli/usr/share/lintian/overrides/sysvinit-core|g' $i
      sed -i 's|/usr/share/lintian/overrides/sysv-rc|/dgli/usr/share/lintian/overrides/sysv-rc|g' $i
      sed -i 's|/usr/share/sysvinit/inittab|/dgli/usr/share/sysvinit/inittab|g' $i
      sed -i 's|/usr/share/sysvinit/update-rc.d|/dgli/usr/share/sysvinit/update-rc.d|g' $i
      sed -i 's|/usr/share/sysv-rc/saveconfig|/dgli/usr/share/sysv-rc/saveconfig|g' $i
#     
      sed -i 's|/lib/init/init-d-script|/dgli/lib/init/init-d-script|g' $i
      sed -i 's|/lib/sysvinit/init|/dgli/lib/sysvinit/init|g' $i
      sed -i 's|/lib/sysvinit/telinit|/dgli/lib/sysvinit/telinit|g' $i
      sed -i 's|/network/if-up.d/mountnfs|/dgli/network/if-up.d/mountnfs|g' $i
      sed -i 's|/sbin/bootlogd|/dgli/sbin/bootlogd|g' $i
      sed -i 's|/sbin/fsck.nfs|/dgli/sbin/fsck.nfs|g' $i
      sed -i 's|/sbin/fstab-decode|/dgli/sbin/fstab-decode|g' $i
      sed -i 's|/sbin/halt|/dgli/sbin/halt|g' $i
      sed -i 's|/sbin/init|/dgli/sbin/init|g' $i
      sed -i 's|/sbin/killall5|/dgli/sbin/killall5|g' $i
      sed -i 's|/sbin/poweroff|/dgli/sbin/poweroff|g' $i
      sed -i 's|/sbin/reboot/|/dgli/sbin/reboot|g' $i
      sed -i 's|/sbin/runlevel|/dgli/sbin/runlevel|g' $i
      sed -i 's|/sbin/shutdown|/dgli/sbin/shutdown|g' $i
      sed -i 's|/sbin/sulogin|/dgli/sbin/sulogin|g' $i
      sed -i 's|/sbin/telinit|/dgli/sbin/telinit|g' $i
      sed -i 's|/etc/inittab|/dgli/etc/inittab|g' $i 
 #     
      sed -i 's|/etc/init.d|/dgli/etc/init.d|g' $i
      sed -i 's|/etc/default/rc|/dgli/etc/default/rc|g' $i
      sed -i 's|/etc/rc|/dgli/etc/rc|g' $i     
    #file001 > file002; cp file002 $i;
    echo $i
    echo $i": processed"
  done

  #rm file001 file002  ENABLE this line GAHAN
  cd $origpath
}


if [ -f $1"/scriptsmodified" ]; then
  echo "Protective Failure: running this script more than once will insert '\dgli' the corresponding number of times."
  exit 1
fi

touch $1"/scriptsmodified"
echo "Created scriptsmodified in the current directory to block multiple runs."
echo "If everything works, you can delete scriptsmodified"


initd="etc/init.d" 
modify_paths $1"/"$initd
rm $1"/bin/pidof"
ln --symbolic /dgli/sbin/killall5 $1"/bin/pidof"

spath="etc/inittab"
modify_paths $1"/"$spath

spath="etc/network/if-up.d"
modify_paths $1"/"$spath

spath="lib/init"
modify_paths $1"/"$spath

spath="sbin/fsck.nfs"
modify_paths $1"/"$spath

spath="usr/sbin"
modify_paths $1"/"$spath

spath="usr/share/lintian"
modify_paths $1"/"$spath

spath="usr/share/sysvinit"
modify_paths $1"/"$spath

spath="usr/share/sysv-rc"
modify_paths $1"/"$spath

mkdir $1"/lib/lsb"
mkdir $1"/lib/lsb/init-functions.d"

exit 0
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5389
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Testing the script:

Postby edbarx » 2014-11-16 21:35

Code: Select all
root@edbarx-pc:/home/edbarx/sysv# ./link-updater.sh dgli
Created scriptsmodified in the current directory to block multiple runs.
If everything works, you can delete scriptsmodified
bootlogd
bootlogd: processed
bootlogs
bootlogs: processed
bootmisc.sh
bootmisc.sh: processed
checkfs.sh
checkfs.sh: processed
checkroot-bootclean.sh
checkroot-bootclean.sh: processed
checkroot.sh
checkroot.sh: processed
halt
halt: processed
hostname.sh
hostname.sh: processed
killprocs
killprocs: processed
motd
motd: processed
mountall-bootclean.sh
mountall-bootclean.sh: processed
mountall.sh
mountall.sh: processed
mountdevsubfs.sh
mountdevsubfs.sh: processed
mountkernfs.sh
mountkernfs.sh: processed
mountnfs-bootclean.sh
mountnfs-bootclean.sh: processed
mountnfs.sh
mountnfs.sh: processed
rc
rc: processed
rc.local
rc.local: processed
rcS
rcS: processed
README
README: processed
reboot
reboot: processed
rmnologin
rmnologin: processed
sendsigs
sendsigs: processed
single
single: processed
skeleton
skeleton: processed
stop-bootlogd
stop-bootlogd: processed
stop-bootlogd-single
stop-bootlogd-single: processed
umountfs
umountfs: processed
umountnfs.sh
umountnfs.sh: processed
umountroot
umountroot: processed
urandom
urandom: processed
dgli/etc/inittab
dgli/etc/inittab: processed
mountnfs
mountnfs: processed
bootclean.sh
bootclean.sh: processed
init-d-script
init-d-script: processed
mount-functions.sh
mount-functions.sh: processed
swap-functions.sh
swap-functions.sh: processed
tmpfs.sh
tmpfs.sh: processed
vars.sh
vars.sh: processed
dgli/sbin/fsck.nfs
dgli/sbin/fsck.nfs: processed
invoke-rc.d
invoke-rc.d: processed
service
service: processed
update-rc.d
update-rc.d: processed
inittab
inittab: processed
update-rc.d
update-rc.d: processed
saveconfig
saveconfig: processed


Rebooted with a shell due to myself forgetting that I copied the missing scripts from /etc/init.d when I succeeded to boot after modifying sysvinit the other week.

I can solve the problem of missing scripts by providing links to /etc/init.d as packages store scripts there but I have doubts about such a solution.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5389
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: How to create an isolated sysvinit.

Postby tomazzi » 2014-11-17 01:57

Hi, Edbarx
I'm really astonished regarding the progress You've made so far... congratulations!

However, I'm going to fork systemd - as I've already said, I like the idea behind it, but I can't withstand or even tolerate that shitty code which comes with the original implementation of systemd. Of course I'm going to drop most of the "extensions" of systemd, like the DNS daemon... (stupidity has limits - users can vote with their feets - there's no equevalent for as extremely stupid piece of code as systemd' DNS service...)

It's relly not so surprising - RedHat has very similar development model to Microshit: targets. Go to the target, implement a target solution - no matter if the code is a shit - target was reached, money has been paid... Yeah I'm the RMVP (RedHat Most Valuable Professional)...

Morons are not born, morons are created...

Regards
Odi profanum vulgus
tomazzi
 
Posts: 730
Joined: 2013-08-02 21:33

Re: How to create an isolated sysvinit.

Postby edbarx » 2014-11-17 06:18

Code: Select all
#!/bin/bash

origpath=`pwd`

function getExtraDaemons()
{
  for j in \
    "hdparm" "stop-bootlogd-single" "acpi-support" "procps" "console-setup" \
    "keyboard-setup" "network-manager" "acpi-fakekey" "slim" "arno-iptables-firewall" \
    "kmod" "anacron" "acpid" "bootlogd" "saned" "rpcbind" "x11-common" "rsyslog" \
    "dbus" "bluetooth" "cron" "cgproxy" "cgmanager" "hwclock.sh" "networking" \
    "dev-finish" "privoxy" "alsa-utils" "stop-bootlogd" "pppd-dns" "udev" \
    "kdm" "sudo" "kbd" "openvpn"; do
   
    if [ -f "/etc/init.d/"$j ]; then
      cp -a "/etc/init.d/"$j $1"/"$j
    fi
  done 
}

function modify_paths()
{
  resstr=""
  fname=$1
  if [ -d $fname ]; then
    resstr=$(ls -1 $1)
    cd $1
  else
    resstr=$1
  fi
 
  #echo $resstr
  #return 1

  for i in $resstr; do
# check if $i is the running script (not done) or a directory (done) and skip accordingly 
    if [ -d $i ]; then
      continue
    fi

    #cp $i file001
      # path replacement instructions
      sed -i 's|/lib/init/vars.sh|/dgli/lib/init/vars.sh|g' $i
      sed -i 's|/lib/lsb/init-functions|/dgli/lib/lsb/init-functions|g' $i
      sed -i 's|/lib/init/mount-functions.sh|/dgli/lib/init/mount-functions.sh|g' $i
      sed -i 's|/lib/init/swap-functions.sh|/dgli/lib/init/swap-functions.sh|g' $i
      sed -i 's|/lib/init/tmpfs.sh|/dgli/lib/init/tmpfs.sh|g' $i
      sed -i 's|/lib/init/bootclean.sh|/dgli/lib/init/bootclean.sh|g' $i
      sed -i 's|/etc/default/devpts|/dgli/etc/default/devpts|g' $i
      sed -i 's|/etc/default/halt|/dgli/etc/default/halt|g' $i
      sed -i 's|/etc/default/rcS|/dgli/etc/default/rcS|g' $i
      sed -i 's|/etc/default/tmpfs|/dgli/etc/default/tmpfs|g' $i
      sed -i 's|/bin/mountpoint|/dgli/bin/mountpoint|g' $i
      sed -i 's|/bin/pidof|/dgli/bin/pidof|g' $i
      sed -i 's|/usr/bin/last|/dgli/usr/bin/last|g' $i
      sed -i 's|/usr/bin/lastb|/dgli/usr/bin/lastb|g' $i
      sed -i 's|/usr/bin/mesg|/dgli/bin/mesg|g' $i
      sed -i 's|/usr/include/initreq.h|/dgli/usr/include/initreq.h|g' $i
      sed -i 's|/usr/sbin/invoke-rc.d|/dgli/usr/sbin/invoke-rc.d|g' $i
      sed -i 's|/usr/sbin/service|/dgli/usr/sbin/service|g' $i
      sed -i 's|/usr/sbin/update-rc.d|/dgli/usr/sbin/update-rc.d|g' $i
#     
      sed -i 's|/usr/share/lintian/overrides/bootlogd|/dgli/usr/share/lintian/overrides/bootlogd|g' $i
      sed -i 's|/usr/share/lintian/overrides/initscripts|/dgli/usr/share/lintian/overrides/initscripts|g' $i
      sed -i 's|/usr/share/lintian/overrides/sysvinit-core|/dgli/usr/share/lintian/overrides/sysvinit-core|g' $i
      sed -i 's|/usr/share/lintian/overrides/sysv-rc|/dgli/usr/share/lintian/overrides/sysv-rc|g' $i
      sed -i 's|/usr/share/sysvinit/inittab|/dgli/usr/share/sysvinit/inittab|g' $i
      sed -i 's|/usr/share/sysvinit/update-rc.d|/dgli/usr/share/sysvinit/update-rc.d|g' $i
      sed -i 's|/usr/share/sysv-rc/saveconfig|/dgli/usr/share/sysv-rc/saveconfig|g' $i
#     
      sed -i 's|/lib/init/init-d-script|/dgli/lib/init/init-d-script|g' $i
      sed -i 's|/lib/sysvinit/init|/dgli/lib/sysvinit/init|g' $i
      sed -i 's|/lib/sysvinit/telinit|/dgli/lib/sysvinit/telinit|g' $i
      sed -i 's|/network/if-up.d/mountnfs|/dgli/network/if-up.d/mountnfs|g' $i
      sed -i 's|/sbin/bootlogd|/dgli/sbin/bootlogd|g' $i
      sed -i 's|/sbin/fsck.nfs|/dgli/sbin/fsck.nfs|g' $i
      sed -i 's|/sbin/fstab-decode|/dgli/sbin/fstab-decode|g' $i
      sed -i 's|/sbin/halt|/dgli/sbin/halt|g' $i
      sed -i 's|/sbin/init|/dgli/sbin/init|g' $i
      sed -i 's|/sbin/killall5|/dgli/sbin/killall5|g' $i
      sed -i 's|/sbin/poweroff|/dgli/sbin/poweroff|g' $i
      sed -i 's|/sbin/reboot/|/dgli/sbin/reboot|g' $i
      sed -i 's|/sbin/runlevel|/dgli/sbin/runlevel|g' $i
      sed -i 's|/sbin/shutdown|/dgli/sbin/shutdown|g' $i
      sed -i 's|/sbin/sulogin|/dgli/sbin/sulogin|g' $i
      sed -i 's|/sbin/telinit|/dgli/sbin/telinit|g' $i
      sed -i 's|/etc/inittab|/dgli/etc/inittab|g' $i 
 #     
      sed -i 's|/etc/init.d|/dgli/etc/init.d|g' $i
      sed -i 's|/etc/default/rc|/dgli/etc/default/rc|g' $i
      sed -i 's|/etc/rc|/dgli/etc/rc|g' $i     
    #file001 > file002; cp file002 $i;
    echo $i
    echo $i": processed"
  done

  #rm file001 file002  ENABLE this line GAHAN
  cd $origpath
}


if [ -f $1"/scriptsmodified" ]; then
  echo "Protective Failure: running this script more than once will insert '\dgli' the corresponding number of times."
  exit 1
fi

touch $1"/scriptsmodified"
echo "Created scriptsmodified in the current directory to block multiple runs."
echo "If everything works, you can delete scriptsmodified"

spath="etc/init.d"
getExtraDaemons $1"/"$spath

initd="etc/init.d" 
modify_paths $1"/"$initd
rm $1"/bin/pidof"
ln --symbolic /dgli/sbin/killall5 $1"/bin/pidof"

spath="etc/inittab"
modify_paths $1"/"$spath

spath="etc/network/if-up.d"
modify_paths $1"/"$spath

spath="lib/init"
modify_paths $1"/"$spath

spath="sbin/fsck.nfs"
modify_paths $1"/"$spath

spath="usr/sbin"
modify_paths $1"/"$spath

spath="usr/share/lintian"
modify_paths $1"/"$spath

spath="usr/share/sysvinit"
modify_paths $1"/"$spath

spath="usr/share/sysv-rc"
modify_paths $1"/"$spath

mkdir $1"/lib/lsb"
mkdir $1"/lib/lsb/init-functions.d"

if [ -f "/lib/lsb/init-functions.d/20-left-info-blocks" ]; then
  cp -a "/lib/lsb/init-functions.d/20-left-info-blocks"  $1"/lib/lsb/init-functions.d/20-left-info-blocks"
fi

if [ -f "/lib/lsb/init-functions" ]; then
  cp -a "/lib/lsb/init-functions"  $1"/lib/lsb/init-functions"
fi

exit 0


Running the script outputs:
Code: Select all
root@edbarx-pc:/home/edbarx/sysv# ./link-updater.sh ./dgli
Created scriptsmodified in the current directory to block multiple runs.
If everything works, you can delete scriptsmodified
acpid
acpid: processed
acpi-fakekey
acpi-fakekey: processed
acpi-support
acpi-support: processed
alsa-utils
alsa-utils: processed
anacron
anacron: processed
arno-iptables-firewall
arno-iptables-firewall: processed
bluetooth
bluetooth: processed
bootlogd
bootlogd: processed
bootlogs
bootlogs: processed
bootmisc.sh
bootmisc.sh: processed
cgmanager
cgmanager: processed
cgproxy
cgproxy: processed
checkfs.sh
checkfs.sh: processed
checkroot-bootclean.sh
checkroot-bootclean.sh: processed
checkroot.sh
checkroot.sh: processed
console-setup
console-setup: processed
cron
cron: processed
dbus
dbus: processed
halt
halt: processed
hdparm
hdparm: processed
hostname.sh
hostname.sh: processed
hwclock.sh
hwclock.sh: processed
kbd
kbd: processed
kdm
kdm: processed
keyboard-setup
keyboard-setup: processed
killprocs
killprocs: processed
kmod
kmod: processed
motd
motd: processed
mountall-bootclean.sh
mountall-bootclean.sh: processed
mountall.sh
mountall.sh: processed
mountdevsubfs.sh
mountdevsubfs.sh: processed
mountkernfs.sh
mountkernfs.sh: processed
mountnfs-bootclean.sh
mountnfs-bootclean.sh: processed
mountnfs.sh
mountnfs.sh: processed
networking
networking: processed
network-manager
network-manager: processed
openvpn
openvpn: processed
pppd-dns
pppd-dns: processed
privoxy
privoxy: processed
procps
procps: processed
rc
rc: processed
rc.local
rc.local: processed
rcS
rcS: processed
README
README: processed
reboot
reboot: processed
rmnologin
rmnologin: processed
rpcbind
rpcbind: processed
rsyslog
rsyslog: processed
saned
saned: processed
sendsigs
sendsigs: processed
single
single: processed
skeleton
skeleton: processed
slim
slim: processed
stop-bootlogd
stop-bootlogd: processed
stop-bootlogd-single
stop-bootlogd-single: processed
sudo
sudo: processed
udev
udev: processed
umountfs
umountfs: processed
umountnfs.sh
umountnfs.sh: processed
umountroot
umountroot: processed
urandom
urandom: processed
x11-common
x11-common: processed
./dgli/etc/inittab
./dgli/etc/inittab: processed
mountnfs
mountnfs: processed
bootclean.sh
bootclean.sh: processed
init-d-script
init-d-script: processed
mount-functions.sh
mount-functions.sh: processed
swap-functions.sh
swap-functions.sh: processed
tmpfs.sh
tmpfs.sh: processed
vars.sh
vars.sh: processed
./dgli/sbin/fsck.nfs
./dgli/sbin/fsck.nfs: processed
invoke-rc.d
invoke-rc.d: processed
service
service: processed
update-rc.d
update-rc.d: processed
inittab
inittab: processed
update-rc.d
update-rc.d: processed
saveconfig
saveconfig: processed
mkdir: cannot create directory ‘./dgli/lib/lsb’: File exists
mkdir: cannot create directory ‘./dgli/lib/lsb/init-functions.d’: File exists
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5389
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: How to create an isolated sysvinit.

Postby edbarx » 2014-11-19 09:19

tomazzi wrote:Hi, Edbarx
I'm really astonished regarding the progress You've made so far... congratulations!

However, I'm going to fork systemd - as I've already said, I like the idea behind it, but I can't withstand or even tolerate that shitty code which comes with the original implementation of systemd. Of course I'm going to drop most of the "extensions" of systemd, like the DNS daemon... (stupidity has limits - users can vote with their feets - there's no equevalent for as extremely stupid piece of code as systemd' DNS service...)

It's relly not so surprising - RedHat has very similar development model to Microshit: targets. Go to the target, implement a target solution - no matter if the code is a shit - target was reached, money has been paid... Yeah I'm the RMVP (RedHat Most Valuable Professional)...

Morons are not born, morons are created...

Regards

Thanks for the encouragement. If you think, I can help, send me a private message.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5389
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: How to create an isolated sysvinit with the script.

Postby anastasis » 2014-11-24 23:31

This is really good stuff.

We live in interesting times.

These days we do things like install a boot sector virus for our init and then have a boot level anti-virus to deactivate and circumvent that boot sector virus so we can boot and initialize our basic services.

This is wonderful.

This is exactly what we needed.

We needed to first have something that worked, then force something that works in questionable ways or doesn't work, and then have other scripts to deactivate the thing that works in questionable so we can get back to something that works.

This makes perfect sense.

That's what makes Debian fun.

I mean, if it ain't hell, they ain't happy, right?
"He might be a German, but he ain't no Einstein."
User avatar
anastasis
 
Posts: 222
Joined: 2012-11-15 02:28
Location: Near White Sands Missile Range

Re: How to create an isolated sysvinit with the script.

Postby edbarx » 2014-11-25 15:52

anastasis wrote:We needed to first have something that worked, then force something that works in questionable ways or doesn't work, and then have other scripts to deactivate the thing that works in questionable so we can get back to something that works.

You are right this is a contorted solution. Frankly, I would have preferred a solution that worked seemlessly with Debian's package management system. However, it is not up to me to 'oblige' the DDs to continue supporting sysvinit. In fact, systemd, lookd more like an overkill for normal computer uses, but I have to live in a world where decisions may not depend on me. In the real world, many decisions are like that: while they heal many, they injure many others.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5389
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 2 guests

fashionable