Skip to content

Instantly share code, notes, and snippets.

@DanielG
Created May 22, 2015 14:06
Show Gist options
  • Save DanielG/46f67aea6a8cef467f47 to your computer and use it in GitHub Desktop.
Save DanielG/46f67aea6a8cef467f47 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -x
NAME=thingy
MIRROR=ftp.at.debian.org/debian
tmpdir=$(mktemp -p "${TMPDIR:-/tmp/}" -d $NAME-XXXX) || exit 1
#tmpdir=/tmp/thingy
#mkdir -p "$tmpdir"
trap 'rm -r '"$tmpdir" 0 2 15
unpack_deb () {
(
p="$PWD"
cd "$tmpdir"
ar x "$p/$1"
tar -C rootdir -xf "data.tar."*
rm "data.tar."*
)
}
wget --continue http://snapshot.debian.org/archive/debian/20141116T035859Z/pool/main/c/cdebootstrap/cdebootstrap-static_0.6.4_amd64.deb -O cdebootstrap-static.deb
# only needed for dns resolver libraraies which busybox dlopens at runtime
# aparently busybox can be built statically with those though but then I'd have
# to build them myself :/
wget --continue http://snapshot.debian.org/archive/debian/20150415T034434Z/pool/main/g/glibc/libc6_2.19-18_amd64.deb -O libc.deb
wget --continue http://snapshot.debian.org/archive/debian/20150304T220713Z/pool/main/b/busybox/busybox-static_1.22.0-15_amd64.deb -O busybox-static.deb
wget --continue http://snapshot.debian.org/archive/debian/20150128T222235Z/pool/main/b/bash/bash-static_4.3-12_amd64.deb -O bash-static.deb
wget --continue http://snapshot.debian.org/archive/debian/20150427T040903Z/pool/main/l/linux/linux-image-3.16.0-4-amd64_3.16.7-ckt9-3~deb8u1_amd64.deb -O linux-image.deb
mkdir "$tmpdir/rootdir"
unpack_deb libc.deb
unpack_deb cdebootstrap-static.deb
unpack_deb busybox-static.deb
unpack_deb bash-static.deb
unpack_deb linux-image.deb
(
set -x
cd "$tmpdir/rootdir"
mkdir -p bin
mkdir -p target
mkdir -p proc
mkdir -p sys
mkdir -p dev
mkdir -p etc/network
mkdir -p etc/network/if-up.d
mkdir -p etc/network/if-down.d
mkdir -p var/run
cp bin/bash-static bin/bash
cp ~/var/build/strace-4.10/strace bin
cp /etc/services etc
mkdir -p etc/udhcpc/
cp usr/share/doc/busybox-static/examples/udhcp/simple.script etc/udhcpc/default.script
chmod +x etc/udhcpc/default.script
./bin/busybox --install bin
ldconfig -r "$PWD"
depmod -b "$PWD"
cat > etc/network/interfaces <<EOF
iface eth0 inet dhcp
EOF
cat > etc/hosts <<EOF
127.0.0.1 localhost
EOF
cat > init <<EOF
#!/bin/bash-static
echo "--- --- init --- ---"
mount -t proc none /proc
mount -t sysfs none /sys
modprobe ata_piix
modprobe sg
modprobe sd_mod
mknod /dev/sda b 8 0
modprobe e1000
ifup eth0
export TERM=linux
/bin/bash-static
#/usr/bin/cdebootstrap-static -vd --allow-unauthenticated wheezy /target http://ftp.at.debian.org/debian
EOF
chmod +x init
find . > ../list
cpio -H newc -o < ../list | gzip > ../initrd.img
);
cp rootdir/boot/vmlinuz-3.16.0-4-amd64 "$p"
cp initrd.img "$p"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment