Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
# Internet Skills for Disconnected People: iskidip.e
# This file is a rewrite of busybox.e.
# Currently it is mostly broken.
# Author:  Eduardo Ochs <eduardoochs@gmail.com>
# Version: 2005sep05 5:04
#
# See also: (find-eevexfile "iskidip2.e")

# (find-eimage0 "$EEVA/iskidip.png")

# (insert (format "(setq last-kbd-macro (read-kbd-macro %S))" (format-kbd-macro)))

(setq last-kbd-macro (read-kbd-macro "C-a 2*<right> « C-e » <<mkto>> <down>"))


# «.busybox-config»		(to "busybox-config")
# «.busybox-compile»		(to "busybox-compile")
# «.busybox-tags»		(to "busybox-tags")

# «.dinitrd-select»		(to "dinitrd-select")
# «.dinitrd-cp-img»		(to "dinitrd-cp-img")
# «.dinitrd-mount»		(to "dinitrd-mount")
# «.dinitrd-umount»		(to "dinitrd-umount")
# «.dinitrd-pack»		(to "dinitrd-pack")
# «.dinitrd-unpack»		(to "dinitrd-unpack")
# «.dinitrd-rm-some-modules»	(to "dinitrd-rm-some-modules")
# «.dinitrd-pack-modules»	(to "dinitrd-pack-modules")
# «.dinitrd-unpack-modules»	(to "dinitrd-unpack-modules")
#   «.about-loadmodules»	(to "about-loadmodules")

# «.instlib-functions»		(to "instlib-functions")
# «.install-bash»		(to "install-bash")
# «.chroot-bash»		(to "chroot-bash")
# «.umount-guestfs»		(to "umount-guestfs")
# «.create-guestfs»		(to "create-guestfs")
# «.create-guestfs.img»		(to "create-guestfs.img")
# «.mount-guestfs»		(to "mount-guestfs")
# «.mkdirs-guest»		(to "mkdirs-guest")
# «.mount-guest-vfss»		(to "mount-guest-vfss")
# «.install-busybox»		(to "install-busybox")
# «.create-devices»		(to "create-devices")
# «.chroot-ash»			(to "chroot-ash")
# «.telnet-port-block»		(to "telnet-port-block")
# «.telnet-port-clear»		(to "telnet-port-clear")
# «.telnetd-killall»		(to "telnetd-killall")
# «.qemu-linux-guestimg»	(to "qemu-linux-guestimg")
# «.qemu-isoimg»		(to "qemu-isoimg")
# «.guest-mkdirs»		(to "guest-mkdirs")
# «.create-etcpasswdgroup»	(to "create-etcpasswdgroup")
# «.create-busyboxconf»		(to "create-busyboxconf")
# «.create-etcprofile»		(to "create-etcprofile")
# «.create-etcinitdrcS»		(to "create-etcinitdrcS")

# «.create-hdaimg-sparse»	(to "create-hdaimg-sparse")

# «.grub-compile»		(to "grub-compile")
# «.grub-iso-mkdirs»		(to "grub-iso-mkdirs")
# «.grub-iso-menulst»		(to "grub-iso-menulst")
# «.grub-iso-mkisofs»		(to "grub-iso-mkisofs")
# «.grub-iso-qemu»		(to "grub-iso-qemu")



# «chroot-ash»  (to ".chroot-ash")
# «qemu-linux-guestimg»  (to ".qemu-linux-guestimg")
# «qemu-isoimg»  (to ".qemu-isoimg")
# «guest-mkdirs»  (to ".guest-mkdirs")



#               «.iptables-ping»	(to "iptables-ping")
#               «.iptables-clear»	(to "iptables-clear")
#               «.iptables-set» 	(to "iptables-set")



# Quick index (blocks on which I'm working actively):
#   (to "bb_etc_inittab")
#   (to "bb_etc_profile")
#   (to "iso-qemu-main")

# Note: don't expect to just go to the "...-main" blocks, type F9, F9,
# F9, ... and have everything working; there are some steps - like
# downloading the ".tar.gz"s with the source for busybox and grub (use
# psne http://foo.org/bar/file.tar.gz for that) that are not
# automated, and are not going to be.

# which ones of those have an inittab?

# bash,      chroot
# |busybox,  chroot
# ||busybox, chroot, iptables, telnetd
# |||
# ||| debian's   initrd, unpack
# ||| |debian's  initrd,               qemu
# ||| ||debian's initrd, busybox-0.60, qemu
  ||| |||
# ||| ||| busybox-1.00,     initrd,          qemu
# ||| ||| |busybox-1.00,    initrd, netcat,  qemu
# ||| ||| ||busybox-1.00,   initrd, telnetd, qemu
# ||| ||| |||busybox-1.00,  initrd, telnetd, grub, iso,     qemu
# ||| ||| ||||busybox-1.00, initrd, telnetd, grub, mkisofs, qemu
# ||| ||| |||||

% install-bash
% chroot-bash
% umount-guestfs
% create-guestfs
% mount-guestfs
% install-busybox
% create-devices
% chroot-ash
% block-telnet-port
% qemu-linux-guestimg
% qemu-isoimg

% install-etcpasswdgoup

#               «.busybox-config»	(to "busybox-config")
#               «.busybox-compile»	(to "busybox-compile")
#               «.busybox-tags»		(to "busybox-tags")

#               «.bb_umounts»		(to "bb_umounts")
#               «.bb_mounts»		(to "bb_mounts")
#               «.bb_mkdirs»		(to "bb_mkdirs")
#               «.bb_functions»		(to "bb_functions")
#               «.bb_addbusybox»	(to "bb_addbusybox")
#               «.bb_etc_passwd_group»	(to "bb_etc_passwd_group")
#               «.bb_busybox.conf»	(to "bb_busybox.conf")
#               «.bb_empty_e2fs»	(to "bb_empty_e2fs")

#               «.bb_chroot_main»	(to "bb_chroot_main")

