Skip to content

Commit ec9315e

Browse files
committed
Initial commit
First pass at a new initrd implementation. Right now, it's a very simple /init and we use nash's switchroot command via switch_root. The idea is to get a switchroot binary into util-linux that can be used instead generate.sh will let you generate an initrd image. Note that the generator is intentionally super simple right now and is an area that will need a lot of work once we're happier with how the /init process runs
0 parents  commit ec9315e

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

generate.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#/bin/bash
2+
# Simple script that creates the tree to use for a new initrd
3+
# note that this is not intended to be pretty, nice or anything
4+
# of the sort. the important thing is working
5+
6+
7+
source /usr/libexec/initrd-functions
8+
9+
INITRDOUT=$1
10+
if [ -z "$INITRDOUT" ]; then
11+
echo "Please specify an initrd file to output"
12+
exit 1
13+
fi
14+
15+
tmpdir=$(mktemp -d)
16+
17+
# executables that we have to have
18+
exe="/bin/bash /bin/mount /bin/mknod /bin/mkdir /sbin/modprobe /sbin/udevd /sbin/udevadm /sbin/nash"
19+
# and some things that are nice for debugging
20+
debugexe="/bin/ls /bin/cat /bin/ln /bin/ps /bin/grep /usr/bin/less"
21+
22+
# install base files
23+
for binary in $exe $debugexe ; do
24+
inst $binary $tmpdir
25+
done
26+
27+
# install our files
28+
inst init $tmpdir/init
29+
inst switch_root $tmpdir/sbin/switch_root
30+
31+
# FIXME: we don't install modules right now, but for the testing we're doing
32+
# everything is already built-in
33+
34+
pushd $tmpdir >/dev/null
35+
find . |cpio -H newc -o |gzip -9 > $INITRDOUT
36+
popd >/dev/null

init

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
emergency_shell()
4+
{
5+
echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!"
6+
echo
7+
bash
8+
}
9+
trap "emergency_shell" 0 2
10+
11+
echo "Starting initrd..."
12+
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
13+
export TERM=linux
14+
15+
# /dev/console comes from the built-in initramfs crud in the kernel
16+
# someday, we may need to mkdir /dev first here
17+
exec > /dev/console 2>&1
18+
19+
# mount some important things
20+
mkdir /proc
21+
mount -t proc /proc /proc
22+
mkdir /sys
23+
mount -t sysfs /sys /sys
24+
mount -t tmpfs -omode=0755 udev /dev
25+
26+
# start up udev and trigger cold plugs
27+
/sbin/udevd --daemon
28+
/sbin/udevadm trigger
29+
# FIXME: should we really wait for the queue to settle or just try to
30+
# find the rootfs?
31+
/sbin/udevadm settle --timeout=30 || :
32+
33+
34+
NEWROOT=/sysroot
35+
# mount the rootfs
36+
mkdir $NEWROOT
37+
# FIXME: obviously we need to parse this from /proc/cmdline
38+
mount -o ro -t ext3 /dev/sda1 $NEWROOT
39+
40+
# now we need to prepare to switchroot
41+
mount --bind /dev $NEWROOT/dev
42+
43+
# FIXME: now for a bunch of boiler-plate mounts. really, we should have
44+
# some like /etc/fstab.sys that's provided by filesystem/initscripts
45+
# and then do mount -f /etc/fstab.sys -a
46+
mount -t proc /proc $NEWROOT/proc
47+
mount -t sysfs /sys $NEWROOT/sys
48+
49+
# FIXME: load selinux policy
50+
51+
# FIXME: nash die die die
52+
exec /sbin/switch_root
53+
# davej doesn't like initrd bugs
54+
echo "Something went very badly wrong in the initrd. Please "
55+
echo "file a bug against mkinitrd."
56+
exit 1

switch_root

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/sbin/nash
2+
3+
switchroot

0 commit comments

Comments
 (0)