5 TEMP='/var/tmp/genkernel'
6 TODEBUGCACHE=1 # Until an error occurs or DEBUGFILE is fully qualified.
13 source /etc/genkernel.conf || small_die "Could not read /etc/genkernel.conf"
14 source ${GK_BIN}/gen_funcs.sh || small_die "Could not read ${GK_BIN}/gen_funcs.sh"
15 source ${GK_BIN}/gen_cmdline.sh || gen_die "Could not read ${GK_BIN}/gen_cmdline.sh"
16 source ${GK_BIN}/gen_arch.sh || gen_die "Could not read ${GK_BIN}/gen_arch.sh"
17 source ${GK_BIN}/gen_determineargs.sh || gen_die "Could not read ${GK_BIN}/gen_determineargs.sh"
18 source ${GK_BIN}/gen_compile.sh || gen_die "Could not read ${GK_BIN}/gen_compile.sh"
19 source ${GK_BIN}/gen_configkernel.sh || gen_die "Could not read ${GK_BIN}/gen_configkernel.sh"
20 source ${GK_BIN}/gen_initrd.sh || gen_die "Could not read ${GK_BIN}/gen_initrd.sh"
21 source ${GK_BIN}/gen_moddeps.sh || gen_die "Could not read ${GK_BIN}/gen_moddeps.sh"
22 source ${GK_BIN}/gen_package.sh || gen_die "Could not read ${GK_BIN}/gen_package.sh"
23 source ${GK_BIN}/gen_bootloader.sh || gen_die "Could not read ${GK_BIN}/gen_bootloader.sh"
28 # Parse all command line options...
35 # Check if no action is specified...
36 if [ "${BUILD_KERNEL}" -eq 0 -a "${BUILD_INITRD}" -eq 0 ]
43 NORMAL=${GOOD} print_info 1 "Gentoo Linux Genkernel; Version ${GK_V}${NORMAL}"
48 # Read arch-specific config
49 source ${ARCH_CONFIG} || gen_die "Could not read ${ARCH_CONFIG}"
50 source ${GK_SHARE}/${ARCH}/modules_load || gen_die "Could not read ${GK_SHARE}/${ARCH}/modules_load"
52 [ ! -f "${TEMP}" ] && mkdir -p "${TEMP}"
53 [ ! -f "${CACHE_DIR}" ] && mkdir -p "${CACHE_DIR}"
55 # Based on genkernel.conf, arch-specific configs, and commandline options,
56 # get the real arguments for usage...
61 NORMAL=${BOLD} print_info 1 "Compiling Linux Kernel ${BOLD}${KV}${NORMAL} for ${BOLD}${ARCH}${NORMAL}..."
64 if [ "${BUILD_INITRD}" -ne '0' ]
68 modprobe loop 2>/dev/null
71 print_error 1 'Your kernel does not appear to have loop device support.'
72 print_error 1 'Please load loop support before running genkernel!'
73 gen_die 'Load loop support!'
75 print_info 1 'loop: "loop" module loaded successfully...'
80 # Check /boot is mounted
81 if isTrue ${CMD_NOINSTALL}
83 isTrue ${MOUNTBOOT} && print_info 2 'Skipping automatic mount of boot'
85 if ! egrep -q ' /boot ' /proc/mounts
87 if egrep -q '^[^#].+ /boot ' /etc/fstab
89 if isTrue ${MOUNTBOOT}
93 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to mount /boot!"
96 print_info 1 'mount: /boot mounted successfully!'
99 print_warning 1 "${BOLD}WARNING${NORMAL}: No mounted /boot partition detected!"
100 print_warning 1 ' Run ``mount /boot`` to mount it!'
106 if isTrue ${MOUNTBOOT}
108 if ! mount -o remount,rw /boot
110 print_warning 1 "${BOLD}WARNING${NORMAL}: Failed to remount /boot RW!"
113 print_info 1 "mount: /boot remounted read/write successfully!"
120 # Check whether another Genkernel is running
121 GENPIDS="`ps -C genkernel --no-headers -o pid | wc -l`"
122 if [ "${GENPIDS}" -gt '3' ]
124 [ "${GENPIDS}" -gt '4' ] && EX='s'
125 print_warning 1 "${BOLD}WARNING${NORMAL}: Another Genkernel instance is running under"
126 print_warning 1 " process ID${EX} " 0
127 GENPIDS=`ps -C genkernel --no-headers -o pid`
128 echo -n "${GENPIDS}" | sed -e "s/$$//; s/ /, /g"
131 print_warning 1 'Running multiple genkernels on the same source tree will cause data loss!'
132 print_info 1 "Press ^C to halt; ^D to continue [ ${BOLD}if${NORMAL} you know what you're doing! ]"
136 TEMP="/var/tmp/genkernel-`dd if=/dev/random count=1 2>/dev/null | md5sum | cut -d\ -f1`"
137 print_info 1 'thread: Running multiple genkernels may cause problems!'
138 print_info 1 "thread: Temporary files reallocated to ${TEMP}..."
142 if [ ${BUILD_KERNEL} -eq 1 ]
151 [ "${VER}" -gt '2' ] || [ "${VER}" -eq '2' -a "${PAT}" -ge '6' ] && compile_generic prepare kernel
154 if [ "${CMD_POSTCONF}" != '' ]
157 print_info 1 "Preparing to run postconf: \"${CMD_POSTCONF}\"" 0
162 trap "CALLBACK_ESCAPE=1" TERM KILL INT QUIT ABRT
163 while [[ ${CALLBACK_ESCAPE} -eq 0 && ${CALLBACK_COUNT} -lt 5 ]]
165 sleep 1; echo -n '.';
166 let CALLBACK_COUNT=${CALLBACK_COUNT}+1
169 if [ "${CALLBACK_ESCAPE}" -eq 0 ]
173 eval ${CMD_POSTCONF} | tee -a ${DEBUGFILE}
174 CMD_STATUS="${PIPESTATUS[0]}"
176 print_info 1 "<<< Postconf callback exit status: ${CMD_STATUS}"
177 [ "${CMD_STATUS}" -ne 0 ] && gen_die '--postconf failed!'
180 print_info 1 '>>> Postconf cancelled...'
182 trap - TERM KILL INT QUIT ABRT
186 if [ "${GENSPLASH}" -eq '1' ]
188 if [ -x /sbin/splash ]
190 [ -z "${GENSPLASH_THEME}" ] && [ -e /etc/conf.d/splash ] && source /etc/conf.d/splash
191 [ -z "${GENSPLASH_THEME}" ] && GENSPLASH_THEME=default
192 print_info 1 " >> Installing gensplash [ using the ${GENSPLASH_THEME} theme ]..."
194 sed -i -e 's:$(obj)/gen_init_cpio $(initramfs-y) FORCE:$(if $(shell [ ! -f $(obj)/initramfs_data.cpio ] \&\& echo 1 ), $(obj)/gen_init_cpio $(initramfs-y)):' ${KERNEL_DIR}/usr/Makefile
196 sed -i -e 's:$(obj)/gen_init_cpio \\:$(if $(shell [ ! -f $(obj)/initramfs_data.cpio ] \&\& echo 1 ), $(obj)/gen_init_cpio $(initramfs-y) $(obj)/initramfs_list):' -e 's:$(initramfs-y) $(obj)/initramfs_list FORCE::' ${KERNEL_DIR}/usr/Makefile
197 splash_geninitramfs -g ${KERNEL_DIR}/usr/initramfs_data.cpio.gz ${GENSPLASH_THEME}
198 gunzip ${KERNEL_DIR}/usr/initramfs_data.cpio.gz
200 print_warning 1 ' >> No splash detected; skipping!'
210 if [ ${SAVE_CONFIG} -eq 1 ]
212 print_info 1 "Copying config for successful build to /etc/kernels/kernel-config-${ARCH}-${KV}"
213 [ ! -e '/etc/kernels' ] && mkdir -p /etc/kernels
214 cp "${KERNEL_DIR}/.config" "/etc/kernels/kernel-config-${ARCH}-${KV}"
219 if [ "${CMD_CALLBACK}" != "" ]
222 print_info 1 "Preparing to run callback: \"${CMD_CALLBACK}\"" 0
227 trap "CALLBACK_ESCAPE=1" TERM KILL INT QUIT ABRT
228 while [[ ${CALLBACK_ESCAPE} -eq 0 && ${CALLBACK_COUNT} -lt 5 ]]
230 sleep 1; echo -n '.';
231 let CALLBACK_COUNT=${CALLBACK_COUNT}+1
234 if [ "${CALLBACK_ESCAPE}" -eq 0 ]
238 eval ${CMD_CALLBACK} | tee -a ${DEBUGFILE}
239 CMD_STATUS="${PIPESTATUS[0]}"
241 print_info 1 "<<< Callback exit status: ${CMD_STATUS}"
242 [ "${CMD_STATUS}" -ne 0 ] && gen_die '--callback failed!'
245 print_info 1 ">>> Callback cancelled..."
247 trap - TERM KILL INT QUIT ABRT
251 if [ "${BUILD_INITRD}" -eq '1' ]
254 # if [ "${USE_DIETLIBC}" = '1' ]
262 # Only compile insmod if we're installing modules onto the initrd
263 if [ "${NOINITRDMODULES}" = '' ]
265 if [ "${PAT}" -gt '4' ]
267 # Compile module-init-tools
268 compile_module_init_tools
275 if [ "${DEVFS}" -eq '0' ]
277 [ "${VER}" -gt '2' ] || [ "${VER}" -eq '2' -a "${PAT}" -ge '6' ] && UDEV=1
279 [ "${UDEV}" -eq '1' ] && compile_udev
284 print_info 1 'initrd: Not building since only the kernel was requested...'
286 [ "${MINKERNPACKAGE}" != "" ] && gen_minkernpackage
287 [ "${MAXKERNPACKAGE}" != "" ] && gen_maxkernpackage
290 [ -n "${CTEMP}" ] && rm -rf "${TEMP}"
292 if [ "${BUILD_KERNEL}" -eq '1' ]
296 print_info 1 "Kernel compiled successfully!"
298 print_info 1 'Required Kernel Parameters:'
299 if [ "${BUILD_INITRD}" -eq '0' ]
301 print_info 1 ' root=/dev/$ROOT'
302 print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]'
304 print_info 1 ' Where $ROOT is the device node for your root partition as the'
305 print_info 1 ' one specified in /etc/fstab'
307 print_info 1 ' root=/dev/ram0 real_root=/dev/$ROOT init=/linuxrc'
308 [ "${INITRD_SIZE}" -ge 4096 ] && print_info 1 " ramdisk_size=8192"
309 print_info 1 ' [ And "vga=0x317 splash=verbose" if you use a framebuffer ]'
311 print_info 1 ' Where $ROOT is the device node for your root partition as the'
312 print_info 1 ' one specified in /etc/fstab'
314 print_info 1 "If you require Genkernel's hardware detection features; you MUST"
315 print_info 1 'tell your bootloader to use the provided initrd file. Otherwise;'
316 print_info 1 'substitute the root argument for the real_root argument if you are'
317 print_info 1 'not planning to use the initrd...'
321 print_info 1 'initrd compiled successfully!'
324 [ "${BOOTRW}" != '' ] && mount -o remount,ro /boot
327 print_info 1 'Do NOT report kernel bugs as genkernel bugs unless your bug'
328 print_info 1 'is about the default genkernel configuration...'
330 print_info 1 'Make sure you have the latest genkernel before reporting bugs.'