#               «.sparse-hda.img»	(to "sparse-hda.img")
#               «.bb_cp_modules»	(to "bb_cp_modules")
#               «.bb_mknods»		(to "bb_mknods")
#               «.bb_etc_init.d_rcS»	(to "bb_etc_init.d_rcS")
#               «.bb_etc_inittab»	(to "bb_etc_inittab")

#               «.bbinitrd-qemu-main»	(to "bbinitrd-qemu-main")


#               «.iso-mkdirs»		(to "iso-mkdirs")
#               «.iso-menu.lst»		(to "iso-menu.lst")
#               «.iso-mkisofs»		(to "iso-mkisofs")
#               «.iso-qemu-run»		(to "iso-qemu-run")

#               «.iso-qemu-main»	(to "iso-qemu-main")
#               «.iso-qemu-main-2»	(to "iso-qemu-main-2")

#               «.cdrecord»		(to "cdrecord")

#               «.download-iso-run-qemu»	(to "download-iso-run-qemu")

#               «.standard-initrd.img»		(to "standard-initrd.img")
#               «.unpack-initrd.img»		(to "unpack-initrd.img")
#               «.about-loadmodules»		(to "about-loadmodules")
#               «.rm-some-initrdfiles-modules»(to "rm-some-initrdfiles-modules")
#               «.cp-initrdfiles-modules»	(to "cp-initrdfiles-modules")

›
(eek "C-a C-q 233 C-o")

(defun mkto2 () (interactive)
  (mkto) (eek "<up> C-a C-SPC <down> C-w")
  (save-excursion (ee-goto-position "\233") (eek "C-a C-y")))

# (eev "cd $EEVE/; a2ps -=p2iso busybox.e; mv o.ps /tmp/; gv /tmp/o.ps")






#####
#
# compiling busybox 1.00
# 2005feb17
#
#####

# http://www.busybox.net/downloads/busybox-1.00.tar.gz
# http://angg.twu.net/BUSYBOX/config-1.00

# Debian's busybox is 0.60.5, which is very old and doesn't have many
# of the features that we need (for example, a telnetd)... so we use
# the upstream version.
#*
# «busybox-config»  (to ".busybox-config")
# Because setting the options in "make menuconfig" takes a long time...
#
mkdir ~/BUSYBOX/
cd    ~/BUSYBOX/
wget http://angg.twu.net/BUSYBOX/config-1.00

#*
# «busybox-compile»  (to ".busybox-compile")
rm -Rfv ~/usrc/busybox-1.00/
tar  -C ~/usrc/ -xvzf $S/http/www.busybox.net/downloads/busybox-1.00.tar.gz
cd      ~/usrc/busybox-1.00/

# (find-busyboxfile "Makefile" "menuconfig:")
# (find-busyboxfile "scripts/config/")
make -C scripts/config ncurses conf mconf     2>&1 | tee omsc

# (find-fline "~/BUSYBOX/")
# (find-fline "~/BUSYBOX/config-1.00")
cp -iv ~/BUSYBOX/config-1.00 .config

# make menuconfig
# cp -iv .config ~/BUSYBOX/config-1.00

cd ~/usrc/busybox-1.00/
make dep     2>&1 | tee omd
make         2>&1 | tee om

#*
# «busybox-tags»  (to ".busybox-tags")
cd ~/usrc/busybox-1.00/
find * -type f -name '*.[ch]' | grep -v '^scripts/' | sort > .files.ch
etags $(<.files.ch)

#*
# (code-c-d "busybox" "~/usrc/busybox-1.00/")
# (find-busyboxfile "")
# (find-busyboxfile "Makefile")
# (find-busyboxfile "Makefile" "menuconfig:")

# (find-busyboxfile "INSTALL")
# (find-busyboxfile "busybox.links")




#####
#
# inspect Debian's initrd
# 2005may11
#
#####

# (find-es "initrd" "debian-busybox-initrd")
#*
# «dinitrd-select»  (to ".dinitrd-select")
# «dinitrd-cp-img»  (to ".dinitrd-cp-img")
# Copy a standard initrd image from /boot/ to /tmp/dinitrd.img.
# (find-sh "cd /var/lib/dpkg/info/; ls kernel-image-*.list")
# (find-fline "/boot/")
#
cp -v /boot/initrd.img-2.6.8-1-386 /tmp/dinitrd.img

#*
# «dinitrd-umount»  (to ".dinitrd-umount")
umount /tmp/dinitrd/dev/pts/
umount /tmp/dinitrd/dev/
umount /tmp/dinitrd/proc/
umount /tmp/dinitrd/

#*
# «dinitrd-mount»  (to ".dinitrd-mount")
mkdir  /tmp/dinitrd/
mount -v -o loop,ro /tmp/dinitrd.img -t cramfs /tmp/dinitrd/

#*
# Cramfs images are hard to use sometimes - among other things, they
# are read-only and they allow hardlinks between directories (most
# other filesystems do not). So we need to uncramfsize them...
# Note: "cp -av" doesn't deal well with hard-linked dirs.

#*
# «dinitrd-pack»  (to ".dinitrd-pack")
cd             /tmp/dinitrd/  \
  && tar -cvzf /tmp/dinitrd.tgz *

#*
# «dinitrd-unpack»  (to ".dinitrd-unpack")
mkdir   /tmp/dinitrdfiles/
tar  -C /tmp/dinitrdfiles/ \
  -xvzf /tmp/dinitrd.tgz \
  2>&1 | grep -v 'implausibly old time stamp'

#*
# «dinitrd-rm-some-modules»  (to ".dinitrd-rm-some-modules")
cd /tmp/dinitrdfiles/ \
  && cd lib/modules/2.6.8-1-386/kernel/drivers/ \
  && rm -Rv md/ scsi/

#*
# «dinitrd-pack-modules»  (to ".dinitrd-pack-modules")
cd             /tmp/dinitrdfiles/ \
  && tar -cvzf /tmp/dinitrd-modules.tgz lib/modules/

