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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>4.1.� Building the initramfs image</title><link rel="stylesheet" href="stylesheets/lfs.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><link rel="stylesheet" href="stylesheets/lfs-print.css" type="text/css" media="print" /></head><body class="lfs" id="lfs-0.3"><div class="navheader"><h4>LFS live howto - Version 0.3</h4><h3>Chapter�4.�initrd</h3><ul><li class="prev"><a accesskey="p" href="ch04.html" title="initrd">Prev</a><p>initrd</p></li><li class="next"><a accesskey="n" href="ch05.html" title="Preparing install">Next</a><p>Preparing install</p></li><li class="up"><a accesskey="u" href="ch04.html" title="Chapter�4.�initrd">Up</a></li><li class="home"><a accesskey="h" href="index.html" title="LFS live howto - Version 0.3">Home</a></li></ul></div><div class="sect1" lang="en" xml:lang="en"><h1 class="sect1"><a id="initrd" name="initrd"></a>4.1. Building the initramfs image</h1><div class="admon note"><img alt="[Note]" src="images/note.png" /><h3>Note</h3><p>This chapter is mandatory for both the livecd and the livekey.</p></div><p>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.
</p><p>Create a directory structure:</p><pre class="userinput"><kbd class="command">mkdir -p initramfs/{bin,sbin,dev/{pts,shm},etc,proc,sys,rtmnt,lib}</kbd></pre><p>Copy busybox which we created in the chapter <a class="xref" href="busybox.html" title="2.4.�busybox 1.19.2">busybox 1.19.2</a> to the bin directory</p><pre class="userinput"><kbd class="command">cp <path-to-busybox-builddir>/busybox initramfs/bin </kbd></pre><p>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.</p><pre class="userinput"><kbd class="command">ln -s /bin/busybox initramfs/bin/ash
ln -s /bin/busybox initramfs/bin/mount </kbd></pre><p>We need access to some devicenodes before udev starts:</p><pre class="userinput"><kbd class="command">mknod initramfs/dev/null c 1 3
mknod initramfs/dev/tty c 5 0
mknod initramfs/dev/console c 5 1 </kbd></pre><p>Add the necessary kernel modules:</p><pre class="userinput"><kbd class="command">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</kbd></pre><p>This will search for the given modules, and copy them to the initramfs</p><p>Now we need to create the initscript:</p><pre class="userinput"><kbd class="command">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</kbd></pre><p>Pack our stuff:</p><pre class="userinput"><kbd class="command">cd initramfs
find ./ | cpio -H newc -o > ../initrd
cd ..
gzip initrd</kbd></pre><p>Keep our created initrd.gz for later use.</p></div><div class="navfooter"><ul><li class="prev"><a accesskey="p" href="ch04.html" title="initrd">Prev</a><p>initrd</p></li><li class="next"><a accesskey="n" href="ch05.html" title="Preparing install">Next</a><p>Preparing install</p></li><li class="up"><a accesskey="u" href="ch04.html" title="Chapter�4.�initrd">Up</a></li><li class="home"><a accesskey="h" href="index.html" title="LFS live howto - Version 0.3">Home</a></li></ul></div></body></html>
|