View previous topic :: View next topic |
Author |
Message |
vericgar Retired Dev
Joined: 13 Dec 2002 Posts: 79 Location: Spokane, WA
|
Posted: Tue Jul 22, 2003 6:15 am Post subject: Compare Kernel Configurations |
|
|
While I was trying the 2.6.0-test1 kernel I often times wanted to compare my new configuration with my current working config, so that I could have everything as close as possible between the two configs (while both still working), as this would give me the advantage of not having to mess with my bootup setting too much (i.e adding different things to modules.autoload and such) and to make the upgrade as smooth as possible. So I wrote this quick little script in PERL to compare and show the differences between two different kernel configs. Suggestions welcome!
Code: |
#!/usr/bin/perl
### kerneldiff.pl
#
# Simple PERL script to show the differences between two kernel configurations
#
# Usage: ./kerneldiff.pl [-v] file1 file2
# -v Shows everything that is the same between configs as well
# file1 The first .config file
# file2 The second .config file
#
# Note: This should work on any file with a similiar config file format
# (i.e. option=value, lines starting with # and blank lines ignored)
#
# Tested using perl 5.8.0
#
# Copyright (c) 2003 Michael Stewart
# This code is release under the GPL version 2.
# Suggestions and comments to vericgar[at]insaneone.com
$file1 = shift @ARGV;
$file2 = shift @ARGV;
if ($file1 eq "-v") {
$verbose = 1;
$file1 = $file2;
$file2 = shift @ARGV;
}
print "$file1 -- $file2\n\n";
open (CFG1, $file1);
@cfg1lines = <CFG1>;
close CFG1;
open (CFG2, $file2);
@cfg2lines = <CFG2>;
close CFG2;
$llen = 0;
foreach (@cfg1lines) {
$_ =~ s/[\n\r]//g;
if (m/\=/ and !m/^\#/) {
($item,$value) = split(/\=/, $_);
$config1{$item} = $value;
$config{$item} = $value;
$len = length($value);
if ($len > $llen) { $llen = $len; }
}
}
foreach (@cfg2lines) {
$_ =~ s/[\n\r]//g;
if (m/\=/ and !m/^\#/) {
($item,$value) = split(/\=/, $_);
$config2{$item} = $value;
$config{$item} = $value;
$len = length($value);
if ($len > $llen) { $llen = $len; }
}
}
foreach (sort(keys(%config))) {
$pack1 = $llen - length($config1{$_});
$pack2 = $llen - length($config2{$_});
$cfo1 = $config1{$_} . ' ' x $pack1;
$cfo2 = $config2{$_} . ' ' x $pack2;
if ($config1{$_} ne "") {
if ($config2{$_} ne "") {
if ($config1{$_} ne $config2{$_}) {
# both exist, different
print "<>\t" . $cfo1 . ' ' . $cfo2 . ' ' . $_ . "\n";
} else {
if ($verbose == 1) {
# is the same in both
print "==\t" . $cfo1 . ' ' . $cfo2 . ' ' . $_ . "\n";
}
}
} else {
# only exists in 1
print "<\t" . $cfo1 . ' ' . $cfo2 . ' ' . $_ . "\n";
}
} else {
# only exists in 2
print " >\t" . $cfo1 . ' ' . $cfo2 . ' ' . $_ . "\n";
}
}
|
Sample Output:
Code: |
vericgar@mooncougar vericgar $ ./kerneldiff.pl /etc/kernel/2.4.20-ck2--2003-01-12 /etc/kernel/2.4.20-ck6--2003-07-19
/etc/kernel/2.4.20-ck2--2003-01-12 -- /etc/kernel/2.4.20-ck6--2003-07-19
< y CONFIG_AUTOFS4_FS
> y CONFIG_BLK_STATS
> y CONFIG_BSD_PROCESS_ACCT
> y CONFIG_DEBUG_KERNEL
> m CONFIG_ETHERTAP
<> 100 200 CONFIG_HZ
< m CONFIG_IPX
< y CONFIG_IP_MULTICAST
> m CONFIG_IP_NF_CONNTRACK
> m CONFIG_IP_NF_IPTABLES
> m CONFIG_IP_NF_NAT
> y CONFIG_IP_NF_NAT_LOCAL
> y CONFIG_IP_NF_NAT_NEEDED
> m CONFIG_IP_NF_TARGET_MASQUERADE
> y CONFIG_LOLAT_SYSCTL
> y CONFIG_MAGIC_SYSRQ
> y CONFIG_NETFILTER
> y CONFIG_NETLINK_DEV
< y CONFIG_PM
< y CONFIG_SCSI_DEBUG_QUEUES
< m CONFIG_SND_ALSA
< m CONFIG_SND_ALSA_ES18XX
< m CONFIG_SND_ALSA_MIXER_OSS
< y CONFIG_SND_ALSA_OSSEMUL
< m CONFIG_SND_ALSA_PCM_OSS
< m CONFIG_SND_ALSA_SB16
< m CONFIG_SND_ALSA_SEQUENCER
< m CONFIG_SOUND_ALSA
> m CONFIG_TUN
vericgar@mooncougar vericgar $
|
For some reason phpbb is killing the space before the > in the sample output. In actual usuage it really is all lined up.
Enjoy! _________________ +~+ Sometimes a good ole loving kick is all it needs +~+ |
|
Back to top |
|
|
wishkah Guru
Joined: 09 May 2003 Posts: 441 Location: de
|
Posted: Tue Jul 22, 2003 2:20 pm Post subject: |
|
|
Wow, you can really learn good perl programming from that little script, thanks pal! _________________ if only I could fill my heart with love... |
|
Back to top |
|
|
pYrania Retired Dev
Joined: 27 Oct 2002 Posts: 650 Location: Cologne - Germany
|
Posted: Tue Jul 22, 2003 2:34 pm Post subject: |
|
|
that's a nice one
i used to test different kernels with differnet settings in order to get the best out of it.. i think i can use this script for comparing the different configs. great idea and even better implementation. _________________ Markus Nigbur |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|