no initrd modules stuff
[genkernel.git] / gen_initrd.sh
1 #!/bin/bash
2
3 # create_initrd_loop(size)
4 create_initrd_loop() {
5         local inodes
6         [ "$#" -ne "1" ] && gen_die "invalid use of create_initrd_loop"
7         mkdir -p ${TEMP}/initrd-mount || gen_die "could not create loopback mount dir"
8         dd if=/dev/zero of=${TEMP}/initrd-loop bs=1k count=${1} >> "${DEBUGFILE}" 2>&1 || gen_die "could not zero initrd-loop"
9         mke2fs -F -N500 -q "${TEMP}/initrd-loop" >> "${DEBUGFILE}" 2>&1 || gen_die "could not format initrd-loop"
10         mount -t ext2 -o loop "${TEMP}/initrd-loop" "${TEMP}/initrd-mount" >> "${DEBUGFILE}" 2>&1 || gen_die "could not mount initrd filesystem"
11 }
12
13 create_initrd_unmount_loop()
14 {
15         cd ${TEMP}
16         umount "${TEMP}/initrd-mount" || gen_die "could not unmount initrd system"
17 }
18
19 move_initrd_to_loop()
20 {
21         cd "${TEMP}/initrd-temp"
22         mv * "${TEMP}/initrd-mount" > ${DEBUGFILE}
23 }
24
25 create_base_initrd_sys() {
26         rm -rf "${TEMP}/initrd-temp" > /dev/null
27         mkdir -p ${TEMP}/initrd-temp/dev
28         mkdir -p ${TEMP}/initrd-temp/bin
29         mkdir -p ${TEMP}/initrd-temp/etc
30         mkdir -p ${TEMP}/initrd-temp/usr
31         mkdir -p ${TEMP}/initrd-temp/proc
32         mkdir -p ${TEMP}/initrd-temp/temp
33         mkdir -p ${TEMP}/initrd-temp/.initrd
34         mkdir -p ${TEMP}/initrd-temp/new_root
35         mkdir -p ${TEMP}/initrd-temp/keymaps
36         ln -s bin ${TEMP}/initrd-temp/sbin
37         ln -s ../bin ${TEMP}/initrd-temp/usr/bin
38         ln -s ../bin ${TEMP}/initrd-temp/usr/sbin
39         echo "/dev/ram0     /           ext2    defaults" > ${TEMP}/initrd-temp/etc/fstab
40         echo "proc          /proc       proc    defaults    0 0" >> ${TEMP}/initrd-temp/etc/fstab
41
42         echo "REGISTER        .*           MKOLDCOMPAT" > ${TEMP}/initrd-temp/etc/devfsd.conf
43         echo "UNREGISTER      .*           RMOLDCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
44         echo "REGISTER        .*           MKNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
45         echo "UNREGISTER      .*           RMNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
46
47
48         cd ${TEMP}/initrd-temp/dev
49         MAKEDEV std
50         MAKEDEV console
51
52         cp "${BUSYBOX_BINCACHE}" "${TEMP}/initrd-temp/bin/busybox.bz2" || gen_die "could not copy busybox from bincache"
53         bunzip2 "${TEMP}/initrd-temp/bin/busybox.bz2" || gen_die "could not uncompress busybox"
54         chmod +x "${TEMP}/initrd-temp/bin/busybox"
55
56         if [ "${NOINITRDMODULES}" = "" ]
57         then
58                 if [ "${PAT}" -gt "4" ]
59                 then
60                         cp "${MODULE_INIT_TOOLS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" || gen_die "could not copy insmod.static from bincache"
61                 else
62                         cp "${MODUTILS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" || gen_die "could not copy insmod.static from bincache"
63                 fi
64
65                 bunzip2 "${TEMP}/initrd-temp/bin/insmod.static.bz2" || gen_die "could not uncompress insmod.static"
66                 mv "${TEMP}/initrd-temp/bin/insmod.static" "${TEMP}/initrd-temp/bin/insmod"
67                 chmod +x "${TEMP}/initrd-temp/bin/insmod"
68         fi
69
70         cp "${DEVFSD_BINCACHE}" "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die "could not copy devfsd executable from bincache"
71         bunzip2 "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die "could not uncompress devfsd"
72         chmod +x "${TEMP}/initrd-temp/bin/devfsd"
73
74 # We make our own devfsd.conf these days, the default one doesn't work with the stripped
75 # down devfsd we use with dietlibc
76 #       cp "${DEVFSD_CONF_BINCACHE}" "${TEMP}/initrd-temp/etc/devfsd.conf.bz2" || gen_die "could not copy devfsd.conf from bincache"
77 #       bunzip2 "${TEMP}/initrd-temp/etc/devfsd.conf.bz2" || gen_die "could not uncompress devfsd.conf"
78
79         for i in '[' ash basename cat chroot clear cp dirname echo env false find \
80         grep gunzip gzip ln ls loadkmap losetup lsmod mkdir mknod more mount mv \
81         pivot_root ps awk pwd rm rmdir rmmod sh sleep tar test touch true umount uname \
82         xargs yes zcat chmod chown cut kill killall; do
83                 rm -f ${TEMP}/initrd-temp/bin/$i > /dev/null
84                 ln  ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i || gen_die "could not link ${i}"
85         done
86 }
87
88 print_list()
89 {
90         local x
91         for x in ${*}
92         do
93                 echo ${x}
94         done
95 }
96
97 create_initrd_modules() {
98         if [ "${PAT}" -gt "4" ]
99         then
100                 MOD_EXT=".ko"
101         else
102                 MOD_EXT=".o"
103         fi
104         for i in `gen_dep_list`
105         do
106                 print_info 2 "$i : module searching" 1 0
107                 mymod=`find /lib/modules/${KV} -name "${i}${MOD_EXT}"`
108                 if [ -z "${mymod}" ]
109                 then
110                         print_info 2 "Warning : ${i}${MOD_EXT} not found; skipping..."
111                         continue;
112                 fi
113                 print_info 2 "copying ${mymod} to initrd"
114                 cp -ax --parents "${mymod}" "${TEMP}/initrd-temp"
115         done
116
117         cp -ax --parents /lib/modules/${KV}/modules* ${TEMP}/initrd-temp
118
119         mkdir -p "${TEMP}/initrd-temp/etc/modules"
120         print_list ${SCSI_MODULES} > "${TEMP}/initrd-temp/etc/modules/scsi"
121         print_list ${FIREWIRE_MODULES} > "${TEMP}/initrd-temp/etc/modules/firewire"
122         print_list ${ATARAID_MODULES} > "${TEMP}/initrd-temp/etc/modules/ataraid"
123         print_list ${PCMCIA_MODULES} > "${TEMP}/initrd-temp/etc/modules/pcmcia"
124         print_list ${USB_MODULES} > "${TEMP}/initrd-temp/etc/modules/usb"
125 }
126
127 create_initrd_aux() {
128         if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
129         then
130                 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
131         else
132                 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
133         fi
134
135         if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
136         then
137                 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
138         else    
139                 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
140         fi
141
142         if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
143         then
144                 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
145         else
146                 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
147         fi
148         if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
149         then
150                 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
151         else
152                 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
153         fi
154
155         chmod +x "${TEMP}/initrd-temp/linuxrc"
156         chmod +x "${TEMP}/initrd-temp/etc/initrd.scripts"
157         chmod +x "${TEMP}/initrd-temp/etc/initrd.defaults"
158         chmod +x "${TEMP}/initrd-temp/sbin/modprobe"
159
160 }
161
162 calc_initrd_size() {
163         local TEST
164         cd ${TEMP}/initrd-temp/
165         TEST=`du -sk 2> /dev/null` 
166         echo $TEST | cut "-d " -f1
167 }
168
169 create_initrd() {
170         local MOD_EXT
171
172         print_info 1 "initrd: creating base system"
173         create_base_initrd_sys
174
175         if [ "${NOINITRDMODULES}" = "" ]
176         then
177                 print_info 1 "initrd: copying modules"
178                 create_initrd_modules
179         else
180                 print_info 1 "initrd: not copying modules"
181         fi
182
183         print_info 1 "initrd: copying auxilary files"
184         create_initrd_aux
185
186         print_info 1 "initrd: calculating initrd size"
187         INITRD_CALC_SIZE=`calc_initrd_size`
188
189         print_info 1 "initrd: calculated size ${INITRD_CALC_SIZE} + 100k slop for fs overhead"
190         INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 100`
191
192         print_info 1 "initrd: real size ${INITRD_SIZE}"
193
194         print_info 1 "initrd: creating loopback filesystem"
195         create_initrd_loop ${INITRD_SIZE}
196
197         print_info 1 "initrd: moving initrd fs to loopback"
198         move_initrd_to_loop
199
200         print_info 1 "initrd: cleaning up and compressing initrd"
201         create_initrd_unmount_loop
202
203         if [ "${COMPRESS_INITRD}" ]
204         then
205                 gzip -f -9 ${TEMP}/initrd-loop
206                 mv ${TEMP}/initrd-loop.gz ${TEMP}/initrd-loop
207         fi
208
209         if [ "${BOOTSPLASH}" -eq "1" ]
210         then
211                 print_info 1 "initrd: copying bootsplash"
212                 /sbin/splash -s -f /etc/bootsplash/gentoo/config/bootsplash-800x600.cfg >> ${TEMP}/initrd-loop || gen_die "could not copy 800x600 bootsplash"
213                 /sbin/splash -s -f /etc/bootsplash/gentoo/config/bootsplash-1024x768.cfg >> ${TEMP}/initrd-loop || gen_die "could not copy 1024x768 bootsplash"
214                 /sbin/splash -s -f /etc/bootsplash/gentoo/config/bootsplash-1280x1024.cfg >> ${TEMP}/initrd-loop || gen_die "could not copy 1280x1024 bootsplash"
215                 /sbin/splash -s -f /etc/bootsplash/gentoo/config/bootsplash-1600x1200.cfg >> ${TEMP}/initrd-loop || gen_die "could not copy 1600x1200 bootsplash"
216         fi
217         cp ${TEMP}/initrd-loop /boot/initrd-${KV} || gen_die "could not copy initrd to boot"
218 }
219