#*
# «dinitrd-unpack-modules»  (to ".dinitrd-unpack-modules")
tar  -C /tmp/guest/ \
  -xvzf /tmp/dinitrd-modules.tgz \
  2>&1 | grep -v 'implausibly old time stamp'

#*
# «about-loadmodules»  (to ".about-loadmodules")
# (find-fline "/tmp/dinitrdfiles/")
# (find-fline "/tmp/dinitrdfiles/loadmodules")
# (find-fline "/tmp/dinitrdfiles/linuxrc")
# (find-fline "/tmp/dinitrdfiles/sbin/init")
# (find-fline "/tmp/dinitrdfiles/sbin/init" "call /loadmodules")
# (find-fline "/tmp/dinitrdfiles/lib/modules/2.6.8-1-386/")
# (find-fline "/usr/sbin/mkinitrd" "loadmodules")
# Which modules go there?
tkdiff             =(cd /lib/modules/2.6.8-1-386/ && find * -type d | sort) \
  =(cd /tmp/dinitrdfiles/lib/modules/2.6.8-1-386/ && find * -type d | sort) &

#*






#*
# «instlib-functions»  (to ".instlib-functions")
guest_getlibs () {
  { for i in $*; do ldd $i; done; } | awk '{print $3}' | sort | uniq;
}
guest_instfiles () { cp --parents -v $* /tmp/guest/; }
guest_instlibsfor () { guest_instfiles $(guest_getlibs $*); }

#*
# «install-bash»  (to ".install-bash")
# (find-es "initrd" "add_binaries_and_libs")
guest_instlibsfor /bin/bash /bin/ls /usr/bin/less /usr/bin/tee /bin/nc
guest_instfiles   /bin/bash /bin/ls /usr/bin/less /usr/bin/tee /bin/nc

#*
# «chroot-bash»  (to ".chroot-bash")
chroot /tmp/guest/ \
  /bin/bash  

#*
# «umount-guestfs»  (to ".umount-guestfs")
umount /tmp/guest/dev/pts
umount /tmp/guest/dev
umount /tmp/guest/proc
umount /tmp/guest

#*
# «create-guestfs»  (to ".create-guestfs")
# «create-guestfs.img»  (to ".create-guestfs.img")
rm -Rv /tmp/guest/
mkdir  /tmp/guest/
# dd bs=1024 count=4096 if=/dev/zero of=/tmp/guest.img
  dd bs=1024 count=8192 if=/dev/zero of=/tmp/guest.img
mke2fs -F /tmp/guest.img

#*
# «mount-guestfs»  (to ".mount-guestfs")
mount -o loop /tmp/guest.img /tmp/guest/

#*
# «mkdirs-guest»  (to ".mkdirs-guest")
mkdir -p /tmp/guest/dev/
mkdir -p /tmp/guest/dev/pts/
mkdir -p /tmp/guest/proc/

mkdir -p /tmp/guest/bin
mkdir -p /tmp/guest/sbin
mkdir -p /tmp/guest/usr/bin
mkdir -p /tmp/guest/usr/sbin
mkdir -p /tmp/guest/etc

mkdir -p /tmp/guest/tmp
ln -s .. /tmp/guest/tmp/guest

chmod 1777      /tmp/guest/tmp/
mkdir -p        /tmp/guest/home/edrx/
chown 1000:1000 /tmp/guest/home/edrx/

#*
# «mount-guest-vfss»  (to ".mount-guest-vfss")
mount -t devfs  guestdev    /tmp/guest/dev
mount -t proc   guestproc   /tmp/guest/proc
mount -t devpts guestdevpts /tmp/guest/dev/pts

#*
# «install-busybox»  (to ".install-busybox")
cd ~/usrc/busybox-1.00/
cp -v          ./busybox /tmp/guest/bin/busybox
for i in $(cat ./busybox.links | sed s_^/__ ); do
  echo $i
  ln /tmp/guest/bin/busybox /tmp/guest/$i
done

guest_instlibsfor /tmp/guest/bin/busybox

#*
# «create-devices»  (to ".create-devices")
cd /tmp/guest/dev/
mknod null    c 1 3
mknod console c 5 1
mknod ptmx    c 5 2
#
# mknod tty     c 5 0
# mknod tty1    c 4 1
# mknod tty2    c 4 2
# mknod tty3    c 4 3
# mknod tty4    c 4 4

mknod tty  c 5   0; for i in $(seq 1 4); do mknod tty$i  c 4 $i; done
mknod vcs  c 7   0; for i in $(seq 1 4); do mknod vcs$i  c 7 $i; done
mknod vcsa c 7 128; for i in $(seq 1 4); do mknod vcsa$i c 7 $[128+$i]; done

mknod hda    b 3 0
mknod hda1   b 3 1
mknod hda2   b 3 2

#*
# «create-etcpasswdgroup»  (to ".create-etcpasswdgroup")
mkdir /tmp/guest/etc/
cat > /tmp/guest/etc/passwd <<'%%%'
root::0:0:root:/:/bin/sh
edrx::1000:1000:edrx,,,:/home/edrx:/bin/sh
aleph::1001:1001:aleph,,,:/:/bin/sh
beth::1002:1002:beth,,,:/:/bin/sh
r::0:0:root:/:/bin/sh
e::1000:1000:edrx,,,:/home/edrx:/bin/sh
%%%
# root->root, edrx->edrx:
cat > /tmp/guest/etc/passwd <<'%%%'
root:$1$$oCLuEVgI1iAqOA8pwkzAg1:0:0:root:/:/bin/sh
edrx:$1$$nO9T/jR80jiG3aAiOsSSV/:1000:1000:edrx,,,:/home/edrx:/bin/sh
aleph::1001:1001:aleph,,,:/:/bin/sh
beth::1002:1002:beth,,,:/:/bin/sh
r::0:0:root:/:/bin/sh
e::1000:1000:edrx,,,:/home/edrx:/bin/sh
%%%
cat > /tmp/guest/etc/group <<'%%%'
root:*:0:
edrx:!:1000:
aleph:!:1001:
beth:!:1002:
%%%

