4 PATH="/bin:/usr/bin:/sbin:/usr/sbin"
7 TEMP='/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=${TEMP}/$RANDOM.$RANDOM.$RANDOM.$$
31 if [ -n "$TEMP" -a -d "$TEMP" ]; then
35 if isTrue ${POSTCLEAR}
38 print_info 1 'RUNNING FINAL CACHE/TMP CLEANUP'
39 print_info 1 "CACHE_DIR: ${CACHE_DIR}"
43 print_info 1 "CACHE_CPIO_DIR: ${CACHE_CPIO_DIR}"
44 CLEAR_CPIO_CACHE='yes'
46 ls -la ${CACHE_CPIO_DIR}
51 trap cleanup SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL
56 # Parse all command line options...
57 Options=$* # Save for later
64 # Check if no action is specified...
65 if [ "${BUILD_KERNEL}" -eq 0 -a "${BUILD_INITRD}" -eq 0 ]
72 NORMAL=${GOOD} print_info 1 "Gentoo Linux Genkernel; Version ${GK_V}${NORMAL}"
73 print_info 1 "Running with options: ${Options}"
79 # Read arch-specific config
80 source ${ARCH_CONFIG} || gen_die "Could not read ${ARCH_CONFIG}"
81 source ${GK_SHARE}/${ARCH}/modules_load || gen_die "Could not read ${GK_SHARE}/${ARCH}/modules_load"
83 # Merge modules_load from config
84 for group_modules in ${!AMODULES_*}; do
85 group="$(echo $group_modules | cut -d_ -f2)"
86 eval cmodules="\$$group_modules"
87 eval MODULES_${group}=\"\${MODULES_${group}} ${cmodules}\"
88 print_info 1 "<config> Merged AMODULES_${group}:'${cmodules}' into MODULES_${group}"
92 # Based on genkernel.conf, arch-specific configs, and commandline options,
93 # get the real arguments for usage...
97 [ ! -f "${TEMP}" ] && mkdir -p "${TEMP}"
104 NORMAL=${BOLD} print_info 1 "Linux Kernel ${BOLD}${KV}${NORMAL} for ${BOLD}${ARCH}${NORMAL}..."
106 if [ "${BUILD_INITRD}" -ne '0' ]
110 modprobe loop 2>/dev/null
114 print_error 1 'The build-host kernel does not appear to have loop device support.'
115 print_error 1 'Please load loop support before running genkernel!'
116 gen_die 'Load loop support!'
118 print_info 1 'loop: "loop" module loaded successfully...'
123 # Check /boot is mounted
124 if isTrue ${CMD_NOINSTALL}
126 isTrue ${MOUNTBOOT} && print_info 2 'Skipping automatic mount of boot'
128 if ! egrep -q ' /boot ' /proc/mounts
130 if egrep -q '^[^#].+ /boot ' /etc/fstab
132 if isTrue ${MOUNTBOOT}
136 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to mount /boot!"
139 print_info 1 'mount: /boot mounted successfully!'
142 print_warning 1 "${BOLD}WARNING${NORMAL}: No mounted /boot partition detected!"
143 print_warning 1 ' Run ``mount /boot`` to mount it!'
149 if isTrue ${MOUNTBOOT}
151 if ! mount -o remount,rw /boot
153 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to remount /boot RW!"
156 print_info 1 "mount: /boot remounted read/write successfully!"
163 # Check whether another Genkernel is running
164 GENPIDS="`ps -C genkernel --no-headers -o pid | wc -l`"
165 if [ "${GENPIDS}" -gt '3' ]
167 [ "${GENPIDS}" -gt '4' ] && EX='s'
168 print_warning 1 "${BOLD}WARNING${NORMAL}: Another Genkernel instance is running under"
169 print_warning 1 " process ID${EX} " 0
170 GENPIDS=`ps -C genkernel --no-headers -o pid`
171 echo -n "${GENPIDS}" | sed -e "s/$$//; s/ /, /g"
174 print_warning 1 'Running multiple genkernels on the same source tree will cause data loss!'
175 print_info 1 "Press ^C to halt; ^D to continue [ ${BOLD}if${NORMAL} you know what you're doing! ]"
179 TEMP=${TEMP}/genkernel.$RANDOM.$RANDOM.$RANDOM.$$
180 print_info 1 'thread: Running multiple genkernels may cause problems!'
181 print_info 1 "thread: Temporary files reallocated to ${TEMP}..."
187 if [ "${KERNCACHE}" != "" ]
189 gen_kerncache_is_valid
192 if [ ${BUILD_KERNEL} -eq 1 -a "${KERNCACHE_IS_VALID}" == "0" ]
201 if [ "${ARCH_HAVENOPREPARE}" = '' ]
203 [ "${VER}" -gt '2' ] || [ "${VER}" -eq '2' -a "${PAT}" -ge '6' ] && compile_generic prepare kernel
206 # KV may have changed due to the configuration
210 [ "${GENERATE_Z_IMAGE}" = '' ] && compile_kernel
213 if [ ${BUILD_MODULES} -eq 1 ]
218 if [ ${SAVE_CONFIG} -eq 1 ]
220 print_info 1 "Copying config for successful build to /etc/kernels/kernel-config-${ARCH}-${KV}"
221 [ ! -e '/etc/kernels' ] && mkdir -p /etc/kernels
222 cp "${KERNEL_DIR}/.config" "/etc/kernels/kernel-config-${ARCH}-${KV}"
224 [ "${KERNCACHE}" != "" ] && gen_kerncache
227 if ! isTrue "${CMD_NOINSTALL}"
229 if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ]
231 gen_kerncache_extract_kernel
235 if [ "${KERNCACHE}" != "" -a "${KERNCACHE_IS_VALID}" != "0" ]
237 gen_kerncache_extract_modules
241 if [ "${CMD_CALLBACK}" != "" ]
244 print_info 1 "Preparing to run callback: \"${CMD_CALLBACK}\"" 0
249 trap "CALLBACK_ESCAPE=1" TERM KILL INT QUIT ABRT
250 while [[ ${CALLBACK_ESCAPE} -eq 0 && ${CALLBACK_COUNT} -lt 5 ]]
252 sleep 1; echo -n '.';
253 let CALLBACK_COUNT=${CALLBACK_COUNT}+1
256 if [ "${CALLBACK_ESCAPE}" -eq 0 ]
260 eval ${CMD_CALLBACK} | tee -a ${DEBUGFILE}
261 CMD_STATUS="${PIPESTATUS[0]}"
263 print_info 1 "<<< Callback exit status: ${CMD_STATUS}"
264 [ "${CMD_STATUS}" -ne 0 ] && gen_die '--callback failed!'
267 print_info 1 ">>> Callback cancelled..."
269 trap - TERM KILL INT QUIT ABRT
273 if [ "${BUILD_INITRD}" -eq '1' ]
275 # Only compile insmod if we're installing modules onto the initrd
276 if [ "${NOINITRDMODULES}" = '' ]
278 if [ "${KERN_24}" != '1' ]
280 # Compile module-init-tools
281 compile_module_init_tools
287 [ "${DISKLABEL}" -eq '1' ] && compile_e2fsprogs
289 if [ "${KERN_24}" != '1' -a "${UDEV}" -eq '1' ]
298 if [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
300 if [ "${BUSYBOX}" -eq '1' ]
314 print_info 1 'initrd: Not building since only the kernel was requested...'
318 if [ "${GENERATE_Z_IMAGE}" != '' ]
320 # Compile kernel, intergrating the initrd into it for Pegasos
324 [ "${MINKERNPACKAGE}" != '' ] && gen_minkernpackage
325 [ "${MODULESPACKAGE}" != '' ] && gen_modulespackage
328 [ -n "${CTEMP}" ] && rm -rf "${TEMP}"
330 if [ "${BUILD_KERNEL}" -eq '1' ]
334 print_info 1 "Kernel compiled successfully!"
336 print_info 1 'Required Kernel Parameters:'
337 if [ "${BUILD_INITRD}" -eq '0' ]
339 print_info 1 ' root=/dev/$ROOT'
340 print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]'
342 print_info 1 ' Where $ROOT is the device node for your root partition as the'
343 print_info 1 ' one specified in /etc/fstab'
344 elif [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
346 print_info 1 ' real_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'
352 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
353 print_info 1 'tell your bootloader to use the provided INITRAMFS file. Otherwise;'
354 print_info 1 'substitute the root argument for the real_root argument if you are'
355 print_info 1 'not planning to use the initrd...'
357 print_info 1 ' root=/dev/ram0 real_root=/dev/$ROOT init=/linuxrc'
358 [ "${INITRD_SIZE}" -ge 4096 ] && print_info 1 " ramdisk_size=${INITRD_SIZE}"
359 print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]'
361 print_info 1 ' Where $ROOT is the device node for your root partition as the'
362 print_info 1 ' one specified in /etc/fstab'
364 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
365 print_info 1 'tell your bootloader to use the provided INITRD file. Otherwise;'
366 print_info 1 'substitute the root argument for the real_root argument if you are'
367 print_info 1 'not planning to use the initrd...'
371 if [ "${BUILD_INITRD}" -eq '1' ]
374 print_info 1 'WARNING... WARNING... WARNING...'
375 print_info 1 'Additional kernel cmdline arguments that *may* be required to boot properly...'
376 [ "${LVM2}" -eq '1' ] && print_info 1 'add "dolvm2" for lvm2 support at boot time'
377 [ "${EVMS2}" -eq '1' ] && print_info 1 'add "doevms" for evms support at boot time'
378 [ "${DMRAID}" -eq '1' ] && print_info 1 'add "dodmraid" for dmraid support at boot time'
379 [ "${DMRAID}" -eq '1' ] && print_info 1 ' or "dodmraid=<additional options>"'
380 [ "${UNIONFS}" -eq '1' ] && print_info 1 'add "unionfs" for unionfs support at boot time'
381 [ "${UNIONFS}" -eq '1' ] && print_info 1 ' or "unionfs=<block_device>"'
384 if [ "${CMD_NOINSTALL}" != '1' -a "${SYMLINK}" = '1' ]
387 print_info 1 'Creating symlinks'
390 print_info 1 ' creating kernel name symlink!'
391 if [ -e /boot/kernel-${KNAME}-${ARCH}-${KV} ]
394 ln -s /boot/kernel-${KNAME}-${ARCH}-${KV} /boot/kernel
396 [ ${ret} = '1' ] && print_error 1 'kernel link failed'
399 if [ "${KERN_24}" != '1' -a "${CMD_BOOTSPLASH}" != '1' ]
401 print_info 1 ' creating initramfs name symlink!'
402 if [ -e /boot/initramfs-${KNAME}-${ARCH}-${KV} ]
404 /bin/rm /boot/initramfs
405 ln -s /boot/initramfs-${KNAME}-${ARCH}-${KV} /boot/initramfs
407 [ ${ret} = '1' ] && print_error 1 'initramfs link failed'
410 print_info 1 ' creating initrd name symlink!'
411 if [ -e /boot/initrd-${KNAME}-${ARCH}-${KV} ]
414 ln -s /boot/initrd-${KNAME}-${ARCH}-${KV} /boot/initrd
416 [ ${ret} = '1' ] && print_error 1 'initrd link failed'
422 [ "${BOOTRW}" != '' ] && mount -o remount,ro /boot
425 print_info 1 'Do NOT report kernel bugs as genkernel bugs unless your bug'
426 print_info 1 'is about the default genkernel configuration...'
428 print_info 1 'Make sure you have the latest genkernel before reporting bugs.'