summaryrefslogtreecommitdiffstats
path: root/initrd.xml
blob: 3b03aabf3495b020c7a557094edf1d0c74f6585f (plain)
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 &lt;path-to-busybox-builddir&gt;/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
&#009;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 &gt; initramfs/init &lt;&lt; &quot;EOF&quot; 
#!/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

&#009;depmod -a

&#009;modprobe sd_mod
&#009;modprobe usbcore
&#009;modprobe ehci-hcd
&#009;modprobe usb-storage
&#009;modprobe ext3

fi

# Check the command line 

initfile=&quot;/sbin/init&quot;
root=&quot;&quot;

# Check the parameterlist for rootdelay 

for arg in $(cat /proc/cmdline); do
&#009;case $arg in

&#009;rootdelay=*)
&#009;&#009;dt=$(echo $arg | cut -d= -f2)
&#009;&#009;sleep $dt
&#009;&#009;;;
&#009;esac
done

# Check the parameterlist for UUID= and LABEL=

for arg in $(cat /proc/cmdline); do
&#009;case $arg in

&#009; root=*)
&#009;&#009;option=$(echo $arg | cut -d= -f2)

&#009;&#009;if [ $option == &quot;LABEL&quot; ] ; then
&#009;&#009;&#009;root=$(findfs LABEL=$(echo $arg | cut -d= -f3))
&#009;&#009;fi

&#009;&#009;if [ $option == &quot;UUID&quot; ] ; then
&#009;&#009;&#009;root=$(findfs UUID=$(echo $arg | cut -d= -f3))
&#009;&#009;fi

&#009;&#009;;;

&#009;init=*)
&#009;&#009;initfile=$(echo &quot;$@&quot; | cut -d &quot;=&quot; -f 2 )

&#009;&#009;;;

&#009;esac
done

if [ $root != &quot;&quot; ] ; then

&#009;mount &quot;${root}&quot; /rtmnt

&#009;if [[ -x &quot;/rtmnt/${initfile}&quot; ]] ; then

&#009;&#009;umount /dev
&#009;&#009;umount /sys 
&#009;&#009;umount /proc

&#009;&#009;exec switch_root /rtmnt &quot;${initfile}&quot;
&#009;fi
fi

# We shouldn&apos;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 &gt; ../initrd 
cd .. 
gzip initrd</userinput></screen>
<para>Keep our created initrd.gz for later use.</para>
</sect1>