#*
# «create-busyboxconf»  (to ".create-busyboxconf")
# (find-busyboxfile "applets/applets.c" "Using fallback suid method")
# (find-busyboxfile "sysdeps/linux/Config.in" "_FEATURE_SUID_CONFIG_QUIET")
# (find-busyboxfile "sysdeps/linux/Config.in" "CONFIG_FEATURE_SUID_CONFIG")
# http://www.softforge.de/bb/suid.html
mkdir /tmp/guest/etc/
touch /tmp/guest/etc/busybox.conf

#*
# «create-etcprofile»  (to ".create-etcprofile")
# (find-busyboxfile "util-linux/mount.c")
# (find-fline "/etc/fstab" "proc")
# (find-esfile "initrd.e" "cat > etc/profile <<'%%%'")

cat > /tmp/guest/etc/profile <<'%%%'
export HOST=172.20.0.1
export HERE=172.20.0.2
export EE=/tmp/ee.sh
alias  laf='ls -laF'
alias  w=which
mountproc   () { mount -t proc   proc   /proc; }
mountdev    () { mount -t devfs  devfs  /dev; }
mountdevpts () { mount -t devpts devpts /dev/pts; }
mounts      () { mountproc; mountdevpts; }
mounts2     () { mountproc; mountdev; mountdevpts; }
insmod_eth  () { cd /tmp/; insmod crc32.ko; insmod 8390.ko;
                 insmod ne2k-pci.ko; }
insmod_plip () { cd /tmp; insmod parport.ko;
                 insmod plip.ko; insmod parport_pc.ko; }
up_lo       () { ifconfig lo 127.0.0.1; route add 127.0.0.1 lo; }
up_eth      () { ifconfig eth0 172.20.0.2; route add 172.20.0.0 eth0; }
up_plip     () { ifconfig plip0 10.0.0.4 pointopoint 10.0.0.3;
                 route add 10.0.0.0 plip0; }
prep        () { mounts;  insmod_eth; up_eth; }
prep2       () { mounts2; insmod_eth; up_eth; }
fromhost    () { nc -l -p 1234; }
tohost      () { nc -q 0 $HOST 1234; }
ee          () { set -v; . $EE; set +v; }
#
vars_eth    () { export HOST=172.20.0.1; export HERE=172.20.0.2; }
vars_plip   () { export HOST=10.0.0.3;   export HERE=10.0.0.4; }

prep2ep     () { prep2; insmodps; up_plip; }
%%%

#*
# «create-etcinitdrcS»  (to ".create-etcinitdrcS")
# Note that this is optional!
# Use only when you want to do all this at startup.

mkdir -p /tmp/guest/etc/init.d/
cat    > /tmp/guest/etc/init.d/rcS <<'%%%'
#!/bin/sh
mount -t proc   proc   /proc
echo "  Before mounts:"; mount
#mount -t devfs devfs  /dev
mount -t devpts devpts /dev/pts
echo "  After mounts:"; mount
#
# (find-eevex "busybox.e" "bb_etc_profile")
. /etc/profile
up_lo
insmod_plip && up_plip
insmod_eth  && up_eth
#
telnetd
%%%
chmod 755 /tmp/guest/etc/init.d/rcS

#*
# «telnet-port-clear»  (to ".telnet-port-clear")
# Note: this blocks gives several funny errors when we run it on empty
# iptables...
iptables -D INPUT -p TCP --dport telnet -j INPUTFILTER
iptables -F INPUTFILTER
iptables -X INPUTFILTER

#*
# «telnet-port-block»  (to ".telnet-port-block")
iptables -N INPUTFILTER
iptables -A INPUTFILTER -s 127.0.0.1    -j ACCEPT
iptables -A INPUTFILTER -j DROP
iptables -A INPUT -p TCP --dport telnet -j INPUTFILTER

#*
# «telnetd-killall»  (to ".telnetd-killall")
killall -9 telnetd

#*




#####
#
# busybox in a chrooted environment
# 2005apr08
#
#####

#*
# «bb_busybox.conf»  (to ".bb_busybox.conf")
# «bb_empty_e2fs»  (to ".bb_empty_e2fs")

#*
# «bb_chroot_main»  (to ".bb_chroot_main")
* (eechannel-xterm "A")
sudo ~/run-zsh
* (find-sh0 "sudo killall -9 telnetd")
* (eevnow-at "iptables-clear")
* (eevnow-at "iptables-set")
* (eevnow-at "bb_umounts")
rm -Rv /tmp/guest/
* (eevnow-at "bb_mounts")
* (eevnow-at "bb_mkdirs")
* (eevnow-at "bb_functions")
* (eevnow-at "bb_addbusybox")
* (eevnow-at "bb_etc_passwd_group")
* (eevnow-at "bb_busybox.conf")

chroot /tmp/guest /bin/ash
passwd root
root
root
passwd edrx
edrx
edrx

# login
# edrx
# edrx
# exit

telnetd &
exit

#*
* (eechannel-xterm "A")
telnet 127.0.0.1
edrx
edrx

#*

* (eechannel-xterm "bb-root" (ee-split "sudo chroot /tmp/guest /bin/ash"))

# (find-busyboxfile "")
# (find-busyboxfile "docs/BusyBox.txt")

# (find-es "initrd" "add_binaries_and_libs")




#####
#
# iptables (to reject outside connections to telnetd)
# 2005apr19
#
#####

#*
# «iptables-ping»  (to ".iptables-ping")
# (find-udw3m "iptables/html/packet-filtering-HOWTO-7.html" "-p icmp -j DROP")
#
iptables -D INPUT -s 127.0.0.1 -p icmp -j DROP
ping -c 2 -W 1       127.0.0.1 | egrep 'from|transmitted'

iptables -A INPUT -s 127.0.0.1 -p icmp -j DROP
iptables -L INPUT
ping -c 2 -W 1       127.0.0.1 | egrep 'from|transmitted'

iptables -L INPUT --line-numbers
iptables -D INPUT 1

#*
iptables -L INPUTFILTER --line-numbers
iptables -L

#*
# (find-fline "/etc/services")
# (find-udw3m "iptables/html/packet-filtering-HOWTO-7.html" "-p icmp -j DROP")
# (find-sh "iptables --help")
# (find-man "iptables" "    -X")

#*
# Some tests (run with F9):
* (eechannel-xterm "A")
* (eebgTWU)
# telnet 127.0.0.1
telnet 200.141.116.226
edrx
edrx
exit

#*
# (find-status   "iptables")
# (find-vldifile "iptables.list")
# (find-udfile   "iptables/")
# (find-udw3m "iptables/html/packet-filtering-HOWTO.html")
# (find-udw3m "iptables/html/packet-filtering-HOWTO-5.html")
# (find-udw3m "iptables/html/packet-filtering-HOWTO-7.html")
# (find-udfile "iptables/examples/3iptables-ppp_up-rules.gz")

# (find-udfile "focalinux/text/avancado/index.txt.gz")
# (find-udfile "focalinux/text/avancado/index.txt.gz" "iptables -P INPUT DROP")
# (find-available "ebtables")




#####
#
# subroutines specific to making initrds and running qemu
# 2005apr20
#
#####

#*
# «create-hdaimg-sparse»  (to ".create-hdaimg-sparse")
python <(cat <<'%%%'
image = open("/tmp/hda.img", "w")
image.truncate(1024 * 1048576L)
image.close()
%%%
)

#*
# Notes about the "job control turned off" problem:
#
# (find-k26file "init/main.c" "/sbin/init")
# (find-busyboxfile "busybox.links" "/sbin/init")
# (find-busyboxfile "docs/BusyBox.txt" "without an inittab")
# (find-busyboxfile "init/init.c" "No inittab file -- set up some default")
# (find-busyboxfile "docs/BusyBox.txt" "controlling tty")
# (find-busyboxfile "init/init.c" "static void set_term(int fd)")
# (find-busyboxfile "init/init.c" "setsid();")
# (find-busyboxfile "shell/ash.c" "can't access tty; job control turned off")

# Entries like "...:/bin/sh" in inittab create "non-login" shells that
# don't read /etc/profile, entries like "...:-/bin/sh" create login
# shells that do...
#
# (find-busyboxfile "shell/ash.c" "if (argv[0] && argv[0][0] == '-')")
# (find-busyboxfile "shell/ash.c" "read_profile(\"/etc/profile\");")
# (find-busyboxfile "init/init.c" "-/bin/sh")

#*
# «bb_etc_inittab»  (to ".bb_etc_inittab")
# This is optional too - this is the default inittab with just one
# change: moving the first shell from the default tty, to tty1, i.e.,
# "::askfirst:/bin/sh" -> "tty1::askfirst:/bin/sh".

cat > /tmp/guest/etc/inittab <<'%%%'
::sysinit:/etc/init.d/rcS
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::restart:/sbin/init
tty1::askfirst:-/bin/sh
tty2::askfirst:-/bin/sh
tty3::askfirst:-/bin/sh
tty4::askfirst:-/bin/sh
%%%

#*






#####
#
# making an initrd
# 2005apr19
#
#####

#*
# «bbinitrd-qemu-main»  (to ".bbinitrd-qemu-main")
* (eechannel-xterm "A")
sudo ~/run-zsh
* (message (find-sh0 "sudo killall -9 telnetd"))
* (eevnow-at "iptables-clear")
* (eevnow-at "iptables-set")
* (eevnow-at "bb_umounts")
rm -Rv /tmp/guest/
dd bs=1024 count=3072 if=/dev/zero of=/tmp/guest.img
mke2fs -F /tmp/guest.img
mkdir /tmp/guest/
mount -o loop /tmp/guest.img /tmp/guest/
* (eevnow-at "bb_mounts")
* (eevnow-at "bb_mkdirs")
* (eevnow-at "bb_functions")
* (eevnow-at "bb_addbusybox")
* (eevnow-at "bb_etc_passwd_group")
* (eevnow-at "bb_busybox.conf")

* (eevnow-at "bb_umounts")
* (eevnow-at "bb_mknods")
* (eevnow-at "bb_etc_profile")
* (eevnow-at "bb_cp_modules")

* (eevnow-at "sparse-hda.img")

cd /tmp/
umount /tmp/guest/

cp -v /boot/vmlinuz-2.6.8-1-386    /tmp/vmlinuz

* (eechannel-xterm "A")
# Try the initrd with qemu.
# (find-man "1 qemu")
cd /tmp/
qemu -hda    /tmp/hda.img  \
     -kernel /tmp/vmlinuz  \
     -monitor stdio -m 64  \
     -pci                  \
     -initrd /tmp/guest.img

#*



# (find-k26file "")

# (find-sh "ifconfig; route")
# (to "bb_etc_profile")
#   init
#   prep2
#   telnetd &

* (eechannel-xterm "B")
telnet 172.20.0.2
root
root

date | netcat -q 0 172.20.0.2 1234



# (find-man "1 qemu" "-nographic")
# (find-man "1 qemu" "-monitor dev")
qemu -m 64 -isa -n /tmp/my-qemu-ifup \


# What to search if plip doesn't work (or is too slow) with the
# default settings, i.e., no IRQ:
#
# (to "bb_etc_profile")
# (find-k26file "drivers/parport/Kconfig")
# (find-k26docfile "parport.txt")




#####
#
# compiling grub 0.96
# 2005may01
#
#####

# ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz
# (code-c-d "grub" "~/usrc/grub-0.97/" "~/usrc/grub-0.97/docs/grub")
# '(add-to-list 'Info-additional-directory-list "~/usrc/grub-0.96/")
# (find-grubfile "")
# (find-grubnode "Top")
# (find-grubnode "Making a GRUB bootable CD-ROM")
# See also:
# http://www.gnu.org/software/grub/grub-2.en.html

