--- /dev/null
+#!/bin/busybox ash
+# -*- mode: sh -*-
+
+err () { echo "ERROR: $@"; }
+msg () { [ "${quiet}" != "y" ] && echo $@; }
+
+rescue_shell() {
+ echo "Irgendwas ging hier schief ... Ich mach hier mal 'ne Shell auf."
+ busybox --install -s
+ exec /bin/sh
+}
+
+export CONSOLE="/dev/tty1"
+export FIRST_RAID_DEVICE="/dev/md1"
+export ROOT="/dev/md3"
+#export CRYPTROOT="/dev/sda4"
+#export CRYPTNAME="root"
+export CONSOLEFONT='ter-v16n'
+
+mount -t sysfs none /sys || rescue_shell
+mount -t proc none /proc || rescue_shell
+
+read CMDLINE </proc/cmdline
+export CMDLINE
+for x in ${CMDLINE}; do
+ case "${x}" in
+ quiet)
+ quiet='y'
+ export quiet
+ ;;
+ esac
+done
+
+msg 'Silencing procfs ...'
+echo 0 > /proc/sys/kernel/printk
+
+echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
+
+msg "Creating device nodes ..."
+mdev -s
+echo /sbin/mdev > /proc/sys/kernel/hotplug
+
+# assure, that import nodes exist
+[ ! -c "$NEWROOT/dev/console" ] && mknod "$NEWROOT/dev/console" c 5 1
+[ ! -c "$NEWROOT/dev/null" ] && mknod "$NEWROOT/dev/null" c 1 3
+
+# setup splash screen
+#. /etc/initrd.splash
+#msg "Setting up splashscreen ..."
+#splash init
+
+# set keymap and console font
+msg "Enabling unicode ..."
+kbd_mode -u -C /dev/tty1
+printf "\033%%G" >> /dev/console
+msg "Loading keymap ..."
+loadkmap < /etc/keymap
+msg "Setting font ..."
+setfont /usr/share/consolefonts/${CONSOLEFONT}.psf.gz -C /dev/tty1
+printf "\033(K" >> /dev/console
+
+# create device mapper control file
+if [ -e "/sys/class/misc/device-mapper" ]; then
+ if [ ! -c "/dev/mapper/control" ]; then
+ # create device, if required
+ msg 'Creating device mapper control node ...'
+ read dev_t < /sys/class/misc/device-mapper/dev
+ mknod "/dev/mapper/control" c `echo "$dev_t" | tr ':' ' '`
+ fi
+else
+ err "Device mapper unavailable, aborting ..."
+ rescue_shell
+fi
+
+# unlock crypto device
+#msg 'Opening luks container ...'
+#while ! cryptsetup luksOpen "${CRYPTROOT}" "${CRYPTNAME}" > /dev/null; do
+# sleep 2
+#done
+
+msg "Detecting Linux RAID devices ..."
+raidautorun "${FIRST_RAID_DEVICE}"
+
+# discover and enable lvm volumes
+msg 'Scanning lvm volumes ...'
+lvm vgscan --ignorelockingfailure > /dev/null
+msg 'Enabling lvm volumes ...'
+lvm vgchange --ignorelockingfailure -ay > /dev/null
+
+# try to resume
+resume
+
+# mount root filesystem (readonly so that fsck doesn't choke)
+msg 'Mounting root filesystem ...'
+mount -o ro "${ROOT}" "/mnt" || rescue_shell
+
+msg 'Cleaning up ...'
+echo > /proc/sys/kernel/hotplug
+umount /proc
+umount /sys
+
+msg 'Switching root ...'
+exec switch_root /mnt /sbin/init
--- /dev/null
+# -*- mode: conf -*-
+# init script (damn important!!!)
+file /init ${package}/init.sh 755 0 0
+
+# directory structure
+dir /proc 755 0 0
+dir /sys 755 0 0
+dir /dev 755 0 0
+dir /lib 755 0 0
+dir /bin 755 0 0
+dir /sbin 755 0 0
+dir /mnt 755 0 0
+dir /etc 755 0 0
+dir /usr 755 0 0
+dir /usr/share 755 0 0
+
+# basic tools
+file /bin/busybox /bin/busybox 755 0 0
+slink /sbin/mdev /bin/busybox 755 0 0
+
+# lvm support
+dir /dev/mapper 755 0 0
+file /sbin/lvm /sbin/lvm.static 755 0 0
+dir /etc/lvm 755 0 0
+file /etc/lvm/lvm.conf /etc/lvm/lvm.conf 644 0 0
+
+# framebuffer support
+#file /sbin/v86d /sbin/v86d 755 0 0
+
+# cryptsetup support
+#file /sbin/cryptsetup /sbin/cryptsetup 755 0 0
+
+# console font
+dir /usr/share/consolefonts 755 0 0
+file /usr/share/consolefonts/ter-v16n.psf.gz /usr/share/consolefonts/ter-v16n.psf.gz 644 0 0
+
+# keymap
+file /etc/keymap ${package}/keymap 644 0 0
+
+# uswsusp support
+#file /sbin/resume /usr/lib/suspend/resume 755 0 0
+#file /etc/suspend.conf /etc/suspend.conf 644 0 0
+
+# splash support
+#dir /lib/splash 644 0 0
+#dir /lib/splash/sys 644 0 0
+#dir /lib/splash/proc 644 0 0
+#file /sbin/fbcondecor_helper /sbin/fbcondecor_helper 755 0 0
+#slink /sbin/splash_helper /sbin/fbcondecor_helper 755 0 0
+#file /etc/initrd.splash /usr/share/splashutils/initrd.splash 644 0 0
+
+# splash theme
+#dir /etc/splash 755 0 0
+#dir /etc/splash/natural_gentoo 755 0 0
+#file /etc/splash/natural_gentoo/1280x800.cfg /etc/splash/natural_gentoo/1280x800.cfg 644 0 0
+#dir /etc/splash/natural_gentoo/images 755 0 0
+#file /etc/splash/natural_gentoo/images/silent-1280x800.jpg /etc/splash/natural_gentoo/images/silent-1280x800.jpg 644 0 0
+#file /etc/splash/natural_gentoo/images/verbose-1280x800.jpg /etc/splash/natural_gentoo/images/verbose-1280x800.jpg 644 0 0
+
+# important device files
+nod /dev/mem 600 0 0 c 1 1
+nod /dev/null 666 0 0 c 1 3
+nod /dev/zero 600 0 0 c 1 5
+nod /dev/console 600 0 0 c 5 1
+nod /dev/tty0 620 0 0 c 4 0
+nod /dev/tty1 600 0 0 c 4 1
+
+# device directories
+dir /dev/fb 755 0 0
+dir /dev/misc 755 0 0
+dir /dev/vc 755 0 0
+
--- /dev/null
+#!/usr/bin/env python
+
+# Copyright (c) 2008, 2009, 2010 Sebastian Wiesner <lunaryorn@googlemail.com>
+
+# This program is free software. It comes without any warranty, to
+# the extent permitted by applicable law. You can redistribute it
+# and/or modify it under the terms of the Do What The Fuck You Want
+# To Public License, Version 2, as published by Sam Hocevar. See
+# http://sam.zoy.org/wtfpl/COPYING for more details.
+
+
+from __future__ import print_function
+
+import os
+import sys
+import gzip
+import subprocess
+from string import Template
+from contextlib import closing
+from optparse import OptionParser
+from shutil import copyfileobj, copy
+from tempfile import NamedTemporaryFile
+from distutils.spawn import find_executable
+
+
+__version__ = '0.1'
+
+
+PACKAGE = os.path.dirname(os.path.abspath(__file__))
+TEMPLATE = os.path.join(PACKAGE, 'makefile.tmpl')
+
+
+def expand_template():
+ """
+ Expands the makefile template.
+
+ :param context: Template context
+ """
+ with open(TEMPLATE) as stream:
+ return Template(stream.read()).substitute(package=PACKAGE)
+
+
+def compile_initramfs(dogzip=False):
+ """
+ Compiles the complete image.
+
+ :param dogzip: If True, compress the image
+ :return: path of compiled image
+ """
+ with NamedTemporaryFile('w', prefix='makefile', delete=False) as stream:
+ stream.write(expand_template())
+ makefile = stream.name
+ target = 'initramfs'
+ print('Generating', target, '...')
+ opener = gzip.open if dogzip else open
+ with closing(opener(target, 'wb')) as stream:
+ proc = subprocess.Popen(
+ ['/usr/src/linux/usr/gen_init_cpio', makefile],
+ stdout=subprocess.PIPE)
+ copyfileobj(proc.stdout, stream)
+ return target
+
+
+def sudo_install_initramfs(source, kernel):
+ cmd = ['sudo', 'install', '-m', '644', source, '/boot']
+ subprocess.check_call(cmd)
+
+
+def su_install_initramfs(source):
+ cmd = ['su', '-c', 'install', '-m', '644', source, '/boot']
+ subprocess.check_call(cmd)
+
+
+def install_initramfs(source):
+ """
+ Installs initramfs from ``source`` on /boot.
+
+ If this process doesn't have root privileges, sudo and su are tried,
+ otherwise the initramfs is just copied
+
+ :param source: source file
+ """
+ print('Installing at /boot ...')
+ if os.geteuid() != 0:
+ sudo = find_executable('sudo')
+ if sudo:
+ return sudo_install_initramfs(source)
+ su = find_executable('su')
+ if su:
+ return su_install_initramfs(source)
+ else:
+ copy(source, os.path.join('/boot', os.path.basename(source)))
+
+
+def _license(*args):
+ print("""\
+Copyright (c) 2008, 2009 Sebastian Wiesner <lunaryorn@googlemail.com>
+
+This program is free software. It comes without any warranty, to
+the extent permitted by applicable law. You can redistribute it
+and/or modify it under the terms of the Do What The Fuck You Want
+To Public License, Version 2, as published by Sam Hocevar. See
+http://sam.zoy.org/wtfpl/COPYING for more details.""")
+ sys.exit()
+
+
+def main():
+ parser = OptionParser(
+ usage='%prog [-i] [-z]',
+ description='Initramfs build script',
+ epilog="""\
+(C) 2009 Sebastian Wiesner <lunaryorn@googlemail.com>""",
+ version=__version__)
+ parser.add_option('-i', '--install', help='Install image at /boot',
+ action='store_true')
+ parser.add_option('-z', '--gzip', help='Compress the image',
+ action='store_true')
+ parser.add_option('-l', '--license', help='Print license and exit',
+ action='callback', callback=_license)
+ options, args = parser.parse_args()
+ initramfs_file = compile_initramfs(options.gzip)
+ if options.install:
+ try:
+ install_initramfs(initramfs_file)
+ except EnvironmentError as error:
+ print(error, file=sys.stderr)
+
+
+if __name__ == '__main__':
+ main()