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 -N500 -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!";
149 if [ "${DMRAID}" = '1' ]
151 print_info 1 'DMRAID: Adding support (compiling binaries)...'
153 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initrd-temp" ||
154 gen_die "Could not extract dmraid binary cache!";
158 if [ "${LVM2}" = '1' ]
160 if [ -e '/sbin/lvm' ] && ldd /sbin/lvm|grep -q 'not a dynamic executable';
162 print_info 1 'LVM2: Adding support (using local static binaries)...'
163 cp /sbin/lvm "${TEMP}/initrd-temp/bin/lvm" ||
164 gen_die 'Could not copy over lvm!'
166 print_info 1 'LVM2: Adding support (compiling binaries)...'
169 /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initrd-temp" ||
170 gen_die "Could not extract lvm2 binary cache!";
171 mv ${TEMP}/initrd-temp/bin/lvm.static ${TEMP}/initrd-temp/bin/lvm ||
172 gen_die 'LVM2 error: Could not move lvm.static to lvm!'
174 for i in vgchange vgscan; do
175 ln ${TEMP}/initrd-temp/bin/lvm ${TEMP}/initrd-temp/bin/$i ||
176 gen_die "LVM2 error: Could not link ${i}!"
178 mkdir -p ${TEMP}/initrd-temp/etc/lvm
179 cp /etc/lvm/lvm.conf "${TEMP}/initrd-temp/etc/lvm/lvm.conf" ||
180 gen_die 'Could not copy over lvm.conf!'
184 if [ "${EVMS2}" = '1' ]
186 if [ -e '/sbin/evms_activate' ]
188 print_info 1 'EVMS2: Adding support...'
189 mkdir -p ${TEMP}/initrd-temp/lib
190 mkdir -p ${TEMP}/initrd-temp/sbin
191 mkdir -p ${TEMP}/initrd-temp/etc
192 mkdir -p ${TEMP}/initrd-temp/bin
193 cp -a /lib/ld-* "${TEMP}/initrd-temp/lib" \
194 || gen_die 'Could not copy files for EVMS2!'
195 if [ -n "`ls /lib/libgcc_s*`" ]
197 cp -a /lib/libgcc_s* "${TEMP}/initramfs-evms2-temp/lib" \
198 || gen_die 'Could not copy files for EVMS2!'
200 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initrd-temp/lib" \
201 || gen_die 'Could not copy files for EVMS2!'
202 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initrd-temp/lib" \
203 || gen_die 'Could not copy files for EVMS2!'
204 cp -a /lib/libpthread* "${TEMP}/initrd-temp/lib" \
205 || gen_die 'Could not copy files for EVMS2!'
206 cp -a /lib/libuuid*so* "${TEMP}/initrd-temp/lib" \
207 || gen_die 'Could not copy files for EVMS2!'
208 cp -a /lib/libevms*so* "${TEMP}/initrd-temp/lib" \
209 || gen_die 'Could not copy files for EVMS2!'
210 cp -a /lib/evms "${TEMP}/initrd-temp/lib" \
211 || gen_die 'Could not copy files for EVMS2!'
212 cp -a /lib/evms/* "${TEMP}/initrd-temp/lib/evms" \
213 || gen_die 'Could not copy files for EVMS2!'
214 cp -a /etc/evms.conf "${TEMP}/initrd-temp/etc" \
215 || gen_die 'Could not copy files for EVMS2!'
216 cp /sbin/evms_activate "${TEMP}/initrd-temp/sbin" \
217 || gen_die 'Could not copy over evms_activate!'
218 # Fix EVMS2 complaining that it cant find the swap utilities.
219 # These are not required in the initrd
220 for swap_libs in "${TEMP}/initrd-temp/lib/evms/*/swap*.so"
227 for i in '[' ash basename cat chroot clear cp dirname echo env false find \
228 grep gunzip gzip ln ls loadkmap losetup lsmod mkdir mknod more mount mv \
229 pivot_root ps awk pwd rm rmdir rmmod sed sh sleep tar test touch true umount uname \
230 xargs yes zcat chmod chown cut kill killall; do
231 rm -f ${TEMP}/initrd-temp/bin/$i > /dev/null
232 ln ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i ||
233 gen_die "Busybox error: could not link ${i}!"
238 if is_static /bin/cryptsetup
240 print_info "Including LUKS support"
241 rm -f ${TEMP}/initrd-temp/sbin/cryptsetup
242 cp /bin/cryptsetup ${TEMP}/initrd-temp/sbin/cryptsetup
243 chmod +x "${TEMP}/initrd-temp/sbin/cryptsetup"
245 print_info "LUKS support requires static cryptsetup at /bin/cryptsetup"
246 print_info "Not including LUKS support"
259 create_initrd_modules() {
263 if [ "${PAT}" -gt "4" ]
270 print_info 2 "initrd: >> Searching for modules..."
272 if [ "${INSTALL_MOD_PATH}" != '' ]
274 cd ${INSTALL_MOD_PATH}
279 for i in `gen_dep_list`
281 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1`
284 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
287 print_info 2 "initrd: >> Copying ${i}${MOD_EXT}..."
288 cp -ax --parents "${mymod}" "${TEMP}/initrd-temp"
291 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initrd-temp 2>/dev/null
293 mkdir -p "${TEMP}/initrd-temp/etc/modules"
294 for group_modules in ${!MODULES_*}; do
295 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
296 print_list ${!group_modules} > "${TEMP}/initrd-temp/etc/modules/${group}"
300 create_initrd_aux() {
301 if [ -f "${CMD_LINUXRC}" ]
303 cp "${CMD_LINUXRC}" "${TEMP}/initrd-temp/linuxrc"
304 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC}"
306 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
308 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
310 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
314 # Make sure it's executable
315 chmod 0755 "${TEMP}/initrd-temp/linuxrc"
317 if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
319 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
321 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
324 if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
326 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
328 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
331 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
332 for group_modules in ${!MODULES_*}; do
333 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
334 echo -n "${group} " >> "${TEMP}/initrd-temp/etc/initrd.defaults"
336 echo '"' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
338 if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
340 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
342 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
344 if isTrue $CMD_DOKEYMAPAUTO
346 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
348 mkdir -p "${TEMP}/initrd-temp/lib/keymaps"
349 /bin/tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
350 if isTrue $CMD_SLOWUSB
352 echo 'MY_HWOPTS="${MY_HWOPTS} slowusb"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
355 cd ${TEMP}/initrd-temp/sbin && ln -s ../linuxrc init
357 chmod +x "${TEMP}/initrd-temp/linuxrc"
358 chmod +x "${TEMP}/initrd-temp/etc/initrd.scripts"
359 chmod +x "${TEMP}/initrd-temp/etc/initrd.defaults"
360 chmod +x "${TEMP}/initrd-temp/sbin/modprobe"
365 cd ${TEMP}/initrd-temp/
366 TEST=`du -sk 2> /dev/null`
367 echo $TEST | cut "-d " -f1
373 print_info 1 "initrd: >> Initializing..."
374 create_base_initrd_sys
376 if [ "${NOINITRDMODULES}" = '' ]
378 print_info 1 " >> Copying modules..."
379 create_initrd_modules
381 print_info 1 "initrd: Not copying modules..."
384 print_info 1 " >> Copying auxilary files..."
387 INITRD_CALC_SIZE=`calc_initrd_size`
388 INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 100`
389 print_info 1 " :: Size is at ${INITRD_SIZE}K"
390 print_info 1 " >> Creating loopback filesystem..."
391 create_initrd_loop ${INITRD_SIZE}
393 print_info 1 " >> Moving initrd files to the loopback..."
396 print_info 1 " >> Cleaning up and compressing the initrd..."
397 create_initrd_unmount_loop
399 if [ "${COMPRESS_INITRD}" ]
401 gzip -f -9 ${TMPDIR}/initrd-${KV}
402 mv ${TMPDIR}/initrd-${KV}.gz ${TMPDIR}/initrd-${KV}
405 if [ "${BOOTSPLASH}" -eq "1" ]
407 if [ -x /sbin/splash ]
409 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash.conf ] && source /etc/conf.d/bootsplash.conf
410 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash ] && source /etc/conf.d/bootsplash
411 [ -z "${BOOTSPLASH_THEME}" ] && BOOTSPLASH_THEME=default
412 print_info 1 " >> Installing bootsplash [ using the ${BOOTSPLASH_THEME} theme ]..."
413 for bootRes in '800x600' '1024x768' '1280x1024' '1600x1200'
415 if [ -f "/etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg" ]
417 /sbin/splash -s -f /etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg >> ${TMPDIR}/initrd-${KV} ||
418 gen_die "Error: could not copy ${bootRes} bootsplash!"
420 print_warning 1 "splash: Did not find a bootsplash for the ${bootRes} resolution..."
424 print_warning 1 ' >> No bootsplash detected; skipping!'
427 if ! isTrue "${CMD_NOINSTALL}"
429 cp ${TMPDIR}/initrd-${KV} ${BOOTDIR}/initrd-${KNAME}-${ARCH}-${KV} ||
430 gen_die 'Could not copy the initrd to ${BOOTDIR}!'
433 # Pegasos hack for merging the initrd into the kernel at compile time
434 [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
435 [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
436 cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz &&
437 rm ${TMPDIR}/initrd-${KV}
439 # Mips also mimics Pegasos to merge the initrd into the kernel
440 [ ${BUILD_INITRAMFS} -eq 1 ] \
441 && cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/mips/ramdisk/initrd.img.gz