You are not logged in.

#1 2011-06-09 09:23:00

brandnewmath
Member
Registered: 2010-02-01
Posts: 14

rc.conf MODULES cleanup helper script

Hello all,

Not sure where else to post this, so I hope it's helpful to somebody if I put it here.

Per the announcement today, blacklisting modules in /etc/rc.conf is deprecated. I don't know about everyone else, but for some reason my rc.conf had a MODULES line that blacklisted a bunch of modules, then loaded them; it looked something like this:

MODULES=(!mii !r8169 !pcspkr !snd-mixer-oss !snd-pcm-oss !snd-hwdep !snd-page-alloc !snd-pcm !snd-timer !snd !snd-hda-codec !snd-hda-intel !soundcore !acpi-cpufreq !pcspkr !snd-seq mii r8169 snd-mixer-oss snd-pcm-oss snd-hwdep snd-page-alloc snd-pcm snd-timer snd snd-hda-codec snd-hda-intel soundcore kvm kvm-intel bridge tun acpi-cpufreq snd-seq)

They seemed to be mostly duplicates, but I thought there were one or two modules blacklisted that weren't loaded. So I wrote a quick Perl script to sort the matter out:

#!/usr/bin/perl

#### Quick ID of modules blacklisted/loaded explicitly

use warnings;
use strict;

### Main

# Open /etc/rc.conf and get the MODULES line
my $modline;
open my $rcconf, '<', "/etc/rc.conf";
while ( <$rcconf> ) {
    chomp;
    /^\s*MODULES=/ and $modline = $_;
}
close $rcconf;

# Trim the fat from the MODULES line and stick
# the individual parts in an array
$modline =~ s/^MODULES=\(//;
$modline =~ s/\)$//;
my @mods = split /\s+/, $modline;

# Separate modules into those blacklisted and those not
my ( @notload, @load );
foreach ( @mods ) {
    /^\!/ and s/^\!// and push @notload, $_ and next;
    push @load, $_;
}

# If there's a name with a ! before it that isn't later loaded,
# print it out suitably for inclusion in an /etc/modprobe.d/*conf
# file
foreach my $mod ( @notload ) {
    not grep { /^$mod$/ } @load and print "blacklist $mod\n";
}

# Print the new MODULES line to go in /etc/rc.conf
print "MODULES=(", join " ", @load, ")\n";

The output looks like this for my example here:

blacklist pcspkr
blacklist pcspkr
MODULES=(mii r8169 snd-mixer-oss snd-pcm-oss snd-hwdep snd-page-alloc snd-pcm snd-timer snd snd-hda-codec snd-hda-intel soundcore kvm kvm-intel bridge tun acpi-cpufreq snd-seq )

As you can see, I really hate the pcspkr ;-) To use the output, you just copy the 'blacklist' lines into a file with a name ending in .conf in the /etc/modprobe.d directory and replace the MODULES line in /etc/rc.conf with the one output by the script. No guarantees (if it breaks, you can keep both halves), but it's worked for me so far.


--
James

Offline

Board footer

Powered by FluxBB