#*
# «grub-compile»  (to ".grub-compile")
rm -Rv ~/usrc/grub-0.97/
tar -C ~/usrc/ -xvzf $S/ftp/alpha.gnu.org/gnu/grub/grub-0.97.tar.gz
cd     ~/usrc/grub-0.97/
./configure  2>&1 | tee oc
make         2>&1 | tee om

#*
# (find-grubnode "Making a GRUB bootable CD-ROM")
# (find-man "8 mkisofs")
# (find-man "8 mkisofs" "-b eltorito_boot_image")
# (find-man "8 mkisofs" "-boot-load-size load_sectors")
# (find-man "8 mkisofs" "-boot-info-table")
# (find-man "8 mkisofs" "-no-emul-boot\n")
# (find-man "8 mkisofs" "\nEL TORITO BOOT INFORMATION TABLE\n")
# (find-fline "/boot/grub/menu.lst")

#*
# «grub-iso-mkdirs»  (to ".grub-iso-mkdirs")
rm -Rv   /tmp/guest-iso/
mkdir    /tmp/guest-iso/
mkdir -p /tmp/guest-iso/boot/grub/
cp -v ~/usrc/grub-0.97/stage2/stage2_eltorito /tmp/guest-iso/boot/grub/

cp -v /boot/vmlinuz-2.6.8-1-386               /tmp/guest-iso/boot/
cp -v /tmp/guest.img                          /tmp/guest-iso/boot/

#*
# «grub-iso-menulst»  (to ".grub-iso-menulst")
cat > /tmp/guest-iso/boot/grub/menu.lst <<'%%%'
timeout 5
default 0
title  Linux 2.6.8 (busybox)
  kernel /boot/vmlinuz-2.6.8-1-386 root=/dev/hda1 vga=1
  initrd /boot/bb.img
title  halt
  halt
%%%

#*
# «grub-iso-mkisofs»  (to ".grub-iso-mkisofs")
mkisofs -R \
  -b boot/grub/stage2_eltorito -no-emul-boot \
  -boot-load-size 4 -boot-info-table \
  -o /tmp/guest-iso.iso /tmp/guest-iso/

#*
# «grub-iso-qemu»  (to ".grub-iso-qemu")
# Try the CD image with qemu.
# (find-man "1 qemu")
cd /tmp/
qemu -hda    /tmp/hda.img    \
     -cdrom  /tmp/guest-iso.iso \
     -boot d                 \
     -monitor stdio -m 64    \
     -pci

#*
# «iso-qemu-main»  (to ".iso-qemu-main")
* (eechannel-xterm "A")
sudo ~/run-zsh
killall -9 telnetd

* (eevnow-at "bb_umounts")
* (eevnow-at "bb_empty_e2fs")
* (eevnow-at "bb_mkdirs")
* (eevnow-at "bb_functions")
* (eevnow-at "bb_addbusybox")
* (eevnow-at "bb_busybox.conf")
* (eevnow-at "bb_mknods")
* (eevnow-at "bb_cp_modules")
* (eevnow-at "bb_etc_passwd_group")
* (eevnow-at "bb_etc_profile")
* (eevnow-at "bb_etc_init.d_rcS")
* (eevnow-at "bb_etc_inittab")

date > /tmp/guest/tmp/VERSION
echo '# (find-eevex "busybox.e" "iso-qemu-main")' \
    >> /tmp/guest/tmp/VERSION

cd     /tmp/
umount /tmp/guest/

* (eevnow-at "iso-mkdirs")
* (eevnow-at "iso-menu.lst")
* (eevnow-at "iso-mkisofs")
* (eevnow-at "sparse-hda.img")

* (eevnow-at "iso-qemu-run")

#*
* (eechannel-xterm "B")
telnet 172.20.0.2
root
root

modprobe piix




#####
#
# another initrd for qemu, this one with all the initrd-ish modules
# 2005may12
#
#####

#*
# «iso-qemu-main-2»  (to ".iso-qemu-main-2")
* (eechannel-xterm "A")
sudo ~/run-zsh
killall -9 telnetd

* (eevnow-at "bb_umounts")
* (eevnow-at "bb_empty_e2fs")
* (eevnow-at "bb_mkdirs")
* (eevnow-at "bb_functions")
* (eevnow-at "bb_addbusybox")
* (eevnow-at "bb_busybox.conf")
* (eevnow-at "bb_mknods")
* (eevnow-at "bb_cp_modules")
* (eevnow-at "bb_etc_passwd_group")
* (eevnow-at "bb_etc_profile")
* (eevnow-at "bb_etc_init.d_rcS")
* (eevnow-at "bb_etc_inittab")

date > /tmp/guest/tmp/VERSION
echo '# (find-eevex "busybox.e" "iso-qemu-main")' \
    >> /tmp/guest/tmp/VERSION

* ;; Experimental:
* (eevnow-at "standard-initrd.img")
* (eevnow-at "unpack-initrd.img")
* (eevnow-at "rm-some-initrdfiles-modules")
* (eevnow-at "cp-initrdfiles-modules")

cd     /tmp/
umount /tmp/guest/

* (eevnow-at "iso-mkdirs")
* (eevnow-at "iso-menu.lst")
* (eevnow-at "iso-mkisofs")
* ;; (eevnow-at "sparse-hda.img")


