Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build the same Linux Kernel twice sources and get the same checksum

I'm searching if it's possible to build the same Linux Kerneltwice (same sources, same environment, same options, same compiler) and get the same checksum. Anybody knows how to do so?

like image 838
gsempe Avatar asked Jun 29 '09 08:06

gsempe


2 Answers

The date of build is included in the version, see init version.c :

const char linux_banner[] =
    "Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@"
    LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";

and UTS_VERSION is defined in include/linux/compile.h :

/* This file is auto generated, version 1 */
/*  PREEMPT */
#define UTS_MACHINE "arm"
#define UTS_VERSION "#1 PREEMPT Mon Jun 29 10:49:17 CEST 2009"
#define LINUX_COMPILE_TIME "10:49:17"
#define LINUX_COMPILE_BY "cynove"
#define LINUX_COMPILE_HOST "jp"
#define LINUX_COMPILE_DOMAIN "evonyc"
#define LINUX_COMPILER "gcc version 4.3.2 (crosstool-NG-1.4.0) "

compile.h is generated by scripts/mkcompile_h, where you find the following line :

UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS `LC_ALL=C LANG=C date`"

By removing the date from the pervious line, you should be able to get rid of the build time dependency.

like image 153
shodanex Avatar answered Oct 27 '22 22:10

shodanex


shodanex's answer is right but incomplete. After some research I found Linux kernel binary embeds a default ramfs which is another reason of differences between two kernels compilations (CPIO RAMFS header embeds date). It's impossible to disable this feature but it's possible to provide a default ramfs. When you do so, you get exactly the same checksum.

Thank you. Your answers help me a lot to resolve my problem.

like image 5
gsempe Avatar answered Oct 27 '22 20:10

gsempe