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 create_base_initrd_sys() {
31 rm -rf "${TEMP}/initrd-temp" > /dev/null
32 mkdir -p ${TEMP}/initrd-temp/dev
33 mkdir -p ${TEMP}/initrd-temp/bin
34 mkdir -p ${TEMP}/initrd-temp/etc
35 mkdir -p ${TEMP}/initrd-temp/usr
36 mkdir -p ${TEMP}/initrd-temp/proc
37 mkdir -p ${TEMP}/initrd-temp/temp
38 mkdir -p ${TEMP}/initrd-temp/sys
39 mkdir -p ${TEMP}/initrd-temp/.initrd
40 mkdir -p ${TEMP}/initrd-temp/var/lock/dmraid
41 ln -s bin ${TEMP}/initrd-temp/sbin
42 ln -s ../bin ${TEMP}/initrd-temp/usr/bin
43 ln -s ../bin ${TEMP}/initrd-temp/usr/sbin
45 echo "/dev/ram0 / ext2 defaults" > ${TEMP}/initrd-temp/etc/fstab
46 echo "proc /proc proc defaults 0 0" >> ${TEMP}/initrd-temp/etc/fstab
48 if [ "${NODEVFSD}" = '' ]
50 echo "REGISTER .* MKOLDCOMPAT" > ${TEMP}/initrd-temp/etc/devfsd.conf
51 echo "UNREGISTER .* RMOLDCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
52 echo "REGISTER .* MKNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
53 echo "UNREGISTER .* RMNEWCOMPAT" >> ${TEMP}/initrd-temp/etc/devfsd.conf
56 # SGI LiveCDs need the following binary (no better place for it than here)
57 # getdvhoff is a DEPEND of genkernel, so it *should* exist
58 if [ ${BUILD_INITRAMFS} -eq 1 ]
60 [ -e /usr/lib/getdvhoff/getdvhoff ] \
61 && cp /usr/lib/getdvhoff/getdvhoff ${TEMP}/initrd-temp/bin \
62 || gen_die "sys-boot/getdvhoff not merged!"
65 cd ${TEMP}/initrd-temp/dev
69 if [ "${DISKLABEL}" -eq '1' ]; then
70 cp "${BLKID_BINCACHE}" "${TEMP}/initrd-temp/bin/blkid.bz2" ||
71 gen_die 'Could not copy blkid from bincache!'
72 bunzip2 "${TEMP}/initrd-temp/bin/blkid.bz2" ||
73 gen_die 'Could not uncompress blkid!'
74 chmod +x "${TEMP}/initrd-temp/bin/blkid"
77 cp "${BUSYBOX_BINCACHE}" "${TEMP}/initrd-temp/bin/busybox.bz2" ||
78 gen_die 'Could not copy busybox from bincache!'
79 bunzip2 "${TEMP}/initrd-temp/bin/busybox.bz2" ||
80 gen_die 'Could not uncompress busybox!'
81 chmod +x "${TEMP}/initrd-temp/bin/busybox"
83 if [ "${NOINITRDMODULES}" = '' ]
85 if [ "${PAT}" -gt "4" ]
87 cp "${MODULE_INIT_TOOLS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
88 gen_die 'Could not copy insmod.static from bincache!'
90 cp "${MODUTILS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
91 gen_die 'Could not copy insmod.static from bincache'
94 bunzip2 "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
95 gen_die 'Could not uncompress insmod.static!'
96 mv "${TEMP}/initrd-temp/bin/insmod.static" "${TEMP}/initrd-temp/bin/insmod"
97 chmod +x "${TEMP}/initrd-temp/bin/insmod"
101 if [ "${UDEV}" != '1' ]
103 cp "${DEVFSD_BINCACHE}" "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die 'Could not copy devfsd executable from bincache!'
104 bunzip2 "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die 'Could not uncompress devfsd!'
105 chmod +x "${TEMP}/initrd-temp/bin/devfsd"
109 if [ "${UDEV}" -eq '1' ]
111 /bin/tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initrd-temp" || gen_die 'Could not extract udev binary cache!'
112 if [ ! -e "${TEMP}/initrd-temp/bin/udevstart" ]
114 ln -sf "./udev" "${TEMP}/initrd-temp/bin/udevstart" || gen_die 'Could not symlink udev -> udevstart!'
117 if [ ! -e "${TEMP}/initrd-temp/bin/udevsend" ]
119 ln -sf "./udev" "${TEMP}/initrd-temp/bin/udevsend" || gen_die 'Could not symlink udev -> udevsend!'
125 if [ "${UNIONFS}" -eq '1' ]
127 print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
128 compile_unionfs_modules
129 /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initrd-temp" ||
130 gen_die "Could not extract unionfs modules binary cache!";
134 if [ "${UNIONFS}" -eq '1' ]
136 print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
137 compile_unionfs_utils
138 /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initrd-temp" ||
139 gen_die "Could not extract unionfs tools binary cache!";
144 if [ "${DMRAID}" = '1' ]
146 print_info 1 'DMRAID: Adding support (compiling binaries)...'
148 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initrd-temp" ||
149 gen_die "Could not extract dmraid binary cache!";
153 if [ "${LVM2}" = '1' ]
155 if [ -e '/sbin/lvm' ] && ldd /sbin/lvm|grep -q 'not a dynamic executable';
157 print_info 1 'LVM2: Adding support (using local static binaries)...'
158 cp /sbin/lvm "${TEMP}/initrd-temp/bin/lvm" ||
159 gen_die 'Could not copy over lvm!'
160 ln "${TEMP}/initrd-temp/bin/lvm" "${TEMP}/initrd-temp/bin/vgscan" ||
161 gen_die 'Could not symlink lvm -> vgscan!'
162 ln "${TEMP}/initrd-temp/bin/lvm" "${TEMP}/initrd-temp/bin/vgchange" ||
163 gen_die 'Could not symlink lvm -> vgchange!'
165 print_info 1 'LVM2: Adding support (compiling binaries)...'
168 /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initrd-temp" ||
169 gen_die "Could not extract lvm2 binary cache!";
170 mv ${TEMP}/initrd-temp/bin/lvm.static ${TEMP}/initrd-temp/bin/lvm ||
171 gen_die 'LVM2 error: Could not move lvm.static to lvm!'
172 for i in vgchange vgscan; do
173 ln ${TEMP}/initrd-temp/bin/lvm ${TEMP}/initrd-temp/bin/$i ||
174 gen_die "LVM2 error: Could not link ${i}!"
180 if [ "${EVMS2}" = '1' ]
182 if [ -e '/sbin/evms_activate' ]
184 print_info 1 'EVMS2: Adding support...'
185 mkdir -p ${TEMP}/initrd-temp/lib
186 mkdir -p ${TEMP}/initrd-temp/sbin
187 mkdir -p ${TEMP}/initrd-temp/etc
188 cp -a /lib/ld-* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
189 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
190 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
191 cp -a /lib/libpthread* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
192 cp -a /lib/libuuid*so* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
193 cp -a /lib/libevms*so* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
194 cp -a /lib/evms "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
195 cp -a /lib/evms/* "${TEMP}/initrd-temp/lib/evms" || gen_die 'Could not copy files for EVMS2!'
196 cp -a /etc/evms.conf "${TEMP}/initrd-temp/etc" || gen_die 'Could not copy files for EVMS2!'
197 cp /sbin/evms_activate "${TEMP}/initrd-temp/sbin/evms_activate" || gen_die 'Could not copy over evms_activate!'
198 # Fix EVMS2 complaining that it cant find the swap utilities.
199 # These are not required in the initrd
200 for swap_libs in "${TEMP}/initrd-temp/lib/evms/*/swap*.so"
207 for i in '[' ash basename cat chroot clear cp dirname echo env false find \
208 grep gunzip gzip ln ls loadkmap losetup lsmod mkdir mknod more mount mv \
209 pivot_root ps awk pwd rm rmdir rmmod sed sh sleep tar test touch true umount uname \
210 xargs yes zcat chmod chown cut kill killall; do
211 rm -f ${TEMP}/initrd-temp/bin/$i > /dev/null
212 ln ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i ||
213 gen_die "Busybox error: could not link ${i}!"
226 create_initrd_modules() {
230 if [ "${PAT}" -gt "4" ]
237 print_info 2 "initrd: >> Searching for modules..."
239 if [ "${INSTALL_MOD_PATH}" != '' ]
241 cd ${INSTALL_MOD_PATH}
246 for i in `gen_dep_list`
248 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1`
251 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
254 print_info 2 "initrd: >> Copying ${i}${MOD_EXT}..."
255 cp -ax --parents "${mymod}" "${TEMP}/initrd-temp"
258 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initrd-temp 2>/dev/null
260 mkdir -p "${TEMP}/initrd-temp/etc/modules"
261 for group_modules in ${!MODULES_*}; do
262 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
263 print_list ${!group_modules} > "${TEMP}/initrd-temp/etc/modules/${group}"
267 create_initrd_aux() {
268 if [ -f "${CMD_LINUXRC}" ]
270 cp "${CMD_LINUXRC}" "${TEMP}/initrd-temp/linuxrc"
271 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC}"
273 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
275 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
277 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
281 if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
283 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
285 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
288 if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
290 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
292 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
295 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
296 for group_modules in ${!MODULES_*}; do
297 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
298 echo -n "${group} " >> "${TEMP}/initrd-temp/etc/initrd.defaults"
300 echo '"' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
302 if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
304 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
306 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
308 if isTrue $CMD_DOKEYMAPAUTO
310 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
312 mkdir -p "${TEMP}/initrd-temp/lib/keymaps"
313 /bin/tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
314 if isTrue $CMD_BLADECENTER
316 echo 'MY_HWOPTS="${MY_HWOPTS} bladecenter"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
319 cd ${TEMP}/initrd-temp/sbin && ln -s ../linuxrc init
321 chmod +x "${TEMP}/initrd-temp/linuxrc"
322 chmod +x "${TEMP}/initrd-temp/etc/initrd.scripts"
323 chmod +x "${TEMP}/initrd-temp/etc/initrd.defaults"
324 chmod +x "${TEMP}/initrd-temp/sbin/modprobe"
329 cd ${TEMP}/initrd-temp/
330 TEST=`du -sk 2> /dev/null`
331 echo $TEST | cut "-d " -f1
337 print_info 1 "initrd: >> Initializing..."
338 create_base_initrd_sys
340 if [ "${NOINITRDMODULES}" = '' ]
342 print_info 1 " >> Copying modules..."
343 create_initrd_modules
345 print_info 1 "initrd: Not copying modules..."
348 print_info 1 " >> Copying auxilary files..."
351 INITRD_CALC_SIZE=`calc_initrd_size`
352 INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 100`
353 print_info 1 " :: Size is at ${INITRD_SIZE}K"
354 print_info 1 " >> Creating loopback filesystem..."
355 create_initrd_loop ${INITRD_SIZE}
357 print_info 1 " >> Moving initrd files to the loopback..."
360 print_info 1 " >> Cleaning up and compressing the initrd..."
361 create_initrd_unmount_loop
363 if [ "${COMPRESS_INITRD}" ]
365 gzip -f -9 ${TMPDIR}/initrd-${KV}
366 mv ${TMPDIR}/initrd-${KV}.gz ${TMPDIR}/initrd-${KV}
369 if [ "${BOOTSPLASH}" -eq "1" ]
371 if [ -x /sbin/splash ]
373 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash.conf ] && source /etc/conf.d/bootsplash.conf
374 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash ] && source /etc/conf.d/bootsplash
375 [ -z "${BOOTSPLASH_THEME}" ] && BOOTSPLASH_THEME=default
376 print_info 1 " >> Installing bootsplash [ using the ${BOOTSPLASH_THEME} theme ]..."
377 for bootRes in '800x600' '1024x768' '1280x1024' '1600x1200'
379 if [ -f "/etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg" ]
381 /sbin/splash -s -f /etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg >> ${TMPDIR}/initrd-${KV} ||
382 gen_die "Error: could not copy ${bootRes} bootsplash!"
384 print_warning 1 "splash: Did not find a bootsplash for the ${bootRes} resolution..."
388 print_warning 1 ' >> No bootsplash detected; skipping!'
391 if ! isTrue "${CMD_NOINSTALL}"
393 cp ${TMPDIR}/initrd-${KV} /boot/initrd-${KNAME}-${ARCH}-${KV} ||
394 gen_die 'Could not copy the initrd to /boot!'
397 # Pegasos hack for merging the initrd into the kernel at compile time
398 [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
399 [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
400 cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz &&
401 rm ${TMPDIR}/initrd-${KV}
403 # Mips also mimics Pegasos to merge the initrd into the kernel
404 [ ${BUILD_INITRAMFS} -eq 1 ] \
405 && cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/mips/ramdisk/initrd.img.gz