4 PATH="/bin:/usr/bin:/sbin:/usr/sbin"
7 TMPDIR='/var/tmp/genkernel'
8 TODEBUGCACHE=1 # Until an error occurs or DEBUGFILE is fully qualified.
15 source /etc/genkernel.conf || small_die "Could not read /etc/genkernel.conf"
16 source ${GK_BIN}/gen_funcs.sh || small_die "Could not read ${GK_BIN}/gen_funcs.sh"
17 source ${GK_BIN}/gen_cmdline.sh || gen_die "Could not read ${GK_BIN}/gen_cmdline.sh"
18 source ${GK_BIN}/gen_arch.sh || gen_die "Could not read ${GK_BIN}/gen_arch.sh"
19 source ${GK_BIN}/gen_determineargs.sh || gen_die "Could not read ${GK_BIN}/gen_determineargs.sh"
20 source ${GK_BIN}/gen_compile.sh || gen_die "Could not read ${GK_BIN}/gen_compile.sh"
21 source ${GK_BIN}/gen_configkernel.sh || gen_die "Could not read ${GK_BIN}/gen_configkernel.sh"
22 source ${GK_BIN}/gen_initrd.sh || gen_die "Could not read ${GK_BIN}/gen_initrd.sh"
23 source ${GK_BIN}/gen_initramfs.sh || gen_die "Could not read ${GK_BIN}/gen_initramfs.sh"
24 source ${GK_BIN}/gen_moddeps.sh || gen_die "Could not read ${GK_BIN}/gen_moddeps.sh"
25 source ${GK_BIN}/gen_package.sh || gen_die "Could not read ${GK_BIN}/gen_package.sh"
26 source ${GK_BIN}/gen_bootloader.sh || gen_die "Could not read ${GK_BIN}/gen_bootloader.sh"
28 TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$
31 #Call exit code of 1 for failure
37 if [ -n "$TEMP" -a -d "$TEMP" ]; then
41 if isTrue ${POSTCLEAR}
44 print_info 1 'RUNNING FINAL CACHE/TMP CLEANUP'
45 print_info 1 "CACHE_DIR: ${CACHE_DIR}"
49 print_info 1 "CACHE_CPIO_DIR: ${CACHE_CPIO_DIR}"
50 CLEAR_CPIO_CACHE='yes'
53 print_info 1 "TMPDIR: ${TMPDIR}"
58 trap trap_cleanup SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL
63 # Parse all command line options...
64 Options=$* # Save for later
71 # Check if no action is specified...
72 if [ "${BUILD_KERNEL}" -eq 0 -a "${BUILD_INITRD}" -eq 0 ]
79 NORMAL=${GOOD} print_info 1 "Gentoo Linux Genkernel; Version ${GK_V}${NORMAL}"
80 print_info 1 "Running with options: ${Options}"
86 # Read arch-specific config
87 source ${ARCH_CONFIG} || gen_die "Could not read ${ARCH_CONFIG}"
88 source ${GK_SHARE}/${ARCH}/modules_load || gen_die "Could not read ${GK_SHARE}/${ARCH}/modules_load"
90 # Merge modules_load from config
91 for group_modules in ${!AMODULES_*}; do
92 group="$(echo $group_modules | cut -d_ -f2)"
93 eval cmodules="\$$group_modules"
94 eval MODULES_${group}=\"\${MODULES_${group}} ${cmodules}\"
95 print_info 1 "<config> Merged AMODULES_${group}:'${cmodules}' into MODULES_${group}"
99 # Based on genkernel.conf, arch-specific configs, and commandline options,
100 # get the real arguments for usage...
104 [ ! -f "${TEMP}" ] && mkdir -p "${TEMP}"
111 NORMAL=${BOLD} print_info 1 "Linux Kernel ${BOLD}${KV}${NORMAL} for ${BOLD}${ARCH}${NORMAL}..."
113 if [ "${BUILD_INITRD}" -ne '0' ]
117 modprobe loop 2>/dev/null
121 print_error 1 'The build-host kernel does not appear to have loop device support.'
122 print_error 1 'Please load loop support before running genkernel!'
123 gen_die 'Load loop support!'
125 print_info 1 'loop: "loop" module loaded successfully...'
130 # Check /boot is mounted
131 if isTrue ${CMD_NOINSTALL}
133 isTrue ${MOUNTBOOT} && print_info 2 'Skipping automatic mount of boot'
135 if ! egrep -q ' /boot ' /proc/mounts
137 if egrep -q '^[^#].+ /boot ' /etc/fstab
139 if isTrue ${MOUNTBOOT}
143 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to mount /boot!"
146 print_info 1 'mount: /boot mounted successfully!'
149 print_warning 1 "${BOLD}WARNING${NORMAL}: No mounted /boot partition detected!"
150 print_warning 1 ' Run ``mount /boot`` to mount it!'
156 if isTrue ${MOUNTBOOT}
158 if ! mount -o remount,rw /boot
160 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to remount /boot RW!"
163 print_info 1 "mount: /boot remounted read/write successfully!"
170 # Check whether another Genkernel is running
171 GENPIDS="`ps -C genkernel --no-headers -o pid | wc -l`"
172 if [ "${GENPIDS}" -gt '3' ]
174 [ "${GENPIDS}" -gt '4' ] && EX='s'
175 print_warning 1 "${BOLD}WARNING${NORMAL}: Another Genkernel instance is running under"
176 print_warning 1 " process ID${EX} " 0
177 GENPIDS=`ps -C genkernel --no-headers -o pid`
178 echo -n "${GENPIDS}" | sed -e "s/$$//; s/ /, /g"
181 print_warning 1 'Running multiple genkernels on the same source tree will cause data loss!'
182 print_info 1 "Press ^C to halt; ^D to continue [ ${BOLD}if${NORMAL} you know what you're doing! ]"
186 TEMP=${TEMP}/genkernel.$RANDOM.$RANDOM.$RANDOM.$$
187 print_info 1 'thread: Running multiple genkernels may cause problems!'
188 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
217 [ "${GENERATE_Z_IMAGE}" = '' ] && compile_kernel
220 if [ ${BUILD_MODULES} -eq 1 ]
225 if [ ${SAVE_CONFIG} -eq 1 ]
227 print_info 1 "Copying config for successful build to /etc/kernels/kernel-config-${ARCH}-${KV}"
228 [ ! -e '/etc/kernels' ] && mkdir -p /etc/kernels
229 cp "${KERNEL_DIR}/.config" "/etc/kernels/kernel-config-${ARCH}-${KV}"
231 [ "${KERNCACHE}" != "" ] && gen_kerncache
234 if ! isTrue "${CMD_NOINSTALL}"
236 if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ]
238 gen_kerncache_extract_kernel
242 if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ]
244 gen_kerncache_extract_modules
248 if [ "${CMD_CALLBACK}" != "" ]
251 print_info 1 "Preparing to run callback: \"${CMD_CALLBACK}\"" 0
256 trap "CALLBACK_ESCAPE=1" TERM KILL INT QUIT ABRT
257 while [[ ${CALLBACK_ESCAPE} -eq 0 && ${CALLBACK_COUNT} -lt 5 ]]
259 sleep 1; echo -n '.';
260 let CALLBACK_COUNT=${CALLBACK_COUNT}+1
263 if [ "${CALLBACK_ESCAPE}" -eq 0 ]
267 eval ${CMD_CALLBACK} | tee -a ${DEBUGFILE}
268 CMD_STATUS="${PIPESTATUS[0]}"
270 print_info 1 "<<< Callback exit status: ${CMD_STATUS}"
271 [ "${CMD_STATUS}" -ne 0 ] && gen_die '--callback failed!'
274 print_info 1 ">>> Callback cancelled..."
276 trap - TERM KILL INT QUIT ABRT
280 if [ "${BUILD_INITRD}" -eq '1' ]
282 # Only compile insmod if we're installing modules onto the initrd
283 if [ "${NOINITRDMODULES}" = '' ]
285 if [ "${KERN_24}" != '1' ]
287 # Compile module-init-tools
288 compile_module_init_tools
294 [ "${DISKLABEL}" -eq '1' ] && compile_e2fsprogs
296 if [ "${KERN_24}" != '1' -a "${UDEV}" -eq '1' ]
305 if [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
307 if [ "${BUSYBOX}" -eq '1' ]
321 print_info 1 'initrd: Not building since only the kernel was requested...'
325 if [ "${GENERATE_Z_IMAGE}" != '' ]
327 # Compile kernel, intergrating the initrd into it for Pegasos
331 [ "${MINKERNPACKAGE}" != '' ] && gen_minkernpackage
332 [ "${MODULESPACKAGE}" != '' ] && gen_modulespackage
335 [ -n "${CTEMP}" ] && rm -rf "${TEMP}"
337 if [ "${BUILD_KERNEL}" -eq '1' ]
341 print_info 1 "Kernel compiled successfully!"
343 print_info 1 'Required Kernel Parameters:'
344 if [ "${BUILD_INITRD}" -eq '0' ]
346 print_info 1 ' root=/dev/$ROOT'
347 print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]'
349 print_info 1 ' Where $ROOT is the device node for your root partition as the'
350 print_info 1 ' one specified in /etc/fstab'
351 elif [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
353 print_info 1 ' real_root=/dev/$ROOT'
355 print_info 1 ' Where $ROOT is the device node for your root partition as the'
356 print_info 1 ' one specified in /etc/fstab'
358 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
359 print_info 1 'tell your bootloader to use the provided INITRAMFS file. Otherwise;'
360 print_info 1 'substitute the root argument for the real_root argument if you are'
361 print_info 1 'not planning to use the initrd...'
363 print_info 1 ' root=/dev/ram0 real_root=/dev/$ROOT init=/linuxrc'
364 [ "${INITRD_SIZE}" -ge 4096 ] && print_info 1 " ramdisk_size=${INITRD_SIZE}"
366 print_info 1 ' Where $ROOT is the device node for your root partition as the'
367 print_info 1 ' one specified in /etc/fstab'
369 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
370 print_info 1 'tell your bootloader to use the provided INITRD file. Otherwise;'
371 print_info 1 'substitute the root argument for the real_root argument if you are'
372 print_info 1 'not planning to use the initrd...'
376 if [ "${BUILD_INITRD}" -eq '1' ]
379 print_info 1 'WARNING... WARNING... WARNING...'
380 print_info 1 'Additional kernel cmdline arguments that *may* be required to boot properly...'
381 [ "${GENSPLASH}" -eq '1' ] && print_info 1 "add \"vga=791 splash=silent,theme:${GENSPLASH_THEME} CONSOLE=/dev/tty1 quiet\" if you use a gensplash framebuffer ]"
382 [ "${BOOTSPLASH}" -eq '1' ] && print_info 1 'add "vga=791 splash=silent" if you use a bootsplash framebuffer'
383 [ "${LVM2}" -eq '1' ] && print_info 1 'add "dolvm2" for lvm2 support'
384 [ "${EVMS2}" -eq '1' ] && print_info 1 'add "doevms" for evms support'
385 [ "${DMRAID}" -eq '1' ] && print_info 1 'add "dodmraid" for dmraid support'
386 [ "${DMRAID}" -eq '1' ] && print_info 1 ' or "dodmraid=<additional options>"'
387 [ "${UNIONFS}" -eq '1' ] && print_info 1 'add "unionfs" for unionfs support'
388 [ "${UNIONFS}" -eq '1' ] && print_info 1 ' or "unionfs=<block_device>"'
391 if [ "${CMD_NOINSTALL}" != '1' -a "${SYMLINK}" = '1' ]
394 print_info 1 'Creating symlinks'
397 print_info 1 ' creating kernel name symlink!'
398 if [ -e /boot/kernel-${KNAME}-${ARCH}-${KV} ]
401 ln -s /boot/kernel-${KNAME}-${ARCH}-${KV} /boot/kernel
403 [ ${ret} = '1' ] && print_error 1 'kernel link failed'
406 if [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
408 print_info 1 ' creating initramfs name symlink!'
409 if [ -e /boot/initramfs-${KNAME}-${ARCH}-${KV} ]
411 /bin/rm /boot/initramfs
412 ln -s /boot/initramfs-${KNAME}-${ARCH}-${KV} /boot/initramfs
414 [ ${ret} = '1' ] && print_error 1 'initramfs link failed'
417 print_info 1 ' creating initrd name symlink!'
418 if [ -e /boot/initrd-${KNAME}-${ARCH}-${KV} ]
421 ln -s /boot/initrd-${KNAME}-${ARCH}-${KV} /boot/initrd
423 [ ${ret} = '1' ] && print_error 1 'initrd link failed'
429 [ "${BOOTRW}" != '' ] && mount -o remount,ro /boot
432 print_info 1 'Do NOT report kernel bugs as genkernel bugs unless your bug'
433 print_info 1 'is about the default genkernel configuration...'
435 print_info 1 'Make sure you have the latest genkernel before reporting bugs.'