* (eechannel-xterm "QEMU" nil '("-geometry" "79x5"))
sudo chmod 666 /dev/net/tun
sudo chmod 666 /tmp/hda.img
R
* (eevnow-at "iso-qemu-run")

* (eechannel-xterm "A")
telnet 172.20.0.2
root
root


* (eevnow-at "iso-qemu-run")

#*
* (eechannel-xterm "B")
telnet 172.20.0.2
root
root

modprobe piix


















* (eechannel-xterm "A")
sudo ~/run-zsh
killall -9 telnetd
* (eevnow-at "bb_umounts")
* (eevnow-at "bb_empty_e2fs")
* (eevnow-at "bb_mkdirs")
* (eevnow-at "bb_functions")
* (eevnow-at "bb_addbusybox")
* (eevnow-at "bb_busybox.conf")
* (eevnow-at "bb_mknods")
* (eevnow-at "bb_cp_modules")

* (eevnow-at "bb_etc_passwd_group")
* (eevnow-at "bb_etc_profile")
* (eevnow-at "bb_etc_init.d_rcS")
* (eevnow-at "bb_etc_inittab")

date > /tmp/guest/tmp/VERSION
echo '# (find-eevex "busybox.e" "iso-qemu-main")' \
    >> /tmp/guest/tmp/VERSION

cp -v /sbin/modprobe /tmp/guest/sbin/modprobe
bb_instlibsfor        /tmp/guest/sbin/modprobe

* (eevnow-at "standard-initrd.img")
* (eevnow-at "unpack-initrd.img")
* (eevnow-at "rm-some-initrd.img-modules")
* (eevnow-at "cp-initrd.img-modules")

cd     /tmp/
umount /tmp/guest/

* (eevnow-at "iso-mkdirs")
* (eevnow-at "iso-menu.lst")
* (eevnow-at "iso-mkisofs")
* ;; (eevnow-at "sparse-hda.img")


* (eechannel-xterm "QEMU" nil '("-geometry" "79x5"))
sudo chmod 666 /dev/net/tun
sudo chmod 666 /tmp/hda.img
# sudo ~/run-zsh
* (eevnow-at "iso-qemu-run")

# Test mounting from the qemu'ed guest
* (eechannel-xterm "A")
telnet 172.20.0.2
root
root



* (eevnow-at "iso-qemu-run")

#*
* (eechannel-xterm "B")
telnet 172.20.0.2
root
root







#####
#
# Turning off the machine (even in qemu) from the shell
# (Note: "halt" in grub works, apm + busybox's "halt" not yet)
# (find-angg ".zshrc" "aa")
# 2005may03
#
#####

* (eechannel-xterm "B")
telnet 172.20.0.2
root
root
cd /tmp/
fromhost > apm.ko
*
* (eechannel-xterm "C")
cd /lib/modules/2.6.8-1-386/kernel/arch/i386/kernel/
cat apm.ko \
  | netcat -q 0 172.20.0.2 1234

* (eechannel-xterm "B")
telnet 172.20.0.2
root
root
cd /tmp/
insmod apm.ko power-off=1
halt



# Kill by hand:
# (find-sh0 "sudo killall -9 qemu")




#####
#
# record the iso image on a CD-RW
#
#####

# «cdrecord»  (to ".cdrecord")
# (find-es "cdrom" "cdrecord")

* (eechannel-xterm "A")
cd /tmp/
cdrecord speed=8 -v -v -v -v -v -dev=/dev/hdd /tmp/guest-iso.iso

cd /tmp/
cdrecord speed=8 blank=fast -v -v -v -v -v -dev=/dev/hdd /tmp/guest-iso.iso

# (find-man "cdrecord")
# (find-man "cdrecord" "fixated")
# (find-man "cdrecord" "speed")

# (find-htetfile "CD-Writing-HOWTO.gz")
# (find-htetfile "CD-Writing-HOWTO.gz" "  How to create a multi-session CD?")
# (find-htetfile "CD-Writing-HOWTO.gz" "specify the parameter blank=fast")

# (find-es "mini" "plipnfs")




#####
#
# allowing dirs from the host to be NFS-mounted by the guest
# 2005may04
#
#####

# What I changed in my /etc (by hand):

# (find-man "5 exports")
# (find-fline "$ASROOT/etc/exports")
/ 127.0.0.1(rw,async) 10.0.0.4(rw,async) 172.20.0.2(rw,async)

# Do I need this?
# (find-man "5 hosts.allow")
# (find-fline "$ASROOT/etc/hosts.allow")
127.0.0.1
10.0.0.4
172.20.0.2

# (find-fline "/etc/init.d/nfs-common")
# (find-fline "/etc/init.d/nfs-kernel-server")
# (find-fline "/etc/default/nfs-common")
# (find-fline "/etc/default/nfs-kernel-server")
# (find-fline "/etc/rc2.d/")

* (eechannel-xterm "A")
sudo ~/run-zsh
/etc/init.d/nfs-kernel-server restart
/etc/init.d/nfs-common restart

# Test using local mounts
# (find-man "5 nfs")
mkdir /tmp/host/
mount -t nfs 127.0.0.1:/     /tmp/host/; ls /tmp/host/
umount /tmp/host/
mount -t nfs 127.0.0.1:/etc/ /tmp/host/; ls /tmp/host/
umount /tmp/host/

* (eechannel-xterm "QEMU")
sudo ~/run-zsh
* (eevnow-at "iso-qemu-run")

# Test mounting from the qemu'ed guest
* (eechannel-xterm "GUEST")
telnet 172.20.0.2
root
root

cd /tmp/
insmod sunrpc.ko
insmod lockd.ko
insmod nfs.ko
echo '127.0.0.1 localhost loopback mistletoe' > /etc/hosts

mkdir  /host
mount -t nfs -o nolock 172.20.0.1:/ /host/
ls     /host/
umount /host/

# Note: if I don't use "-o nolock" I get these (kernel?) errors:
#   nfs warning: mount version older than kernel
#   portmap: server localhost not responding, timed out
#   RPC: failed to contact portmap (errno -5).
#   portmap: server localhost not responding, timed out
#   RPC: failed to contact portmap (errno -5).
#   lockd_up: makesock failed, error=-5
#   RPC: failed to contact portmap (errno -5).
#   lockd_down: no lockd running.





#####
#
# how to try it by downloading just the iso image
# 2005may04
#
#####

gzip -c9 < /tmp/guest-iso.iso \
 > /var/www/tmp/guest-iso.iso.gz
#
# (find-fline "/var/www/tmp/")

# «download-iso-run-qemu»  (to ".download-iso-run-qemu")
cd /tmp/
wget http://201.8.142.27/tmp/guest-iso.iso.gz
gunzip bb-iso.iso.gz
python <(cat <<'%%%'
image = open("/tmp/hda.img", "w")
image.truncate(1024 * 1048576L)
image.close()
%%%
)
cd /tmp/
qemu -hda    /tmp/hda.img    \
     -cdrom  /tmp/guest-iso.iso \
     -boot d                 \
     -monitor stdio -m 64    \
     -pci

# Then, if tun support exists and if qemu can open /dev/net/tun, it
# should be possible to telnet to the box...
# (find-es "qemu" "tun-tap")

* (eechannel-xterm "GUEST")
telnet 172.20.0.2
root
root










#####
#
# Trying to debug busybox (ignore this block)
# 2005apr09
#
#####

# I started this because I couldn't make a telnetd to work on Debian's
# busybox... with busybox-1.00 the built-in telnetd works, but,
# anyway, how do we debug chrooted programs?

#*
chroot /tmp/guest bin/login

#*
# Needs to be run as root
# (ee-once (eeb-gdb-start "/tmp/guest/usr/sbin/" "chroot"))
set args /tmp/guest /bin/login
br main
br applets.c:164
br chroot_main
run

#*




cat > /tmp/guest/etc/issue.net <<'%%%'
Debian GNU/Linux 3.1 initrd %t
%%%





#####
#
# mkinitrd with the new busybox
# 2005apr09
#
#####

# (find-es "initrd" "debian-busybox-initrd")
# (find-fline "/usr/sbin/mkinitrd")
# (find-fline "/usr/sbin/mkinitrd" "if [ $BUSYBOX ]")
# (find-fline "/usr/sbin/mkinitrd" "if [ $BUSYBOX ]" "Curr")
# (find-busyboxsh "./busybox")

Hypothesis: "PATH=$HOME/usrc/busybox-1.00:$PATH mkinitrd ..." will
locate busybox-1.00 before debian's busybox-0.60, and use it. Mkinitrd
gets the list of links from busybox itself, but how does it select in
which dirs they should go?




#####
#
# Debian busybox source (this block is obsolete)
# 2005apr08
#
#####

# (find-status   "busybox")
# (find-vldifile "busybox.list")
# (find-udfile   "busybox/")
# (find-man  "1 busybox")
# (find-udfile "busybox/BusyBox.txt.gz" "\n    init\n")
# (find-udfile "busybox/BusyBox.txt.gz" "\n    init\n" "controlling tty")

# http://ftp.debian.org/debian/pool/main/b/busybox/busybox_0.60.5-2.2.dsc
#*
rm -Rv ~/usrc/busybox/
mkdir  ~/usrc/busybox/
cd     ~/usrc/busybox/
dpkg-source -x \
  $S/http/ftp.debian.org/debian/pool/main/b/busybox/busybox_0.60.5-2.2.dsc

#*
# (code-c-d "busybox" "~/usrc/busybox/busybox-0.60.5/")
# (find-busyboxfile "")
# (find-busyboxfile "telnet.c")
# (find-busyboxfile "init.c" "static void set_term(int fd)")
# (find-busyboxfile "init.c" "setsid();")




# 2005apr20: qemu doesn't boot the image, maybe there are devices
# missing... I think that there's an option to linux to make it mount
# devfs, but I'll try some mknods first...

# (find-k26file "init/main.c" "/sbin/init")
# (find-esfile "initrd.e" "mknod tty")
# (find-esfile "initrd.e" "mount -v -o loop,ro /tmp/initrd.img")

# Here's a listing of the /dev dir in debian's initrd:
# /tmp/initrdfs/dev(root:pe)# laf
# total 5
# lrwxrwxrwx  1 root root   14 Dec 31  1969 cciss -> ../devfs/cciss
# crw-rw----  1 root root 5, 1 Dec 31  1969 console
# lrwxrwxrwx  1 root root   12 Dec 31  1969 ida -> ../devfs/ida
# lrwxrwxrwx  1 root root   12 Dec 31  1969 ide -> ../devfs/ide
# lrwxrwxrwx  1 root root   15 Dec 31  1969 mapper -> ../devfs/mapper
# lrwxrwxrwx  1 root root   11 Dec 31  1969 md -> ../devfs/md
# crw-rw-rw-  1 root root 1, 3 Dec 31  1969 null
# lrwxrwxrwx  1 root root   13 Dec 31  1969 scsi -> ../devfs/scsi

#*



# Problems, 2005apr20:
# init is not very happy - Alt-F2 doesn't work, for example



# (find-busyboxfile "")
# (find-busyboxfile "networking/telnetd.c")
# (find-busyboxfile "init/init.c")
# (find-busyboxfile "init/init.c" "static void parse_inittab")
# (find-busyboxfile "docs/BusyBox.txt" "\n    init\n")
# (find-busyboxfile "console-tools/openvt.c")

# (find-busyboxfile "util-linux/nfsmount.c")

  | netcat -q 0 172.20.0.2 1234

alias w=which


#*
# «bb_cp_modules»  (to ".bb_cp_modules")
# (find-k26confvar "CONFIG_NE2000")
# (find-k26confvar "CONFIG_NE2K_PCI")
# (find-fline "/lib/modules/2.6.8-1-386/")
# (find-fline "/lib/modules/2.6.8-1-386/kernel/drivers/net/")
# (find-fline "/lib/modules/2.6.8-1-386/modules.dep")
# (find-fline "/lib/modules/2.6.8-1-386/modules.dep" "ne2k-pci.ko")






#  Local Variables:
#  coding:               no-conversion
#  modes:                (fundamental-mode sh-mode emacs-lisp-mode)
#  ee-delimiter-hash:    "\n#*\n"
#  ee-delimiter-percent: "\n%*\n"
#  ee-anchor-format:     "«%s»"
#  End: