3 # create_initrd_loop(size)
6 [ "$#" -ne '1' ] && gen_die 'create_initrd_loop(): Not enough arguments!'
7 mkdir -p ${TEMP}/initrd-mount ||
8 gen_die 'Could not create loopback mount directory!'
9 dd if=/dev/zero of=${TMPDIR}/initrd-${KV} bs=1k count=${1} >> "${DEBUGFILE}" 2>&1 ||
10 gen_die "Could not zero initrd-${KV}"
11 mke2fs -F -N750 -q "${TMPDIR}/initrd-${KV}" >> "${DEBUGFILE}" 2>&1 ||
12 gen_die "Could not format initrd-${KV}!"
13 mount -t ext2 -o loop "${TMPDIR}/initrd-${KV}" "${TEMP}/initrd-mount" >> "${DEBUGFILE}" 2>&1 ||
14 gen_die 'Could not mount the initrd filesystem!'
17 create_initrd_unmount_loop()
20 umount "${TEMP}/initrd-mount" ||
21 gen_die 'Could not unmount initrd system!'
26 cd "${TEMP}/initrd-temp"
27 mv * "${TEMP}/initrd-mount" >> ${DEBUGFILE} 2>&1
30 # check for static linked file with objdump
32 objdump -T $1 2>&1 | grep "not a dynamic object" > /dev/null
36 create_base_initrd_sys() {
37 rm -rf "${TEMP}/initrd-temp" > /dev/null
38 mkdir -p ${TEMP}/initrd-temp/dev
39 mkdir -p ${TEMP}/initrd-temp/bin
40 mkdir -p ${TEMP}/initrd-temp/etc
41 mkdir -p ${TEMP}/initrd-temp/usr
42 mkdir -p ${TEMP}/initrd-temp/proc
43 mkdir -p ${TEMP}/initrd-temp/temp
44 mkdir -p ${TEMP}/initrd-temp/sys
45 mkdir -p ${TEMP}/initrd-temp/.initrd
46 mkdir -p ${TEMP}/initrd-temp/var/lock/dmraid
47 ln -s bin ${TEMP}/initrd-temp/sbin
48 ln -s ../bin ${TEMP}/initrd-temp/usr/bin
49 ln -s ../bin ${TEMP}/initrd-temp/usr/sbin
51 echo "/dev/ram0 / ext2 defaults 0 0" > ${TEMP}/initrd-temp/etc/fstab
52 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initrd-temp/etc/fstab
54 if [ "${NODEVFSD}" = '' ]
56 echo "REGISTER .* MKOLDCOMPAT" > ${TEMP}/initrd-temp/etc/devfsd.conf
57 echo "UNREGISTER .* RMOLDCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
58 echo "REGISTER .* MKNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
59 echo "UNREGISTER .* RMNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
62 # SGI LiveCDs need the following binary (no better place for it than here)
63 # getdvhoff is a DEPEND of genkernel, so it *should* exist
64 if [ ${BUILD_INITRAMFS} -eq 1 ]
66 [ -e /usr/lib/getdvhoff/getdvhoff ] \
67 && cp /usr/lib/getdvhoff/getdvhoff ${TEMP}/initrd-temp/bin \
68 || gen_die "sys-boot/getdvhoff not merged!"
71 cd ${TEMP}/initrd-temp/dev
75 if [ "${DISKLABEL}" -eq '1' ]; then
76 cp "${BLKID_BINCACHE}" "${TEMP}/initrd-temp/bin/blkid.bz2" ||
77 gen_die 'Could not copy blkid from bincache!'
78 bunzip2 "${TEMP}/initrd-temp/bin/blkid.bz2" ||
79 gen_die 'Could not uncompress blkid!'
80 chmod +x "${TEMP}/initrd-temp/bin/blkid"
83 cp "${BUSYBOX_BINCACHE}" "${TEMP}/initrd-temp/bin/busybox.bz2" ||
84 gen_die 'Could not copy busybox from bincache!'
85 bunzip2 "${TEMP}/initrd-temp/bin/busybox.bz2" ||
86 gen_die 'Could not uncompress busybox!'
87 chmod +x "${TEMP}/initrd-temp/bin/busybox"
89 if [ "${NOINITRDMODULES}" = '' ]
91 if [ "${PAT}" -gt "4" ]
93 cp "${MODULE_INIT_TOOLS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
94 gen_die 'Could not copy insmod.static from bincache!'
96 cp "${MODUTILS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
97 gen_die 'Could not copy insmod.static from bincache'
100 bunzip2 "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
101 gen_die 'Could not uncompress insmod.static!'
102 mv "${TEMP}/initrd-temp/bin/insmod.static" "${TEMP}/initrd-temp/bin/insmod"
103 chmod +x "${TEMP}/initrd-temp/bin/insmod"
107 if [ "${DEVFS}" -eq '1' ]
109 cp "${DEVFSD_BINCACHE}" "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die 'Could not copy devfsd executable from bincache!'
110 bunzip2 "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die 'Could not uncompress devfsd!'
111 chmod +x "${TEMP}/initrd-temp/bin/devfsd"
115 # if [ "${UDEV}" -eq '1' ]
117 # /bin/tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initrd-temp" || gen_die 'Could not extract udev binary cache!'
118 # if [ ! -e "${TEMP}/initrd-temp/bin/udevstart" ]
120 # ln -sf "./udev" "${TEMP}/initrd-temp/bin/udevstart" || gen_die 'Could not symlink udev -> udevstart!'
123 # if [ ! -e "${TEMP}/initrd-temp/bin/udevsend" ]
125 # ln -sf "./udev" "${TEMP}/initrd-temp/bin/udevsend" || gen_die 'Could not symlink udev -> udevsend!'
130 if [ "${UNIONFS}" -eq '1' ]
132 print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
133 compile_unionfs_modules
134 /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initrd-temp" ||
135 gen_die "Could not extract unionfs modules binary cache!";
139 if [ "${UNIONFS}" -eq '1' ]
141 print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
142 compile_unionfs_utils
143 /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initrd-temp" ||
144 gen_die "Could not extract unionfs tools binary cache!";
148 if [ "${SUSPEND}" = '1' ]
150 print_info 1 'SUSPEND: Adding support (compiling binaries)...'
152 /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initrd-temp" ||
153 gen_die "Could not extract suspend binary cache!"
154 mkdir -p "${TEMP}/initrd-temp/etc"
155 cp -f /etc/suspend.conf "${TEMP}/initrd-temp/etc" ||
156 gen_die 'Could not copy /etc/suspend.conf'
160 if [ "${DMRAID}" = '1' ]
162 print_info 1 'DMRAID: Adding support (compiling binaries)...'
164 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initrd-temp" ||
165 gen_die "Could not extract dmraid binary cache!";
169 if [ "${LVM2}" = '1' ]
171 if [ -e '/sbin/lvm' ] && ldd /sbin/lvm|grep -q 'not a dynamic executable';
173 print_info 1 'LVM2: Adding support (using local static binaries)...'
174 cp /sbin/lvm "${TEMP}/initrd-temp/bin/lvm" ||
175 gen_die 'Could not copy over lvm!'
177 print_info 1 'LVM2: Adding support (compiling binaries)...'
180 /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initrd-temp" ||
181 gen_die "Could not extract lvm2 binary cache!";
182 mv ${TEMP}/initrd-temp/bin/lvm.static ${TEMP}/initrd-temp/bin/lvm ||
183 gen_die 'LVM2 error: Could not move lvm.static to lvm!'
185 for i in vgchange vgscan; do
186 ln ${TEMP}/initrd-temp/bin/lvm ${TEMP}/initrd-temp/bin/$i ||
187 gen_die "LVM2 error: Could not link ${i}!"
189 mkdir -p ${TEMP}/initrd-temp/etc/lvm
192 lvm dumpconfig 2>&1 > /dev/null || gen_die 'Could not copy over lvm.conf!'
196 cp /etc/lvm/lvm.conf "${TEMP}/initramfs-lvm2-temp/etc/lvm/" ||
197 gen_die 'Could not copy over lvm.conf!'
199 gen_die 'Could not copy over lvm.conf!'
205 if [ "${EVMS2}" = '1' ]
207 if [ -e '/sbin/evms_activate' ]
209 print_info 1 'EVMS2: Adding support...'
210 mkdir -p ${TEMP}/initrd-temp/lib
211 mkdir -p ${TEMP}/initrd-temp/sbin
212 mkdir -p ${TEMP}/initrd-temp/etc
213 mkdir -p ${TEMP}/initrd-temp/bin
214 cp -a /lib/ld-* "${TEMP}/initrd-temp/lib" \
215 || gen_die 'Could not copy files for EVMS2!'
216 if [ -n "`ls /lib/libgcc_s*`" ]
218 cp -a /lib/libgcc_s* "${TEMP}/initramfs-evms2-temp/lib" \
219 || gen_die 'Could not copy files for EVMS2!'
221 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initrd-temp/lib" \
222 || gen_die 'Could not copy files for EVMS2!'
223 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initrd-temp/lib" \
224 || gen_die 'Could not copy files for EVMS2!'
225 cp -a /lib/libpthread* "${TEMP}/initrd-temp/lib" \
226 || gen_die 'Could not copy files for EVMS2!'
227 cp -a /lib/libuuid*so* "${TEMP}/initrd-temp/lib" \
228 || gen_die 'Could not copy files for EVMS2!'
229 cp -a /lib/libevms*so* "${TEMP}/initrd-temp/lib" \
230 || gen_die 'Could not copy files for EVMS2!'
231 cp -a /lib/evms "${TEMP}/initrd-temp/lib" \
232 || gen_die 'Could not copy files for EVMS2!'
233 cp -a /lib/evms/* "${TEMP}/initrd-temp/lib/evms" \
234 || gen_die 'Could not copy files for EVMS2!'
235 cp -a /etc/evms.conf "${TEMP}/initrd-temp/etc" \
236 || gen_die 'Could not copy files for EVMS2!'
237 cp /sbin/evms_activate "${TEMP}/initrd-temp/sbin" \
238 || gen_die 'Could not copy over evms_activate!'
239 # Fix EVMS2 complaining that it cant find the swap utilities.
240 # These are not required in the initrd
241 for swap_libs in "${TEMP}/initrd-temp/lib/evms/*/swap*.so"
248 for i in '[' ash basename cat chroot clear cp dirname echo env false find \
249 grep gunzip gzip ln ls loadkmap losetup lsmod mdev mkdir mknod more mount \
250 mv pivot_root ps awk pwd rm rmdir rmmod sed sh sleep tar test touch true \
251 umount uname xargs yes zcat chmod chown cut kill killall; do
252 rm -f ${TEMP}/initrd-temp/bin/$i > /dev/null
253 ln ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i ||
254 gen_die "Busybox error: could not link ${i}!"
259 if is_static /bin/cryptsetup
261 print_info 1 "Including LUKS support"
262 rm -f ${TEMP}/initrd-temp/sbin/cryptsetup
263 cp /bin/cryptsetup ${TEMP}/initrd-temp/sbin/cryptsetup
264 chmod +x "${TEMP}/initrd-temp/sbin/cryptsetup"
266 print_info 1 "LUKS support requires static cryptsetup at /bin/cryptsetup"
267 print_info 1 "Not including LUKS support"
280 create_initrd_modules() {
284 if [ "${PAT}" -gt "4" ]
291 print_info 2 "initrd: >> Searching for modules..."
293 if [ "${INSTALL_MOD_PATH}" != '' ]
295 cd ${INSTALL_MOD_PATH}
300 for i in `gen_dep_list`
302 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1`
305 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
308 print_info 2 "initrd: >> Copying ${i}${MOD_EXT}..."
309 cp -ax --parents "${mymod}" "${TEMP}/initrd-temp"
312 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initrd-temp 2>/dev/null
314 mkdir -p "${TEMP}/initrd-temp/etc/modules"
315 for group_modules in ${!MODULES_*}; do
316 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
317 print_list ${!group_modules} > "${TEMP}/initrd-temp/etc/modules/${group}"
321 create_initrd_aux() {
322 if [ -f "${CMD_LINUXRC}" ]
324 cp "${CMD_LINUXRC}" "${TEMP}/initrd-temp/linuxrc"
325 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC}"
327 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
329 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
331 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
335 # Make sure it's executable
336 chmod 0755 "${TEMP}/initrd-temp/linuxrc"
338 if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
340 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
342 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
345 if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
347 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
349 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
352 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
353 for group_modules in ${!MODULES_*}; do
354 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
355 echo -n "${group} " >> "${TEMP}/initrd-temp/etc/initrd.defaults"
357 echo '"' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
359 if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
361 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
363 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
365 if isTrue $CMD_DOKEYMAPAUTO
367 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
369 mkdir -p "${TEMP}/initrd-temp/lib/keymaps"
370 /bin/tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
371 if isTrue $CMD_SLOWUSB
373 echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
376 cd ${TEMP}/initrd-temp/sbin && ln -s ../linuxrc init
378 chmod +x "${TEMP}/initrd-temp/linuxrc"
379 chmod +x "${TEMP}/initrd-temp/etc/initrd.scripts"
380 chmod +x "${TEMP}/initrd-temp/etc/initrd.defaults"
381 chmod +x "${TEMP}/initrd-temp/sbin/modprobe"
386 cd ${TEMP}/initrd-temp/
387 TEST=`du -sk 2> /dev/null`
388 echo $TEST | cut "-d " -f1
394 print_info 1 "initrd: >> Initializing..."
395 create_base_initrd_sys
397 if [ "${NOINITRDMODULES}" = '' ]
399 print_info 1 " >> Copying modules..."
400 create_initrd_modules
402 print_info 1 "initrd: Not copying modules..."
405 print_info 1 " >> Copying auxilary files..."
408 INITRD_CALC_SIZE=`calc_initrd_size`
409 INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 250`
410 print_info 1 " :: Size is at ${INITRD_SIZE}K"
411 print_info 1 " >> Creating loopback filesystem..."
412 create_initrd_loop ${INITRD_SIZE}
414 print_info 1 " >> Moving initrd files to the loopback..."
417 print_info 1 " >> Cleaning up and compressing the initrd..."
418 create_initrd_unmount_loop
420 if [ "${COMPRESS_INITRD}" ]
422 gzip -f -9 ${TMPDIR}/initrd-${KV}
423 mv ${TMPDIR}/initrd-${KV}.gz ${TMPDIR}/initrd-${KV}
426 if [ "${BOOTSPLASH}" -eq "1" ]
428 if [ -x /sbin/splash ]
430 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash.conf ] && source /etc/conf.d/bootsplash.conf
431 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash ] && source /etc/conf.d/bootsplash
432 [ -z "${BOOTSPLASH_THEME}" ] && BOOTSPLASH_THEME=default
433 print_info 1 " >> Installing bootsplash [ using the ${BOOTSPLASH_THEME} theme ]..."
434 for bootRes in '800x600' '1024x768' '1280x1024' '1600x1200'
436 if [ -f "/etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg" ]
438 /sbin/splash -s -f /etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg >> ${TMPDIR}/initrd-${KV} ||
439 gen_die "Error: could not copy ${bootRes} bootsplash!"
441 print_warning 1 "splash: Did not find a bootsplash for the ${bootRes} resolution..."
445 print_warning 1 ' >> No bootsplash detected; skipping!'
448 if ! isTrue "${CMD_NOINSTALL}"
450 copy_image_with_preserve "initrd" \
451 "${TMPDIR}/initrd-${KV}" \
452 "initrd-${KNAME}-${ARCH}-${KV}"
455 # Pegasos hack for merging the initrd into the kernel at compile time
456 [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
457 [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
458 cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz &&
459 rm ${TMPDIR}/initrd-${KV}
461 # Mips also mimics Pegasos to merge the initrd into the kernel
462 [ ${BUILD_INITRAMFS} -eq 1 ] \
463 && cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/mips/ramdisk/initrd.img.gz