4 PATH="/bin:/usr/bin:/sbin:/usr/sbin"
7 TMPDIR='/var/tmp/genkernel'
8 TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$
9 TODEBUGCACHE=1 # Until an error occurs or DEBUGFILE is fully qualified.
16 source /etc/genkernel.conf || small_die "Could not read /etc/genkernel.conf"
17 source ${GK_BIN}/gen_funcs.sh || small_die "Could not read ${GK_BIN}/gen_funcs.sh"
18 source ${GK_BIN}/gen_cmdline.sh || gen_die "Could not read ${GK_BIN}/gen_cmdline.sh"
19 source ${GK_BIN}/gen_arch.sh || gen_die "Could not read ${GK_BIN}/gen_arch.sh"
20 source ${GK_BIN}/gen_determineargs.sh || gen_die "Could not read ${GK_BIN}/gen_determineargs.sh"
21 source ${GK_BIN}/gen_compile.sh || gen_die "Could not read ${GK_BIN}/gen_compile.sh"
22 source ${GK_BIN}/gen_configkernel.sh || gen_die "Could not read ${GK_BIN}/gen_configkernel.sh"
23 source ${GK_BIN}/gen_initrd.sh || gen_die "Could not read ${GK_BIN}/gen_initrd.sh"
24 source ${GK_BIN}/gen_initramfs.sh || gen_die "Could not read ${GK_BIN}/gen_initramfs.sh"
25 source ${GK_BIN}/gen_moddeps.sh || gen_die "Could not read ${GK_BIN}/gen_moddeps.sh"
26 source ${GK_BIN}/gen_package.sh || gen_die "Could not read ${GK_BIN}/gen_package.sh"
27 source ${GK_BIN}/gen_bootloader.sh || gen_die "Could not read ${GK_BIN}/gen_bootloader.sh"
30 # Call exit code of 1 for failure
36 if [ -n "$TEMP" -a -d "$TEMP" ]; then
40 if isTrue ${POSTCLEAR}
43 print_info 1 'RUNNING FINAL CACHE/TMP CLEANUP'
44 print_info 1 "CACHE_DIR: ${CACHE_DIR}"
48 print_info 1 "TMPDIR: ${TMPDIR}"
53 trap trap_cleanup SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL
58 # Parse all command line options...
59 Options=$* # Save for later
66 # Check if no action is specified...
67 if [ "${BUILD_KERNEL}" -eq 0 -a "${BUILD_INITRD}" -eq 0 ]
74 NORMAL=${GOOD} print_info 1 "Gentoo Linux Genkernel; Version ${GK_V}${NORMAL}"
75 print_info 1 "Running with options: ${Options}"
81 # Read arch-specific config
82 source ${ARCH_CONFIG} || gen_die "Could not read ${ARCH_CONFIG}"
83 source ${GK_SHARE}/${ARCH}/modules_load || gen_die "Could not read ${GK_SHARE}/${ARCH}/modules_load"
85 # Merge modules_load from config
86 for group_modules in ${!AMODULES_*}; do
87 group="$(echo $group_modules | cut -d_ -f2)"
88 eval cmodules="\$$group_modules"
89 eval MODULES_${group}=\"\${MODULES_${group}} ${cmodules}\"
90 print_info 1 "<config> Merged AMODULES_${group}:'${cmodules}' into MODULES_${group}"
94 # Based on genkernel.conf, arch-specific configs, and commandline options,
95 # get the real arguments for usage...
99 [ ! -f "${TEMP}" ] && mkdir -p "${TEMP}"
106 NORMAL=${BOLD} print_info 1 "Linux Kernel ${BOLD}${KV}${NORMAL} for ${BOLD}${ARCH}${NORMAL}..."
108 if [ "${BUILD_INITRD}" -ne '0' ]
112 modprobe loop 2>/dev/null
116 print_error 1 'The build-host kernel does not appear to have loop device support.'
117 print_error 1 'Please load loop support before running genkernel!'
118 gen_die 'Load loop support!'
120 print_info 1 'loop: "loop" module loaded successfully...'
125 # Check BOOTDIR is mounted
126 if isTrue ${CMD_NOINSTALL}
128 isTrue ${MOUNTBOOT} && print_info 2 'Skipping automatic mount of boot'
130 [[ -d ${BOOTDIR} ]] || gen_die "${BOOTDIR} is not a directory"
132 if ! egrep -q "[[:space:]]${BOOTDIR}[[:space:]]" /proc/mounts
134 if egrep -q "^[^#].+[[:space:]]${BOOTDIR}[[:space:]]" /etc/fstab
136 if isTrue ${MOUNTBOOT}
138 if ! mount ${BOOTDIR}
140 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to mount ${BOOTDIR}!"
143 print_info 1 "mount: ${BOOTDIR} mounted successfully!"
146 print_warning 1 "${BOLD}WARNING${NORMAL}: No mounted ${BOOTDIR} partition detected!"
147 print_warning 1 " Run ``mount ${BOOTDIR}`` to mount it!"
153 if isTrue ${MOUNTBOOT}
155 if ! mount -o remount,rw ${BOOTDIR}
157 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to remount ${BOOTDIR} RW!"
160 print_info 1 "mount: ${BOOTDIR} remounted read/write successfully!"
167 ## Check whether another Genkernel is running
168 #GENPIDS="`ps -C genkernel --no-headers -o pid | wc -l`"
169 #if [ "${GENPIDS}" -gt '3' ]
171 # [ "${GENPIDS}" -gt '4' ] && EX='s'
172 # print_warning 1 "${BOLD}WARNING${NORMAL}: Another Genkernel instance is running under"
173 # print_warning 1 " process ID${EX} " 0
174 # GENPIDS=`ps -C genkernel --no-headers -o pid`
175 # echo -n "${GENPIDS}" | sed -e "s/$$//; s/ /, /g"
178 # print_warning 1 'Running multiple genkernels on the same source tree will cause data loss!'
179 # print_info 1 "Press ^C to halt; ^D to continue [ ${BOLD}if${NORMAL} you know what you're doing! ]"
182 # TEMP=${TMPDIR-/tmp}
183 # TEMP=${TEMP}/genkernel.$RANDOM.$RANDOM.$RANDOM.$$
184 # print_info 1 'thread: Running multiple genkernels may cause problems!'
185 # print_info 1 "thread: Temporary files reallocated to ${TEMP}..."
190 if [ "${KERNCACHE}" != "" ]
192 gen_kerncache_is_valid
195 if [ ${BUILD_KERNEL} -eq 1 -a "${KERNCACHE_IS_VALID}" == "0" ]
204 if [ "${ARCH_HAVENOPREPARE}" = '' ]
206 [ "${VER}" -gt '2' ] || [ "${VER}" -eq '2' -a "${PAT}" -ge '6' ] && compile_generic prepare kernel
209 # KV may have changed due to the configuration
212 # Compile kernel; If using --genzimage, or building a mips kernel, skip compile
213 # till after initrd/initramfs is done
214 [ "${GENERATE_Z_IMAGE}" = '' -a ${BUILD_INITRAMFS} -eq 0 ] && compile_kernel
217 if [ ${BUILD_MODULES} -eq 1 -a ${BUILD_STATIC} -eq 0 ]
222 if [ ${SAVE_CONFIG} -eq 1 ]
224 print_info 1 "Copying config for successful build to /etc/kernels/kernel-config-${ARCH}-${KV}"
225 [ ! -e '/etc/kernels' ] && mkdir -p /etc/kernels
226 cp "${KERNEL_DIR}/.config" "/etc/kernels/kernel-config-${ARCH}-${KV}"
228 if [ "${KERNCACHE}" != "" ]
230 if [ "${GENERATE_Z_IMAGE}" = '' -a ${BUILD_INITRAMFS} -eq 0 ]
237 if ! isTrue "${CMD_NOINSTALL}"
239 if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ]
241 gen_kerncache_extract_kernel
245 if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ]
247 [ ${BUILD_STATIC} -eq 0 ] && gen_kerncache_extract_modules
248 gen_kerncache_extract_config
253 if [ "${CMD_CALLBACK}" != "" ]
256 print_info 1 "Preparing to run callback: \"${CMD_CALLBACK}\"" 0
261 trap "CALLBACK_ESCAPE=1" TERM KILL INT QUIT ABRT
262 while [[ ${CALLBACK_ESCAPE} -eq 0 && ${CALLBACK_COUNT} -lt 5 ]]
264 sleep 1; echo -n '.';
265 let CALLBACK_COUNT=${CALLBACK_COUNT}+1
268 if [ "${CALLBACK_ESCAPE}" -eq 0 ]
272 eval ${CMD_CALLBACK} | tee -a ${DEBUGFILE}
273 CMD_STATUS="${PIPESTATUS[0]}"
275 print_info 1 "<<< Callback exit status: ${CMD_STATUS}"
276 [ "${CMD_STATUS}" -ne 0 ] && gen_die '--callback failed!'
279 print_info 1 ">>> Callback cancelled..."
281 trap - TERM KILL INT QUIT ABRT
285 if [ "${BUILD_INITRD}" -eq '1' ]
287 # Only compile insmod if we're installing modules onto the initrd
288 if [ "${NOINITRDMODULES}" = '' ]
290 if [ "${KERN_24}" != '1' ]
292 # Compile module-init-tools
293 [ ${BUILD_STATIC} -eq 0 ] && compile_module_init_tools
295 [ ${BUILD_STATIC} -eq 0 ] && compile_modutils
299 [ "${DISKLABEL}" -eq '1' ] && compile_e2fsprogs
301 if [ "${KERN_24}" != '1' -a "${UDEV}" -eq '1' ]
311 if [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
313 if [ "${BUSYBOX}" -eq '1' ]
327 print_info 1 'initrd: Not building since only the kernel was requested...'
331 if [ "${GENERATE_Z_IMAGE}" != '' -o ${BUILD_INITRAMFS} -eq 1 ]
333 # Compile kernel, intergrating the initrd into it for Pegasos & mips
336 # We skipped the kernel build and kerncache generation
338 [ "${KERNCACHE}" != "" ] && gen_kerncache
341 [ "${MINKERNPACKAGE}" != '' ] && gen_minkernpackage
342 [ "${MODULESPACKAGE}" != '' ] && gen_modulespackage
345 [ -n "${CTEMP}" ] && rm -rf "${TEMP}"
347 if [ "${BUILD_KERNEL}" -eq '1' ]
351 print_info 1 "Kernel compiled successfully!"
353 print_info 1 'Required Kernel Parameters:'
354 if [ "${BUILD_INITRD}" -eq '0' ]
356 print_info 1 ' root=/dev/$ROOT'
357 print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]'
359 print_info 1 ' Where $ROOT is the device node for your root partition as the'
360 print_info 1 ' one specified in /etc/fstab'
361 elif [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
363 print_info 1 ' real_root=/dev/$ROOT'
365 print_info 1 ' Where $ROOT is the device node for your root partition as the'
366 print_info 1 ' one specified in /etc/fstab'
368 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
369 print_info 1 'tell your bootloader to use the provided INITRAMFS file. Otherwise;'
370 print_info 1 'substitute the root argument for the real_root argument if you are'
371 print_info 1 'not planning to use the initrd...'
373 print_info 1 ' root=/dev/ram0 real_root=/dev/$ROOT init=/linuxrc'
374 [ "${INITRD_SIZE}" -ge 4096 ] && print_info 1 " ramdisk_size=${INITRD_SIZE}"
376 print_info 1 ' Where $ROOT is the device node for your root partition as the'
377 print_info 1 ' one specified in /etc/fstab'
379 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
380 print_info 1 'tell your bootloader to use the provided INITRD file. Otherwise;'
381 print_info 1 'substitute the root argument for the real_root argument if you are'
382 print_info 1 'not planning to use the initrd...'
386 if [ "${BUILD_INITRD}" -eq '1' ]
389 print_info 1 'WARNING... WARNING... WARNING...'
390 print_info 1 'Additional kernel cmdline arguments that *may* be required to boot properly...'
391 [ "${GENSPLASH}" -eq '1' ] && print_info 1 "add \"vga=791 splash=silent,theme:${GENSPLASH_THEME} CONSOLE=/dev/tty1 quiet\" if you use a gensplash framebuffer ]"
392 [ "${BOOTSPLASH}" -eq '1' ] && print_info 1 'add "vga=791 splash=silent" if you use a bootsplash framebuffer'
393 [ "${LVM2}" -eq '1' ] && print_info 1 'add "dolvm2" for lvm2 support'
394 [ "${EVMS2}" -eq '1' ] && print_info 1 'add "doevms2" for evms support'
395 [ "${DMRAID}" -eq '1' ] && print_info 1 'add "dodmraid" for dmraid support'
396 [ "${DMRAID}" -eq '1' ] && print_info 1 ' or "dodmraid=<additional options>"'
397 [ "${UNIONFS}" -eq '1' ] && print_info 1 'add "unionfs" for unionfs support'
398 [ "${UNIONFS}" -eq '1' ] && print_info 1 ' or "unionfs=<block_device>"'
404 local fullVer=${KNAME}-${ARCH}-${KV}
406 local newThing=${BOOTDIR}/${base}-${fullVer}
407 local newSym=${BOOTDIR}/${base}
408 local oldSym=${newSym}.old
413 print_info 1 " creating ${base} name symlink!"
414 if [ -e ${newThing} ] ; then
415 if [ -L ${newSym} ] ; then
416 prevLink=`readlink --no-newline ${newSym}`
417 if [ ${prevLink} != ${newThing} ] ; then
418 if [ -L ${oldSym} ] ; then
421 ln -s ${prevLink} ${oldSym}
426 ln -s ${newThing} ${newSym}
430 if [[ ${ret} > 0 ]] ; then
431 print_error 1 " $base link failed: ${ret}"
438 if [ "${CMD_NOINSTALL}" != '1' -a "${SYMLINK}" = '1' ]
441 print_info 1 'Creating symlinks'
447 if [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ] ; then
455 [ "${BOOTRW}" != '' ] && mount -o remount,ro ${BOOTDIR}
458 print_info 1 'Do NOT report kernel bugs as genkernel bugs unless your bug'
459 print_info 1 'is about the default genkernel configuration...'
461 print_info 1 'Make sure you have the latest genkernel before reporting bugs.'