newbie questions

Matt Domsch Matt_Domsch at dell.com
Sat Dec 8 07:33:32 CST 2007


On Sat, Dec 08, 2007 at 02:20:47AM -0500, Jon Masters wrote:
> 
> On Fri, 2007-12-07 at 22:25 -0600, Matt Domsch wrote:
> > On Fri, Dec 07, 2007 at 03:41:12AM -0500, Jon Masters wrote:
> > > On Fri, 2007-12-07 at 08:10 +0700, Fajar A. Nugraha wrote:
> > > 
> > > > - forcing a call to /etc/init.d/dkms_autoinstaller during kernel upgrade
> > > > (using %post, or in my case by hijacking /sbin/weak-modules) might not
> > > > work, due to the fact that kernel-devel for that kernel version might
> > > > not be installed yet.
> > > 
> > > That's an interesting point.
> > > 
> > > I'm working on modifying weak-modules in RHEL5 to be more friendly with
> > > DKMS users, so that it'll let you call your own scripts automatically.
> > > But you're right that we might not have the -devel package installed at
> > > the moment that we call the weak-modules script. That possibly means we
> > > need to do something ugly...but I need to think some more :-)
> > > 
> > > Matt, do you have any particular preference about when/how this happens?
> > 
> > In Ubuntu, we cheat.  Seriously. :-)
> 
> Right.
> 
> > In RPM, we can use %posttrans in kernel and kernel-devel to invoke the
> > dkms_autoinstaller, but it'll run twice then (succeed the first time,
> > and ignore the second time), which is better, but not ideal.
> 
> Yeah, it will.
> 
> > We don't have an equivalent of %posttrans-runonce in RPM that I know of.
> 
> There's a needed feature right there, don't you just love RPM? :-)
> 
> I guess you'd prefer if it I added a .d directory and just called a
> script that runs all of those scripts as a result of a %posttrans on
> both kernel and kernel-devel packages? The scripts in that directory
> (essentially *only* DKMS for the foreseeable future) would need to know
> that they might get called twice if we installed both packages.

Yes.  And ideally, you would use the same directory and arguments as
the Ubuntu kernel package uses, so scripts can work on either.

/etc/kernel/postinst.d
/etc/kernel/prerm.d
/etc/kernel/header_postinst.d

and here's a snippet of the code they actually use to invoke the
postinstall scripts:
if (-d "/etc/kernel/postinst.d") {
  print STDERR "Examining /etc/kernel/postinst.d.\n";
  system ("run-parts --verbose --exit-on-error --arg=$version " .
          "--arg=$realimageloc$kimage-$version " .
          "/etc/kernel/postinst.d") &&
            die "Failed to process /etc/kernel/postinst.d";
}

if (-d "/etc/kernel/postinst.d/$version") {
  print STDERR "Examining /etc/kernel/postinst.d/$version.\n";
  system ("run-parts --verbose --exit-on-error --arg=$version " .
          "--arg=$realimageloc$kimage-$version " .
          "/etc/kernel/postinst.d/$version") &&
            die "Failed to process /etc/kernel/postinst.d/$version";
}


and preuninstall scripts:

if (-d "/etc/kernel/prerm.d") {
  print STDERR "Examining /etc/kernel/prerm.d.\n";
  system ("run-parts --verbose --exit-on-error --arg=$version " .
          "--arg=$realimageloc$kimage-$version /etc/kernel/prerm.d")
	  &&
            die "Failed to process /etc/kernel/prerm.d";
}
if (-d "/etc/kernel/prerm.d/$version") {
  print STDERR "Examining /etc/kernel/prerm.d/$version.\n";
  system ("run-parts --verbose --exit-on-error --arg=$version" .
          " --arg=$realimageloc$kimage-$version " .
          "/etc/kernel/prerm.d/$version") &&
            die "Failed to process /etc/kernel/prerm.d/$version";
}


Notice there's a subdirectory $version under each, so you could have a
script that only ran on a particular kernel version.  I hope that
would never be necessary, but it doesn't hurt to have.



The scripts in these directories are passed 2 arguments:
$1 = the version of the kernel  (e.g. 2.6.23.1-49.fc8)
$2 = the full path to the vmlinuz (e.g. /boot/vmlinuz-2.6.23.1-49.fc8)


Then DKMS drops its scripts into these directories.  Here's one for *postinst.d/:

#!/bin/bash
# We're passed the version of the kernel being installed
inst_kern=$1

[ -x /etc/init.d/dkms_autoinstaller ] && \
  /etc/init.d/dkms_autoinstaller start $inst_kern

exit 0


and prerm.d/:

#!/bin/bash                                                                                                                                                                                                      # We're passed the version of the kernel being installed                                                                                                                                                          
inst_kern=$1

if [ -x /usr/sbin/dkms ]; then
while read line; do
   name=`echo "$line" | awk '{print $1}' | sed 's/,$//'`
   vers=`echo "$line" | awk '{print $2}' | sed 's/,$//'`
   arch=`echo "$line" | awk '{print $4}' | sed 's/,$//'`
   echo "Uninstalling: $name $vers ($inst_kern) ($arch)"
   dkms uninstall -m $name -v $vers -k $inst_kern -a $arch
done < <(dkms status -k $inst_kern 2>/dev/null | grep ": installed")
fi

exit 0



Thanks,
Matt

-- 
Matt Domsch
Linux Technology Strategist, Dell Office of the CTO
linux.dell.com & www.dell.com/linux



More information about the DKMS-devel mailing list