summaryrefslogtreecommitdiff
path: root/i/pc104/initrd/create.sh
diff options
context:
space:
mode:
Diffstat (limited to 'i/pc104/initrd/create.sh')
-rwxr-xr-xi/pc104/initrd/create.sh163
1 files changed, 163 insertions, 0 deletions
diff --git a/i/pc104/initrd/create.sh b/i/pc104/initrd/create.sh
new file mode 100755
index 0000000..b991c83
--- /dev/null
+++ b/i/pc104/initrd/create.sh
@@ -0,0 +1,163 @@
+#!/bin/bash
+# Create an empty initrd
+# This script require to be run under root privilege...
+
+set -u
+set -e
+
+# Parameters
+# Initrd size in Mo
+INITRD_SIZE=16
+# The output file for the initrd
+INITRD_OUTPUT="initrd.test"
+# Save the name of a temporary directory
+INITRD_TEMPDIR=""
+# Directory with stuff for the script
+INITRD_CONFIG_DIR="conf"
+# Busybox source location
+INITRD_BUSYBOX="$INITRD_CONFIG_DIR/busybox"
+# Initrd compression (activate by default)
+INITRD_COMPRESS=0
+
+help_initrd ()
+{
+ echo "Usage: $0 [-o <file>] [-s <size>] [-z]"
+ echo " -o <file> : name of the initrd file"
+ echo " -s <size> : size of the initrd (in Mb)"
+ echo " -z : disable compression"
+ echo " -h : this message"
+ exit 1
+}
+
+# Create initrd file
+create_initrd ()
+{
+ # Create an empty file
+ dd if=/dev/zero of=$INITRD_OUTPUT bs=1M count=$INITRD_SIZE
+ # Format in ext2 with block size 1024, force and nothing reserved for
+ # root ! Be quiet !
+ /sbin/mkfs -t ext2 -b 1024 -F -m 0 -q $INITRD_OUTPUT
+}
+
+mount_initrd ()
+{
+ # Create a temporary directory
+ INITRD_TEMPDIR=`mktemp -d -t initrd_robot.XXXXXX`
+ # Mount the initrd on the temporary directory
+ mount -o loop -t ext2 $INITRD_OUTPUT $INITRD_TEMPDIR
+}
+
+create_empty_struct ()
+{
+ # Create an empty root structure
+ mkdir -p $INITRD_TEMPDIR/{bin,dev,etc,lib,proc,sbin,usr/{sbin,bin},var/lock,robot,initrd}
+ # Create all the devices files we need
+ create_dev
+ # Fstab
+ install -m 755 $INITRD_CONFIG_DIR/fstab $INITRD_TEMPDIR/etc/fstab
+ # Copy the linuxrc script
+ install -m 755 $INITRD_CONFIG_DIR/linuxrc $INITRD_TEMPDIR/linuxrc
+}
+
+create_dev ()
+{
+ # Where is MAKEDEV ?
+ makedev="/dev/MAKEDEV"
+ # We have to move to the dev directory...
+ cur_dir=`pwd`
+ cd $INITRD_TEMPDIR/dev
+ # Create device
+ $makedev -v std
+ # Create the console for logging ? Useful ? XXX
+ $makedev -v consoleonly
+ # XXX Complete...
+ # Back to the originated directory
+ cd $cur_dir
+}
+
+# XXX Usefull ?
+compil_busybox ()
+{
+ # Compile a busybox for the initrd
+ # First, put the configuration file
+ #cp $INITRD_CONFIG_DIR/config-busybox $INITRD_BUSYBOX/
+ # Compile busybox
+ make -C $INITRD_BUSYBOX all 2>/dev/null
+ # Move it
+ cp $INITRD_BUSYBOX/{busybox,busybox.links} $INITRD_CONFIG_DIR/
+}
+
+fill_struct_busybox ()
+{
+ # Copy busybox in bin
+ install -m 755 $INITRD_BUSYBOX/busybox $INITRD_TEMPDIR/bin/busybox
+ # Now we can create all the links provided by busybox
+# for c in $($INITRD_TEMPDIR/bin/busybox |
+# sed -n -e '/,/s/[,\[]/ /gp')
+ # New version from applets/install.sh from busybox
+ for c in $(sort $INITRD_BUSYBOX/busybox.links | uniq)
+ do
+ # Get the directory name and the rights links
+ case "$(dirname $c)" in
+ /)
+ bb_path="bin/busybox"
+ ;;
+ /bin)
+ bb_path="busybox"
+ ;;
+ /sbin)
+ bb_path="../bin/busybox"
+ ;;
+ /usr/bin|/usr/sbin)
+ bb_path="../../bin/busybox"
+ ;;
+ *)
+ echo "Unknown installation directory: $appdir"
+ exit 1
+ ;;
+ esac
+ echo "$c -> $bb_path"
+ ln -s $bb_path $INITRD_TEMPDIR/$c
+ done
+ # We need, in ANY cases, the glibc, even in static (for gethostname
+ # function for example)
+ # In fact, even if after the compilation it said that we need the lib,
+ # we do not need it...
+ #cp /lib/libc.so.6 $INITRD_TEMPDIR/lib/
+}
+
+umount_initrd ()
+{
+ # Umount the initrd directory
+ umount $INITRD_TEMPDIR
+ # Remove temporary files
+ rmdir $INITRD_TEMPDIR
+ # Need a compression ?
+ if (( $INITRD_COMPRESS == 0 ))
+ then
+ gzip -f -9 $INITRD_OUTPUT
+ fi
+}
+
+if [ $# -gt 5 ]
+then
+ help_initrd
+fi
+while getopts "o:s:zh" option
+do
+ case $option in
+ o) INITRD_OUTPUT="$OPTARG";;
+ s) INITRD_SIZE="$OPTARG";;
+ z) INITRD_COMPRESS=1;;
+ h) help_initrd;;
+ \?) help_initrd;;
+ esac
+done
+
+create_initrd
+mount_initrd || umount_initrd
+create_empty_struct || umount_initrd
+fill_struct_busybox || umount_initrd
+umount_initrd
+
+exit 0