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 "CACHE_CPIO_DIR: ${CACHE_CPIO_DIR}"
49 CLEAR_CPIO_CACHE='yes'
52 print_info 1 "TMPDIR: ${TMPDIR}"
57 trap trap_cleanup SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL
62 # Parse all command line options...
63 Options=$* # Save for later
70 # Check if no action is specified...
71 if [ "${BUILD_KERNEL}" -eq 0 -a "${BUILD_INITRD}" -eq 0 ]
78 NORMAL=${GOOD} print_info 1 "Gentoo Linux Genkernel; Version ${GK_V}${NORMAL}"
79 print_info 1 "Running with options: ${Options}"
85 # Read arch-specific config
86 source ${ARCH_CONFIG} || gen_die "Could not read ${ARCH_CONFIG}"
87 source ${GK_SHARE}/${ARCH}/modules_load || gen_die "Could not read ${GK_SHARE}/${ARCH}/modules_load"
89 # Merge modules_load from config
90 for group_modules in ${!AMODULES_*}; do
91 group="$(echo $group_modules | cut -d_ -f2)"
92 eval cmodules="\$$group_modules"
93 eval MODULES_${group}=\"\${MODULES_${group}} ${cmodules}\"
94 print_info 1 "<config> Merged AMODULES_${group}:'${cmodules}' into MODULES_${group}"
98 # Based on genkernel.conf, arch-specific configs, and commandline options,
99 # get the real arguments for usage...
103 [ ! -f "${TEMP}" ] && mkdir -p "${TEMP}"
110 NORMAL=${BOLD} print_info 1 "Linux Kernel ${BOLD}${KV}${NORMAL} for ${BOLD}${ARCH}${NORMAL}..."
112 if [ "${BUILD_INITRD}" -ne '0' ]
116 modprobe loop 2>/dev/null
120 print_error 1 'The build-host kernel does not appear to have loop device support.'
121 print_error 1 'Please load loop support before running genkernel!'
122 gen_die 'Load loop support!'
124 print_info 1 'loop: "loop" module loaded successfully...'
129 # Check BOOTDIR is mounted
130 if isTrue ${CMD_NOINSTALL}
132 isTrue ${MOUNTBOOT} && print_info 2 'Skipping automatic mount of boot'
134 [[ -d ${BOOTDIR} ]] || gen_die "${BOOTDIR} is not a directory"
136 if ! egrep -q "[[:space:]]${BOOTDIR}[[:space:]]" /proc/mounts
138 if egrep -q "^[^#].+[[:space:]]${BOOTDIR}[[:space:]]" /etc/fstab
140 if isTrue ${MOUNTBOOT}
142 if ! mount ${BOOTDIR}
144 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to mount ${BOOTDIR}!"
147 print_info 1 "mount: ${BOOTDIR} mounted successfully!"
150 print_warning 1 "${BOLD}WARNING${NORMAL}: No mounted ${BOOTDIR} partition detected!"
151 print_warning 1 " Run ``mount ${BOOTDIR}`` to mount it!"
157 if isTrue ${MOUNTBOOT}
159 if ! mount -o remount,rw ${BOOTDIR}
161 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to remount ${BOOTDIR} RW!"
164 print_info 1 "mount: ${BOOTDIR} remounted read/write successfully!"
171 ## Check whether another Genkernel is running
172 #GENPIDS="`ps -C genkernel --no-headers -o pid | wc -l`"
173 #if [ "${GENPIDS}" -gt '3' ]
175 # [ "${GENPIDS}" -gt '4' ] && EX='s'
176 # print_warning 1 "${BOLD}WARNING${NORMAL}: Another Genkernel instance is running under"
177 # print_warning 1 " process ID${EX} " 0
178 # GENPIDS=`ps -C genkernel --no-headers -o pid`
179 # echo -n "${GENPIDS}" | sed -e "s/$$//; s/ /, /g"
182 # print_warning 1 'Running multiple genkernels on the same source tree will cause data loss!'
183 # print_info 1 "Press ^C to halt; ^D to continue [ ${BOLD}if${NORMAL} you know what you're doing! ]"
186 # TEMP=${TMPDIR-/tmp}
187 # TEMP=${TEMP}/genkernel.$RANDOM.$RANDOM.$RANDOM.$$
188 # print_info 1 'thread: Running multiple genkernels may cause problems!'
189 # print_info 1 "thread: Temporary files reallocated to ${TEMP}..."
194 if [ "${KERNCACHE}" != "" ]
196 gen_kerncache_is_valid
199 if [ ${BUILD_KERNEL} -eq 1 -a "${KERNCACHE_IS_VALID}" == "0" ]
208 if [ "${ARCH_HAVENOPREPARE}" = '' ]
210 [ "${VER}" -gt '2' ] || [ "${VER}" -eq '2' -a "${PAT}" -ge '6' ] && compile_generic prepare kernel
213 # KV may have changed due to the configuration
216 # Compile kernel; If using --genzimage, or building a mips kernel, skip compile
217 # till after initrd/initramfs is done
218 [ "${GENERATE_Z_IMAGE}" = '' -a ${BUILD_INITRAMFS} -eq 0 ] && compile_kernel
221 if [ ${BUILD_MODULES} -eq 1 -a ${BUILD_STATIC} -eq 0 ]
226 if [ ${SAVE_CONFIG} -eq 1 ]
228 print_info 1 "Copying config for successful build to /etc/kernels/kernel-config-${ARCH}-${KV}"
229 [ ! -e '/etc/kernels' ] && mkdir -p /etc/kernels
230 cp "${KERNEL_DIR}/.config" "/etc/kernels/kernel-config-${ARCH}-${KV}"
232 if [ "${KERNCACHE}" != "" ]
234 if [ "${GENERATE_Z_IMAGE}" = '' -a ${BUILD_INITRAMFS} -eq 0 ]
241 if ! isTrue "${CMD_NOINSTALL}"
243 if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ]
245 gen_kerncache_extract_kernel
249 if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ]
251 [ ${BUILD_STATIC} -eq 0 ] && gen_kerncache_extract_modules
252 gen_kerncache_extract_config
257 if [ "${CMD_CALLBACK}" != "" ]
260 print_info 1 "Preparing to run callback: \"${CMD_CALLBACK}\"" 0
265 trap "CALLBACK_ESCAPE=1" TERM KILL INT QUIT ABRT
266 while [[ ${CALLBACK_ESCAPE} -eq 0 && ${CALLBACK_COUNT} -lt 5 ]]
268 sleep 1; echo -n '.';
269 let CALLBACK_COUNT=${CALLBACK_COUNT}+1
272 if [ "${CALLBACK_ESCAPE}" -eq 0 ]
276 eval ${CMD_CALLBACK} | tee -a ${DEBUGFILE}
277 CMD_STATUS="${PIPESTATUS[0]}"
279 print_info 1 "<<< Callback exit status: ${CMD_STATUS}"
280 [ "${CMD_STATUS}" -ne 0 ] && gen_die '--callback failed!'
283 print_info 1 ">>> Callback cancelled..."
285 trap - TERM KILL INT QUIT ABRT
289 if [ "${BUILD_INITRD}" -eq '1' ]
291 # Only compile insmod if we're installing modules onto the initrd
292 if [ "${NOINITRDMODULES}" = '' ]
294 if [ "${KERN_24}" != '1' ]
296 # Compile module-init-tools
297 [ ${BUILD_STATIC} -eq 0 ] && compile_module_init_tools
299 [ ${BUILD_STATIC} -eq 0 ] && compile_modutils
303 [ "${DISKLABEL}" -eq '1' ] && compile_e2fsprogs
305 if [ "${KERN_24}" != '1' -a "${UDEV}" -eq '1' ]
315 if [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
317 if [ "${BUSYBOX}" -eq '1' ]
331 print_info 1 'initrd: Not building since only the kernel was requested...'
335 if [ "${GENERATE_Z_IMAGE}" != '' -o ${BUILD_INITRAMFS} -eq 1 ]
337 # Compile kernel, intergrating the initrd into it for Pegasos & mips
340 # We skipped the kernel build and kerncache generation
342 [ "${KERNCACHE}" != "" ] && gen_kerncache
345 [ "${MINKERNPACKAGE}" != '' ] && gen_minkernpackage
346 [ "${MODULESPACKAGE}" != '' ] && gen_modulespackage
349 [ -n "${CTEMP}" ] && rm -rf "${TEMP}"
351 if [ "${BUILD_KERNEL}" -eq '1' ]
355 print_info 1 "Kernel compiled successfully!"
357 print_info 1 'Required Kernel Parameters:'
358 if [ "${BUILD_INITRD}" -eq '0' ]
360 print_info 1 ' root=/dev/$ROOT'
361 print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]'
363 print_info 1 ' Where $ROOT is the device node for your root partition as the'
364 print_info 1 ' one specified in /etc/fstab'
365 elif [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
367 print_info 1 ' real_root=/dev/$ROOT'
369 print_info 1 ' Where $ROOT is the device node for your root partition as the'
370 print_info 1 ' one specified in /etc/fstab'
372 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
373 print_info 1 'tell your bootloader to use the provided INITRAMFS file. Otherwise;'
374 print_info 1 'substitute the root argument for the real_root argument if you are'
375 print_info 1 'not planning to use the initrd...'
377 print_info 1 ' root=/dev/ram0 real_root=/dev/$ROOT init=/linuxrc'
378 [ "${INITRD_SIZE}" -ge 4096 ] && print_info 1 " ramdisk_size=${INITRD_SIZE}"
380 print_info 1 ' Where $ROOT is the device node for your root partition as the'
381 print_info 1 ' one specified in /etc/fstab'
383 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
384 print_info 1 'tell your bootloader to use the provided INITRD file. Otherwise;'
385 print_info 1 'substitute the root argument for the real_root argument if you are'
386 print_info 1 'not planning to use the initrd...'
390 if [ "${BUILD_INITRD}" -eq '1' ]
393 print_info 1 'WARNING... WARNING... WARNING...'
394 print_info 1 'Additional kernel cmdline arguments that *may* be required to boot properly...'
395 [ "${GENSPLASH}" -eq '1' ] && print_info 1 "add \"vga=791 splash=silent,theme:${GENSPLASH_THEME} CONSOLE=/dev/tty1 quiet\" if you use a gensplash framebuffer ]"
396 [ "${BOOTSPLASH}" -eq '1' ] && print_info 1 'add "vga=791 splash=silent" if you use a bootsplash framebuffer'
397 [ "${LVM2}" -eq '1' ] && print_info 1 'add "dolvm2" for lvm2 support'
398 [ "${EVMS2}" -eq '1' ] && print_info 1 'add "doevms2" for evms support'
399 [ "${DMRAID}" -eq '1' ] && print_info 1 'add "dodmraid" for dmraid support'
400 [ "${DMRAID}" -eq '1' ] && print_info 1 ' or "dodmraid=<additional options>"'
401 [ "${UNIONFS}" -eq '1' ] && print_info 1 'add "unionfs" for unionfs support'
402 [ "${UNIONFS}" -eq '1' ] && print_info 1 ' or "unionfs=<block_device>"'
408 local fullVer=${KNAME}-${ARCH}-${KV}
410 local newThing=${BOOTDIR}/${base}-${fullVer}
411 local newSym=${BOOTDIR}/${base}
412 local oldSym=${newsym}.old
417 print_info 1 " creating ${base} name symlink!"
418 if [ -e ${newThing} ] ; then
419 if [ -L ${newSym} ] ; then
420 prevLink=`readlink --no-newline ${newSym}`
421 if [ ${prevLink} != ${newThing} ] ; then
422 if [ -L ${oldSym} ] ; then
425 ln -s ${prevLink} ${oldSym}
430 ln -s ${newThing} ${newSym}
434 if [[ ${ret} > 0 ]] ; then
435 print_error 1 " $base link failed: ${ret}"
442 if [ "${CMD_NOINSTALL}" != '1' -a "${SYMLINK}" = '1' ]
445 print_info 1 'Creating symlinks'
451 if [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ] ; then
459 [ "${BOOTRW}" != '' ] && mount -o remount,ro ${BOOTDIR}
462 print_info 1 'Do NOT report kernel bugs as genkernel bugs unless your bug'
463 print_info 1 'is about the default genkernel configuration...'
465 print_info 1 'Make sure you have the latest genkernel before reporting bugs.'