lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 18 Sep 2008 13:34:04 -0400 (EDT)
From:	Steven Rostedt <rostedt@...dmis.org>
To:	LKML <linux-kernel@...r.kernel.org>
cc:	Linus Torvalds <torvalds@...ux-foundation.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...e.hu>, Theodore Tso <tytso@....edu>,
	gregkh@...e.de
Subject: [PATCH] script to remove unused modules from config file


I heard that at KS my script was mentioned, and that I should submit
it as a patch to be added to the scripts directory. Well here's the patch.

The way this script works is that you must boot into the kernel that
you want to clean up the config. Then change into the directory that holds
the source of the kernel you booted into. Make sure all the modules you
want are loaded (remember to plug in a USB stick ;-) Then simply run
this script redirecting the output into another file.

 $ cd ~/kernels/linux.git
 $ scripts/streamline_config.pl > config-sl
 $ mv .config config-orig
 $ mv config-sl .config
 $ make oldconfig

That's it!

The way this works is that the script reads what modules are loaded by doing
a lsmod. Then it reads all the Makefiles finding the configurations that
turn on those modules. Finally it reads the config and disables all modules
that were not used.

Note, this script does not touch any "y" option, only "m".

Signed-off-by: Steven Rostedt <srostedt@...hat.com>
---
 scripts/streamline_config.pl |  121 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)

Index: linux-tip.git/scripts/streamline_config.pl
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-tip.git/scripts/streamline_config.pl	2008-09-17 14:56:52.000000000 -0400
@@ -0,0 +1,121 @@
+#!/usr/bin/perl -w
+#
+# Copywrite 2005-2008 - Steven Rostedt
+# Licensed under the terms of the GNU GPL License version 2
+#
+#  It's simple enough to figure out how this works.
+#  If not, then you can ask me at rostedt@...dmis.org
+#
+# What it does?
+#
+#   If you have installed a Linux kernel from a distribution
+#   that turns on way too many modules than you need, and
+#   you only want the modules you use, than this program
+#   is perfect for you.
+#
+#   It gives you the ability to turn off all the modules that are
+#   not loaded on your system.
+#
+# Howto:
+#
+#  1. Boot up the kernel that you want to stream line the config on.
+#  2. Change directory to the directory holding the source of the
+#       kernel that you just booted.
+#  3. Copy the configuraton file to this directory as .config
+#  4. Have all your devices that you need modules for connected and
+#      operational (make sure that their corresponding modules are loaded)
+#  5. Run this script redirecting the output to some other file
+#       like config_strip.
+#  6. Back up your old config (if you want too).
+#  7. copy the config_strip file to .config
+#  8. Run "make oldconfig"
+#
+#  Now your kernel is ready to be built with only the modules that
+#  are loaded.
+#
+# Here's what I did with my Debian distribution.
+#
+#    cd /usr/src/linux-2.6.10
+#    cp /boot/config-2.6.10-1-686-smp .config
+#    ~/bin/streamline_config > config_strip
+#    mv .config config_sav
+#    mv config_strip .config
+#    make oldconfig
+#
+my $config = ".config";
+my $linuxpath = ".";
+
+open(CIN,$config) || die "Can't open current config file: $config";
+my @makefiles = `find $linuxpath -name Makefile`;
+
+my %objects;
+my $var;
+my $cont = 0;
+
+foreach my $makefile (@makefiles) {
+	chomp $makefile;
+
+	open(MIN,$makefile) || die "Can't open $makefile";
+	while (<MIN>) {
+		my $catch = 0;
+
+		if ($cont && /(\S.*)$/) {
+			$objs = $1;
+			$catch = 1;
+		}
+		$cont = 0;
+
+		if (/obj-\$\((CONFIG_[^)]*)\)\s*[+:]?=\s*(.*)/) {
+			$var = $1;
+			$objs = $2;
+			$catch = 1;
+		}
+		if ($catch) {
+			if ($objs =~ m,(.*)\\$,) {
+				$objs = $1;
+				$cont = 1;
+			}
+
+			foreach my $obj (split /\s+/,$objs) {
+				$obj =~ s/-/_/g;
+				if ($obj =~ /(.*)\.o$/) {
+					$objects{$1} = $var;
+				}
+			}
+		}
+	}
+	close(MIN);
+}
+
+my %modules;
+
+open(LIN,"/sbin/lsmod|") || die "Cant lsmod";
+while (<LIN>) {
+	next if (/^Module/);  # Skip the first line.
+	if (/^(\S+)/) {
+		$modules{$1} = 1;
+	}
+}
+close (LIN);
+
+my %configs;
+foreach my $module (keys(%modules)) {
+	if (defined($objects{$module})) {
+		$configs{$objects{$module}} = $module;
+	} else {
+		print STDERR "$module config not found!!\n";
+	}
+}
+
+while(<CIN>) {
+	if (/^(CONFIG.*)=m/) {
+		if (defined($configs{$1})) {
+			print;
+		} else {
+			print "# $1 is not set\n";
+		}
+	} else {
+		print;
+	}
+}
+close(CIN);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