1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
<?xml version='1.0' encoding='ISO-8859-1'?>
<!-- This document was created with Syntext Serna Free. -->
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []>
<sect1 id="initrd">
<?dbhtml filename="initrd.html"?> <title> Building the initramfs image</title>
<note><para>This chapter is mandatory for both the livecd and the livekey.</para></note>
<para>To boot our live system, we will need an initramfs image, which will contain a couple of utilities and kernel modules, necessary to find our rootfs and mount it.
</para>
<para>Create a directory structure:</para>
<screen><userinput>mkdir -p initramfs/{bin,sbin,dev/{pts,shm},etc,proc,sys,rtmnt,lib}</userinput></screen>
<para>Copy busybox which we created in the chapter <xref linkend="busybox"/> to the bin directory</para>
<screen><userinput>cp <path-to-busybox-builddir>/busybox initramfs/bin </userinput></screen>
<para>Busybox can install symlinks for the desired utilities itself, however this can be done until the init script is running. So for some utilities that we need before this stage, we need to create the symlinks our selfs.</para>
<para><screen><userinput>ln -s /bin/busybox initramfs/bin/ash
ln -s /bin/busybox initramfs/bin/mount </userinput></screen></para>
<para>We need access to some devicenodes before udev starts:</para>
<para><screen><userinput>mknod initramfs/dev/null c 1 3
mknod initramfs/dev/tty c 5 0
mknod initramfs/dev/console c 5 1 </userinput></screen></para>
<para>Add the necessary kernel modules:</para>
<para><screen><userinput>for filename in sd_mod usbcore ehci-hcd usb-storage usb-libusual uhci-hcd ext3 mbcache jbd
do
	find /lib/modules/`uname -r` -name "$filename"* -exec cp -r --parents {} initramfs \;
done</userinput></screen></para>
<para>This will search for the given modules, and copy them to the initramfs</para>
<para>Now we need to create the initscript:</para>
<screen><userinput>cat > initramfs/init << "EOF"
#!/bin/ash
PATH=/bin:/sbin
# Mount proc and sysfs
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
# Unpack the busybox
/bin/busybox --install -s
# Add modules
if [ -z $(ls /lib/modules/) ]; then
	depmod -a
	modprobe sd_mod
	modprobe usbcore
	modprobe ehci-hcd
	modprobe usb-storage
	modprobe ext3
fi
# Check the command line
initfile="/sbin/init"
root=""
# Check the parameterlist for rootdelay
for arg in $(cat /proc/cmdline); do
	case $arg in
	rootdelay=*)
		dt=$(echo $arg | cut -d= -f2)
		sleep $dt
		;;
	esac
done
# Check the parameterlist for UUID= and LABEL=
for arg in $(cat /proc/cmdline); do
	case $arg in
	 root=*)
		option=$(echo $arg | cut -d= -f2)
		if [ $option == "LABEL" ] ; then
			root=$(findfs LABEL=$(echo $arg | cut -d= -f3))
		fi
		if [ $option == "UUID" ] ; then
			root=$(findfs UUID=$(echo $arg | cut -d= -f3))
		fi
		;;
	init=*)
		initfile=$(echo "$@" | cut -d "=" -f 2 )
		;;
	esac
done
if [ $root != "" ] ; then
	mount "${root}" /rtmnt
	if [[ -x "/rtmnt/${initfile}" ]] ; then
		umount /dev
		umount /sys
		umount /proc
		exec switch_root /rtmnt "${initfile}"
	fi
fi
# We shouldn't come here
exec ash
EOF
chmod 0755 initramfs/init</userinput></screen>
<para>Pack our stuff:</para>
<screen><userinput>cd initramfs
find ./ | cpio -H newc -o > ../initrd
cd ..
gzip initrd</userinput></screen>
<para>Keep our created initrd.gz for later use.</para>
</sect1>
|