3 CPIO_ARGS="--quiet -o -H newc"
6 if [ -d "${TEMP}/initramfs-base-temp" ]
8 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
10 mkdir -p ${TEMP}/initramfs-base-temp/dev
11 mkdir -p ${TEMP}/initramfs-base-temp/bin
12 mkdir -p ${TEMP}/initramfs-base-temp/etc
13 mkdir -p ${TEMP}/initramfs-base-temp/usr
14 mkdir -p ${TEMP}/initramfs-base-temp/proc
15 mkdir -p ${TEMP}/initramfs-base-temp/temp
16 mkdir -p ${TEMP}/initramfs-base-temp/sys
17 mkdir -p ${TEMP}/initramfs-temp/.initrd
18 mkdir -p ${TEMP}/initramfs-base-temp/var/lock/dmraid
19 mkdir -p ${TEMP}/initramfs-base-temp/sbin
20 mkdir -p ${TEMP}/initramfs-base-temp/usr/bin
21 mkdir -p ${TEMP}/initramfs-base-temp/usr/sbin
22 ln -s lib ${TEMP}/initramfs-base-temp/lib64
24 echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initramfs-base-temp/etc/fstab
25 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initramfs-base-temp/etc/fstab
27 cd ${TEMP}/initramfs-base-temp/dev
28 mknod -m 660 console c 5 1
29 mknod -m 660 null c 1 3
30 mknod -m 600 tty1 c 4 1
31 cd "${TEMP}/initramfs-base-temp/"
32 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
33 rm -rf "${TEMP}/initramfs-base-temp" > /dev/null
37 if [ -d "${TEMP}/initramfs-busybox-temp" ]
39 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
41 mkdir -p "${TEMP}/initramfs-busybox-temp/bin/"
43 cp "${GK_SHARE}/generic/udhcpc.scripts" ${TEMP}/initramfs-busybox-temp/bin/
44 chmod +x "${TEMP}/initramfs-busybox-temp/bin/udhcpc.scripts"
45 tar -xjf "${BUSYBOX_BINCACHE}" -C "${TEMP}/initramfs-busybox-temp/bin" busybox ||
46 gen_die 'Could not extract busybox bincache!'
47 chmod +x "${TEMP}/initramfs-busybox-temp/bin/busybox"
49 for i in '[' ash sh mount uname echo cut; do
50 rm -f ${TEMP}/initramfs-busybox-temp/bin/$i > /dev/null
51 ln ${TEMP}/initramfs-busybox-temp/bin/busybox ${TEMP}/initramfs-busybox-temp/bin/$i ||
52 gen_die "Busybox error: could not link ${i}!"
55 cd "${TEMP}/initramfs-busybox-temp/"
56 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
57 rm -rf "${TEMP}/initramfs-busybox-temp" > /dev/null
61 if [ -d "${TEMP}/initramfs-blkid-temp" ]
63 rm -r "${TEMP}/initramfs-blkid-temp/"
66 mkdir -p "${TEMP}/initramfs-blkid-temp/bin/"
67 [ "${DISKLABEL}" -eq '1' ] && { /bin/bzip2 -dc "${BLKID_BINCACHE}" > "${TEMP}/initramfs-blkid-temp/bin/blkid" ||
68 gen_die "Could not extract blkid binary cache!"; }
69 chmod a+x "${TEMP}/initramfs-blkid-temp/bin/blkid"
70 cd "${TEMP}/initramfs-blkid-temp/"
71 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
72 rm -rf "${TEMP}/initramfs-blkid-temp" > /dev/null
76 # if [ -d "${TEMP}/initramfs-suspend-temp" ];
78 # rm -r "${TEMP}/initramfs-suspend-temp/"
80 # print_info 1 'SUSPEND: Adding support (compiling binaries)...'
82 # mkdir -p "${TEMP}/initramfs-suspend-temp/"
83 # /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" ||
84 # gen_die "Could not extract suspend binary cache!"
85 # mkdir -p "${TEMP}/initramfs-suspend-temp/etc"
86 # cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" ||
87 # gen_die 'Could not copy /etc/suspend.conf'
88 # cd "${TEMP}/initramfs-suspend-temp/"
89 # find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
90 # rm -r "${TEMP}/initramfs-suspend-temp/"
94 if [ -d "${TEMP}/initramfs-dmraid-temp" ]
96 rm -r "${TEMP}/initramfs-dmraid-temp/"
98 print_info 1 'DMRAID: Adding support (compiling binaries)...'
100 mkdir -p "${TEMP}/initramfs-dmraid-temp/"
101 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initramfs-dmraid-temp" ||
102 gen_die "Could not extract dmraid binary cache!";
103 cd "${TEMP}/initramfs-dmraid-temp/"
104 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
105 rm -r "${TEMP}/initramfs-dmraid-temp/"
109 if [ -d "${TEMP}/initramfs-lvm-temp" ]
111 rm -r "${TEMP}/initramfs-lvm-temp/"
114 mkdir -p "${TEMP}/initramfs-lvm-temp/bin/"
115 mkdir -p "${TEMP}/initramfs-lvm-temp/etc/lvm/"
116 if [ -e '/sbin/lvm' ] && LC_ALL="C" ldd /sbin/lvm|grep -q 'not a dynamic executable'
118 print_info 1 ' LVM: Adding support (using local static binaries)...'
119 cp /sbin/lvm "${TEMP}/initramfs-lvm-temp/bin/lvm" ||
120 gen_die 'Could not copy over lvm!'
122 print_info 1 ' LVM: Adding support (compiling binaries)...'
124 /bin/tar -jxpf "${LVM_BINCACHE}" -C "${TEMP}/initramfs-lvm-temp" ||
125 gen_die "Could not extract lvm binary cache!";
126 mv ${TEMP}/initramfs-lvm-temp/sbin/lvm.static ${TEMP}/initramfs-lvm-temp/bin/lvm ||
127 gen_die 'LVM error: Could not move lvm.static to lvm!'
131 # lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
135 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm-temp/etc/lvm/" ||
136 gen_die 'Could not copy over lvm.conf!'
138 # gen_die 'Could not copy over lvm.conf!'
141 cd "${TEMP}/initramfs-lvm-temp/"
142 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
143 rm -r "${TEMP}/initramfs-lvm-temp/"
147 if [ -d "${TEMP}/initramfs-evms-temp" ]
149 rm -r "${TEMP}/initramfs-evms-temp/"
151 mkdir -p "${TEMP}/initramfs-evms-temp/lib/evms"
152 mkdir -p "${TEMP}/initramfs-evms-temp/etc/"
153 mkdir -p "${TEMP}/initramfs-evms-temp/bin/"
154 mkdir -p "${TEMP}/initramfs-evms-temp/sbin/"
155 if [ "${EVMS}" -eq '1' ]
157 print_info 1 ' EVMS: Adding support...'
158 mkdir -p ${TEMP}/initramfs-evms-temp/lib
159 cp -a /lib/ld-* "${TEMP}/initramfs-evms-temp/lib" \
160 || gen_die 'Could not copy files for EVMS!'
161 if [ -n "`ls /lib/libgcc_s*`" ]
163 cp -a /lib/libgcc_s* "${TEMP}/initramfs-evms-temp/lib" \
164 || gen_die 'Could not copy files for EVMS!'
166 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initramfs-evms-temp/lib" \
167 || gen_die 'Could not copy files for EVMS!'
168 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initramfs-evms-temp/lib" \
169 || gen_die 'Could not copy files for EVMS!'
170 cp -a /lib/libpthread* "${TEMP}/initramfs-evms-temp/lib" \
171 || gen_die 'Could not copy files for EVMS!'
172 cp -a /lib/libuuid*so* "${TEMP}/initramfs-evms-temp/lib" \
173 || gen_die 'Could not copy files for EVMS!'
174 cp -a /lib/libevms*so* "${TEMP}/initramfs-evms-temp/lib" \
175 || gen_die 'Could not copy files for EVMS!'
176 cp -a /lib/evms "${TEMP}/initramfs-evms-temp/lib" \
177 || gen_die 'Could not copy files for EVMS!'
178 cp -a /lib/evms/* "${TEMP}/initramfs-evms-temp/lib/evms" \
179 || gen_die 'Could not copy files for EVMS!'
180 cp -a /etc/evms.conf "${TEMP}/initramfs-evms-temp/etc" \
181 || gen_die 'Could not copy files for EVMS!'
182 cp /sbin/evms_activate "${TEMP}/initramfs-evms-temp/sbin" \
183 || gen_die 'Could not copy over evms_activate!'
185 # Fix EVMS complaining that it can't find the swap utilities.
186 # These are not required in the initramfs
187 for swap_libs in "${TEMP}/initramfs-evms-temp/lib/evms/*/swap*.so"
192 cd "${TEMP}/initramfs-evms-temp/"
193 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
194 rm -r "${TEMP}/initramfs-evms-temp/"
198 if [ -d "${TEMP}/initramfs-mdadm-temp" ]
200 rm -r "${TEMP}/initramfs-mdadm-temp/"
203 mkdir -p "${TEMP}/initramfs-mdadm-temp/etc/"
204 if [ "${MDADM}" -eq '1' ]
206 cp -a /etc/mdadm.conf "${TEMP}/initramfs-mdadm-temp/etc" \
207 || gen_die "Could not copy mdadm.conf!"
209 cd "${TEMP}/initramfs-mdadm-temp/"
210 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
211 rm -rf "${TEMP}/initramfs-mdadm-temp" > /dev/null
215 splash_geninitramfs=`which splash_geninitramfs 2>1&`
216 if [ -x ${splash_geninitramfs} ]
218 [ -z "${SPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
219 [ -z "${SPLASH_THEME}" ] && SPLASH_THEME=default
220 print_info 1 " >> Installing splash [ using the ${SPLASH_THEME} theme ]..."
221 if [ -d "${TEMP}/initramfs-splash-temp" ]
223 rm -r "${TEMP}/initramfs-splash-temp/"
225 mkdir -p "${TEMP}/initramfs-splash-temp"
228 [ -n "${SPLASH_RES}" ] && tmp="-r ${SPLASH_RES}"
229 splash_geninitramfs -c "${TEMP}/initramfs-splash-temp" ${tmp} ${SPLASH_THEME} || gen_die "Could not build splash cpio archive"
230 if [ -e "/usr/share/splashutils/initrd.splash" ]; then
231 mkdir -p "${TEMP}/initramfs-splash-temp/etc"
232 cp -f "/usr/share/splashutils/initrd.splash" "${TEMP}/initramfs-splash-temp/etc"
234 cd "${TEMP}/initramfs-splash-temp/"
235 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}" \
236 || gen_die "compressing splash cpio"
237 rm -r "${TEMP}/initramfs-splash-temp/"
239 print_warning 1 ' >> No splash detected; skipping!'
244 cd ${INITRAMFS_OVERLAY}
245 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
261 print_info 2 "initramfs: >> Searching for modules..."
262 if [ "${INSTALL_MOD_PATH}" != '' ]
264 cd ${INSTALL_MOD_PATH}
269 if [ -d "${TEMP}/initramfs-modules-${KV}-temp" ]
271 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
273 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/lib/modules/${KV}"
274 for i in `gen_dep_list`
276 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1 `
279 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
283 print_info 2 "initramfs: >> Copying ${i}${MOD_EXT}..."
284 cp -ax --parents "${mymod}" "${TEMP}/initramfs-modules-${KV}-temp"
287 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initramfs-modules-${KV}-temp 2>/dev/null
289 mkdir -p "${TEMP}/initramfs-modules-${KV}-temp/etc/modules"
290 for group_modules in ${!MODULES_*}; do
291 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
292 print_list ${!group_modules} > "${TEMP}/initramfs-modules-${KV}-temp/etc/modules/${group}"
294 cd "${TEMP}/initramfs-modules-${KV}-temp/"
295 find . | cpio ${CPIO_ARGS} --append -F "${CPIO}"
297 rm -r "${TEMP}/initramfs-modules-${KV}-temp/"
300 # check for static linked file with objdump
302 LANG="C" LC_ALL="C" objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
307 if [ -d "${TEMP}/initramfs-aux-temp" ]
309 rm -r "${TEMP}/initramfs-aux-temp/"
311 mkdir -p "${TEMP}/initramfs-aux-temp/etc"
312 mkdir -p "${TEMP}/initramfs-aux-temp/sbin"
313 if [ -f "${CMD_LINUXRC}" ]
315 cp "${CMD_LINUXRC}" "${TEMP}/initramfs-aux-temp/init"
316 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC} to init"
318 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
320 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initramfs-aux-temp/init"
322 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initramfs-aux-temp/init"
326 # Make sure it's executable
327 chmod 0755 "${TEMP}/initramfs-aux-temp/init"
329 # Make a symlink to init .. incase we are bundled inside the kernel as one
331 cd ${TEMP}/initramfs-aux-temp
333 # ln ${TEMP}/initramfs-aux-temp/init ${TEMP}/initramfs-aux-temp/linuxrc
335 if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
337 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
339 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
342 if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
344 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
346 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
349 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
350 for group_modules in ${!MODULES_*}; do
351 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
352 echo -n "${group} " >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
354 echo '"' >> "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
356 if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
358 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
360 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initramfs-aux-temp/sbin/modprobe"
362 if isTrue $CMD_DOKEYMAPAUTO
364 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
366 mkdir -p "${TEMP}/initramfs-aux-temp/lib/keymaps"
367 /bin/tar -C "${TEMP}/initramfs-aux-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
368 if isTrue $CMD_SLOWUSB
370 echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initramfs-aux-temp/etc/initrd.defaults
374 if is_static /bin/cryptsetup
376 print_info 1 "Including LUKS support"
377 rm -f ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
378 cp /bin/cryptsetup ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
379 chmod +x "${TEMP}/initramfs-aux-temp/sbin/cryptsetup"
380 elif is_static /sbin/cryptsetup
382 print_info 1 "Including LUKS support"
383 rm -f ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
384 cp /sbin/cryptsetup ${TEMP}/initramfs-aux-temp/sbin/cryptsetup
385 chmod +x "${TEMP}/initramfs-aux-temp/sbin/cryptsetup"
388 print_info 1 "LUKS support requires static cryptsetup at /bin/cryptsetup or /sbin/cryptsetup"
389 print_info 1 "Not including LUKS support"
393 cd ${TEMP}/initramfs-aux-temp/sbin && ln -s ../init init
395 chmod +x "${TEMP}/initramfs-aux-temp/init"
396 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.scripts"
397 chmod +x "${TEMP}/initramfs-aux-temp/etc/initrd.defaults"
398 chmod +x "${TEMP}/initramfs-aux-temp/sbin/modprobe"
399 cd "${TEMP}/initramfs-aux-temp/"
400 find . -print | cpio ${CPIO_ARGS} --append -F "${CPIO}"
402 rm -r "${TEMP}/initramfs-aux-temp/"
407 local func="append_${name}"
409 if [ $# -eq 1 ] || [ ${var} -eq 1 ]
411 print_info 1 " >> Appending ${name} cpio data..."
417 print_info 1 "initramfs: >> Initializing..."
420 CPIO="${TMPDIR}/initramfs-${KV}"
421 echo | cpio ${CPIO_ARGS} -F "${CPIO}" 2>/dev/null \
422 || gen_die "Could not create empty cpio at ${CPIO}"
424 append_data 'base_layout'
425 append_data 'auxilary'
426 append_data 'busybox' "${BUSYBOX}"
427 append_data 'lvm' "${LVM}"
428 append_data 'dmraid' "${DMRAID}"
429 append_data 'evms' "${EVMS}"
430 append_data 'mdadm' "${MDADM}"
432 if [ "${NOINITRDMODULES}" -eq '0' ]
434 append_data 'modules'
436 print_info 1 "initramfs: Not copying modules..."
439 append_data 'blkid' "${DISKLABEL}"
440 append_data 'splash' "${SPLASH}"
442 # This should always be appended last
443 if [ "${INITRAMFS_OVERLAY}" != '' ]
445 append_data 'overlay'
449 mv -f "${CPIO}.gz" "${CPIO}"
451 if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
453 # Pegasos hack for merging the initramfs into the kernel at compile time
454 cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/arch/powerpc/boot/ramdisk.image.gz &&
455 rm ${TMPDIR}/initramfs-${KV}
456 elif [ ${BUILD_INITRAMFS} -eq '1' ]
458 # Mips also mimics Pegasos to merge the initramfs into the kernel
459 cp ${TMPDIR}/initramfs-${KV} ${KERNEL_DIR}/initramfs.cpio.gz
460 gunzip -f ${KERNEL_DIR}/initramfs.cpio.gz
463 if ! isTrue "${CMD_NOINSTALL}"
465 if [ "${ENABLE_PEGASOS_HACKS}" != 'yes' ]
467 copy_image_with_preserve "initramfs" \
468 "${TMPDIR}/initramfs-${KV}" \
469 "initramfs-${KNAME}-${ARCH}-${KV}"