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=${TEMP}/initrd-${KV} bs=1k count=${1} >> "${DEBUGFILE}" 2>&1 ||
10 gen_die "Could not zero initrd-${KV}"
11 mke2fs -F -N500 -q "${TEMP}/initrd-${KV}" >> "${DEBUGFILE}" 2>&1 ||
12 gen_die "Could not format initrd-${KV}!"
13 mount -t ext2 -o loop "${TEMP}/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 [ "${NODEVFSD}" = '' ]
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 cp -a /lib/ld-* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
169 cp -a /lib/libc-* /lib/libc.* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
170 cp -a /lib/libdl-* /lib/libdl.* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
171 cp -a /lib/libpthread* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
172 cp -a /lib/libuuid*so* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
173 cp -a /lib/libevms*so* "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
174 cp -a /lib/evms "${TEMP}/initrd-temp/lib" || gen_die 'Could not copy files for EVMS2!'
175 cp -a /lib/evms/* "${TEMP}/initrd-temp/lib/evms" || gen_die 'Could not copy files for EVMS2!'
176 cp -a /etc/evms.conf "${TEMP}/initrd-temp/etc" || gen_die 'Could not copy files for EVMS2!'
177 cp /sbin/evms_activate "${TEMP}/initrd-temp/bin/evms_activate" || gen_die 'Could not copy over vgscan!'
178 # Fix EVMS2 complaining that it cant find the swap utilities.
179 # These are not required in the initrd
180 for swap_libs in "${TEMP}/initrd-temp/lib/evms/*/swap*.so"
187 for i in '[' ash basename cat chroot clear cp dirname echo env false find \
188 grep gunzip gzip ln ls loadkmap losetup lsmod mkdir mknod more mount mv \
189 pivot_root ps awk pwd rm rmdir rmmod sed sh sleep tar test touch true umount uname \
190 xargs yes zcat chmod chown cut kill killall; do
191 rm -f ${TEMP}/initrd-temp/bin/$i > /dev/null
192 ln ${TEMP}/initrd-temp/bin/busybox ${TEMP}/initrd-temp/bin/$i ||
193 gen_die "Busybox error: could not link ${i}!"
206 create_initrd_modules() {
210 if [ "${PAT}" -gt "4" ]
217 print_info 2 "initrd: >> Searching for modules..."
219 if [ "${INSTALL_MOD_PATH}" != '' ]
221 cd ${INSTALL_MOD_PATH}
226 for i in `gen_dep_list`
228 mymod=`find ./lib/modules/${KV} -name "${i}${MOD_EXT}" 2>/dev/null| head -n 1`
231 print_warning 2 "Warning :: ${i}${MOD_EXT} not found; skipping..."
234 print_info 2 "initrd: >> Copying ${i}${MOD_EXT}..."
235 cp -ax --parents "${mymod}" "${TEMP}/initrd-temp"
238 cp -ax --parents ./lib/modules/${KV}/modules* ${TEMP}/initrd-temp 2>/dev/null
240 mkdir -p "${TEMP}/initrd-temp/etc/modules"
241 for group_modules in ${!MODULES_*}; do
242 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
243 print_list ${!group_modules} > "${TEMP}/initrd-temp/etc/modules/${group}"
247 create_initrd_aux() {
248 if [ -f "${CMD_LINUXRC}" ]
250 cp "${CMD_LINUXRC}" "${TEMP}/initrd-temp/linuxrc"
251 print_info 2 " >> Copying user specified linuxrc: ${CMD_LINUXRC}"
253 if [ -f "${GK_SHARE}/${ARCH}/linuxrc" ]
255 cp "${GK_SHARE}/${ARCH}/linuxrc" "${TEMP}/initrd-temp/linuxrc"
257 cp "${GK_SHARE}/generic/linuxrc" "${TEMP}/initrd-temp/linuxrc"
261 if [ -f "${GK_SHARE}/${ARCH}/initrd.scripts" ]
263 cp "${GK_SHARE}/${ARCH}/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
265 cp "${GK_SHARE}/generic/initrd.scripts" "${TEMP}/initrd-temp/etc/initrd.scripts"
268 if [ -f "${GK_SHARE}/${ARCH}/initrd.defaults" ]
270 cp "${GK_SHARE}/${ARCH}/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
272 cp "${GK_SHARE}/generic/initrd.defaults" "${TEMP}/initrd-temp/etc/initrd.defaults"
275 echo -n 'HWOPTS="$HWOPTS ' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
276 for group_modules in ${!MODULES_*}; do
277 group="$(echo $group_modules | cut -d_ -f2 | tr "[:upper:]" "[:lower:]")"
278 echo -n "${group} " >> "${TEMP}/initrd-temp/etc/initrd.defaults"
280 echo '"' >> "${TEMP}/initrd-temp/etc/initrd.defaults"
282 if [ -f "${GK_SHARE}/${ARCH}/modprobe" ]
284 cp "${GK_SHARE}/${ARCH}/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
286 cp "${GK_SHARE}/generic/modprobe" "${TEMP}/initrd-temp/sbin/modprobe"
288 if isTrue $CMD_DOKEYMAPAUTO
290 echo 'MY_HWOPTS="${MY_HWOPTS} keymap"' >> ${TEMP}/initrd-temp/etc/initrd.defaults
292 mkdir -p "${TEMP}/initrd-temp/lib/keymaps"
293 /bin/tar -C "${TEMP}/initrd-temp/lib/keymaps" -zxf "${GK_SHARE}/generic/keymaps.tar.gz"
295 cd ${TEMP}/initrd-temp/sbin && ln -s ../linuxrc init
297 chmod +x "${TEMP}/initrd-temp/linuxrc"
298 chmod +x "${TEMP}/initrd-temp/etc/initrd.scripts"
299 chmod +x "${TEMP}/initrd-temp/etc/initrd.defaults"
300 chmod +x "${TEMP}/initrd-temp/sbin/modprobe"
305 cd ${TEMP}/initrd-temp/
306 TEST=`du -sk 2> /dev/null`
307 echo $TEST | cut "-d " -f1
313 print_info 1 "initrd: >> Initializing..."
314 create_base_initrd_sys
316 if [ "${NOINITRDMODULES}" = '' ]
318 print_info 1 " >> Copying modules..."
319 create_initrd_modules
321 print_info 1 "initrd: Not copying modules..."
324 print_info 1 " >> Copying auxilary files..."
327 INITRD_CALC_SIZE=`calc_initrd_size`
328 INITRD_SIZE=`expr ${INITRD_CALC_SIZE} + 100`
329 print_info 1 " :: Size is at ${INITRD_SIZE}K"
330 print_info 1 " >> Creating loopback filesystem..."
331 create_initrd_loop ${INITRD_SIZE}
333 print_info 1 " >> Moving initrd files to the loopback..."
336 print_info 1 " >> Cleaning up and compressing the initrd..."
337 create_initrd_unmount_loop
339 if [ "${COMPRESS_INITRD}" ]
341 gzip -f -9 ${TEMP}/initrd-${KV}
342 mv ${TEMP}/initrd-${KV}.gz ${TEMP}/initrd-${KV}
345 if [ "${BOOTSPLASH}" -eq "1" ]
347 if [ -x /sbin/splash ]
349 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash.conf ] && source /etc/conf.d/bootsplash.conf
350 [ -z "${BOOTSPLASH_THEME}" ] && [ -e /etc/conf.d/bootsplash ] && source /etc/conf.d/bootsplash
351 [ -z "${BOOTSPLASH_THEME}" ] && BOOTSPLASH_THEME=default
352 print_info 1 " >> Installing bootsplash [ using the ${BOOTSPLASH_THEME} theme ]..."
353 for bootRes in '800x600' '1024x768' '1280x1024' '1600x1200'
355 if [ -f "/etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg" ]
357 /sbin/splash -s -f /etc/bootsplash/${BOOTSPLASH_THEME}/config/bootsplash-${bootRes}.cfg >> ${TEMP}/initrd-${KV} ||
358 gen_die "Error: could not copy ${bootRes} bootsplash!"
360 print_warning 1 "splash: Did not find a bootsplash for the ${bootRes} resolution..."
364 print_warning 1 ' >> No bootsplash detected; skipping!'
367 if ! isTrue "${CMD_NOINSTALL}"
369 cp ${TEMP}/initrd-${KV} /boot/initrd-${KNAME}-${ARCH}-${KV} ||
370 gen_die 'Could not copy the initrd to /boot!'
372 [ "${KERNEL_MAKE_DIRECTIVE}" == 'zImage.initrd' ] ||
373 [ "${KERNEL_MAKE_DIRECTIVE_2}" == 'zImage.initrd' ] &&
374 cp ${TEMP}/initrd-${KV} ${KERNEL_DIR}/arch/${ARCH}/boot/images/ramdisk.image.gz