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 cd ${TEMP}/initrd-temp/dev
60 if [ "${DISKLABEL}" -eq '1' ]; then
61 cp "${BLKID_BINCACHE}" "${TEMP}/initrd-temp/bin/blkid.bz2" ||
62 gen_die 'Could not copy blkid from bincache!'
63 bunzip2 "${TEMP}/initrd-temp/bin/blkid.bz2" ||
64 gen_die 'Could not uncompress blkid!'
65 chmod +x "${TEMP}/initrd-temp/bin/blkid"
68 cp "${BUSYBOX_BINCACHE}" "${TEMP}/initrd-temp/bin/busybox.bz2" ||
69 gen_die 'Could not copy busybox from bincache!'
70 bunzip2 "${TEMP}/initrd-temp/bin/busybox.bz2" ||
71 gen_die 'Could not uncompress busybox!'
72 chmod +x "${TEMP}/initrd-temp/bin/busybox"
74 if [ "${NOINITRDMODULES}" = '' ]
76 if [ "${PAT}" -gt "4" ]
78 cp "${MODULE_INIT_TOOLS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
79 gen_die 'Could not copy insmod.static from bincache!'
81 cp "${MODUTILS_BINCACHE}" "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
82 gen_die 'Could not copy insmod.static from bincache'
85 bunzip2 "${TEMP}/initrd-temp/bin/insmod.static.bz2" ||
86 gen_die 'Could not uncompress insmod.static!'
87 mv "${TEMP}/initrd-temp/bin/insmod.static" "${TEMP}/initrd-temp/bin/insmod"
88 chmod +x "${TEMP}/initrd-temp/bin/insmod"
92 if [ "${UDEV}" != '1' ]
94 cp "${DEVFSD_BINCACHE}" "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die 'Could not copy devfsd executable from bincache!'
95 bunzip2 "${TEMP}/initrd-temp/bin/devfsd.bz2" || gen_die 'Could not uncompress devfsd!'
96 chmod +x "${TEMP}/initrd-temp/bin/devfsd"
100 if [ "${UDEV}" -eq '1' ]
102 /bin/tar -jxpf "${UDEV_BINCACHE}" -C "${TEMP}/initrd-temp" || gen_die 'Could not extract udev binary cache!'
103 ln -sf "./udev" "${TEMP}/initrd-temp/bin/udevstart" || gen_die 'Could not symlink udev -> udevstart!'
107 if [ "${UNIONFS}" -eq '1' ]
109 print_info 1 'UNIONFS MODULES: Adding support (compiling)...'
110 compile_unionfs_modules
111 /bin/tar -jxpf "${UNIONFS_MODULES_BINCACHE}" -C "${TEMP}/initrd-temp" ||
112 gen_die "Could not extract unionfs modules binary cache!";
116 if [ "${UNIONFS}" -eq '1' ]
118 print_info 1 'UNIONFS TOOLS: Adding support (compiling)...'
119 compile_unionfs_utils
120 /bin/tar -jxpf "${UNIONFS_BINCACHE}" -C "${TEMP}/initrd-temp" ||
121 gen_die "Could not extract unionfs tools binary cache!";
126 if [ "${DMRAID}" = '1' ]
128 print_info 1 'DMRAID: Adding support (compiling binaries)...'
130 /bin/tar -jxpf "${DMRAID_BINCACHE}" -C "${TEMP}/initrd-temp" ||
131 gen_die "Could not extract dmraid binary cache!";
135 if [ "${LVM2}" = '1' ]
137 if [ -e '/sbin/lvm' ] && ldd /sbin/lvm|grep -q 'not a dynamic executable';
139 print_info 1 'LVM2: Adding support (using local static binaries)...'
140 cp /sbin/lvm "${TEMP}/initrd-temp/bin/lvm" ||
141 gen_die 'Could not copy over lvm!'
142 ln "${TEMP}/initrd-temp/bin/lvm" "${TEMP}/initrd-temp/bin/vgscan" ||
143 gen_die 'Could not symlink lvm -> vgscan!'
144 ln "${TEMP}/initrd-temp/bin/lvm" "${TEMP}/initrd-temp/bin/vgchange" ||
145 gen_die 'Could not symlink lvm -> vgchange!'
147 print_info 1 'LVM2: Adding support (compiling binaries)...'
150 /bin/tar -jxpf "${LVM2_BINCACHE}" -C "${TEMP}/initrd-temp" ||
151 gen_die "Could not extract lvm2 binary cache!";
152 mv ${TEMP}/initrd-temp/bin/lvm.static ${TEMP}/initrd-temp/bin/lvm ||
153 gen_die 'LVM2 error: Could not move lvm.static to lvm!'
154 for i in vgchange vgscan; do
155 ln ${TEMP}/initrd-temp/bin/lvm ${TEMP}/initrd-temp/bin/$i ||
156 gen_die "LVM2 error: Could not link ${i}!"
162 if [ "${EVMS2}" = '1' ]
164 if [ -e '/sbin/evms_activate' ]
166 print_info 1 'EVMS2: Adding support...'
167 mkdir -p ${TEMP}/initrd-temp/lib
168 mkdir -p ${TEMP}/initrd-temp/sbin
169 mkdir -p ${TEMP}/initrd-temp/etc
170 cp -a /lib/ld-* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
171 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
172 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
173 cp -a /lib/libpthread* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
174 cp -a /lib/libuuid*so* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
175 cp -a /lib/libevms*so* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
176 cp -a /lib/evms "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
177 cp -a /lib/evms/* "${TEMP}/initrd-temp/lib/evms" || gen_die 'Could not copy files for EVMS2!'
178 cp -a /etc/evms.conf "${TEMP}/initrd-temp/etc" || gen_die 'Could not copy files for EVMS2!'
179 cp /sbin/evms_activate "${TEMP}/initrd-temp/sbin/evms_activate" || gen_die 'Could not copy over evms_activate!'
180 # Fix EVMS2 complaining that it cant find the swap utilities.
181 # These are not required in the initrd
182 for swap_libs in "${TEMP}/initrd-temp/lib/evms/*/swap*.so"
189 for i in '[' ash basename cat chroot clear cp dirname echo env false find \
190 grep gunzip gzip ln ls loadkmap losetup lsmod mkdir mknod more mount mv \
191 pivot_root ps awk pwd rm rmdir rmmod sed sh sleep tar test touch true umount uname \
192 xargs yes zcat chmod chown cut kill killall; do
193 rm -f ${TEMP}/initrd-temp/bin/$i > /dev/null
194 ln ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i ||
195 gen_die "Busybox error: could not link ${i}!"
208 create_initrd_modules() {
212 if [ "${PAT}" -gt "4" ]
219 print_info 2 "initrd: >> Searching for modules..."
221 if [ "${INSTALL_MOD_PATH}" != '' ]
223 cd ${INSTALL_MOD_PATH}
228 for i in `gen_dep_list`
230 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1`
233 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
236 print_info 2 "initrd: >> Copying ${i}${MOD_EXT}..."
237 cp -ax --parents "${mymod}" "${TEMP}/initrd-temp"
240 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initrd-temp 2>/dev/null
242 mkdir -p "${TEMP}/initrd-temp/etc/modules"
243 for group_modules in ${!MODULES_*}; do
244 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
245 print_list ${!group_modules} > "${TEMP}/initrd-temp/etc/modules/${group}"
249 create_initrd_aux() {
250 if [ -f "${CMD_LINUXRC}" ]
252 cp "${CMD_LINUXRC}" "${TEMP}/initrd-temp/linuxrc"
253 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC}"
255 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
257 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
259 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
263 if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
265 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
267 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
270 if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
272 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
274 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
277 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
278 for group_modules in ${!MODULES_*}; do
279 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
280 echo -n "${group} " >> "${TEMP}/initrd-temp/etc/initrd.defaults"
282 echo '"' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
284 if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
286 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
288 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
290 if isTrue $CMD_DOKEYMAPAUTO
292 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
294 mkdir -p "${TEMP}/initrd-temp/lib/keymaps"
295 /bin/tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
296 if isTrue $CMD_BLADECENTER
298 echo 'MY_HWOPTS="${MY_HWOPTS} bladecenter"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
301 cd ${TEMP}/initrd-temp/sbin && ln -s ../linuxrc init
303 chmod +x "${TEMP}/initrd-temp/linuxrc"
304 chmod +x "${TEMP}/initrd-temp/etc/initrd.scripts"
305 chmod +x "${TEMP}/initrd-temp/etc/initrd.defaults"
306 chmod +x "${TEMP}/initrd-temp/sbin/modprobe"
311 cd ${TEMP}/initrd-temp/
312 TEST=`du -sk 2> /dev/null`
313 echo $TEST | cut "-d " -f1
319 print_info 1 "initrd: >> Initializing..."
320 create_base_initrd_sys
322 if [ "${NOINITRDMODULES}" = '' ]
324 print_info 1 " >> Copying modules..."
325 create_initrd_modules
327 print_info 1 "initrd: Not copying modules..."
330 print_info 1 " >> Copying auxilary files..."
333 INITRD_CALC_SIZE=`calc_initrd_size`
334 INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 100`
335 print_info 1 " :: Size is at ${INITRD_SIZE}K"
336 print_info 1 " >> Creating loopback filesystem..."
337 create_initrd_loop ${INITRD_SIZE}
339 print_info 1 " >> Moving initrd files to the loopback..."
342 print_info 1 " >> Cleaning up and compressing the initrd..."
343 create_initrd_unmount_loop
345 if [ "${COMPRESS_INITRD}" ]
347 gzip -f -9 ${TMPDIR}/initrd-${KV}
348 mv ${TMPDIR}/initrd-${KV}.gz ${TMPDIR}/initrd-${KV}
351 if [ "${BOOTSPLASH}" -eq "1" ]
353 if [ -x /sbin/splash ]
355 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash.conf ] && source /etc/conf.d/bootsplash.conf
356 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash ] && source /etc/conf.d/bootsplash
357 [ -z "${BOOTSPLASH_THEME}" ] && BOOTSPLASH_THEME=default
358 print_info 1 " >> Installing bootsplash [ using the ${BOOTSPLASH_THEME} theme ]..."
359 for bootRes in '800x600' '1024x768' '1280x1024' '1600x1200'
361 if [ -f "/etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg" ]
363 /sbin/splash -s -f /etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg >> ${TMPDIR}/initrd-${KV} ||
364 gen_die "Error: could not copy ${bootRes} bootsplash!"
366 print_warning 1 "splash: Did not find a bootsplash for the ${bootRes} resolution..."
370 print_warning 1 ' >> No bootsplash detected; skipping!'
373 if ! isTrue "${CMD_NOINSTALL}"
375 cp ${TMPDIR}/initrd-${KV} /boot/initrd-${KNAME}-${ARCH}-${KV} ||
376 gen_die 'Could not copy the initrd to /boot!'
378 [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] ||
379 [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' -a "${GENERATE_Z_IMAGE}" = '1' ] &&
380 cp ${TMPDIR}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz