Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

include-modules 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/perl -w
  2. #
  3. # Retrieve modules required for an initrd image
  4. # $Id$
  5. unless ( @ARGV ) {
  6. die "Syntax: $0 [ -d target_directory ] module_1 module_2 module_3\n"
  7. }
  8. # Parse command line arguments
  9. my @requested_modules = ();
  10. my $target_dir = "";
  11. my $kernel_ver;
  12. my $quiet;
  13. chomp ( my $current_kernel_ver = `uname -r` );
  14. while ( $_ = shift ) {
  15. if ( /-d/ ) { $target_dir = shift }
  16. elsif ( /-k/ ) { $kernel_ver = shift }
  17. elsif ( /-q/ ) { $quiet = 1 }
  18. else { push @requested_modules, $_ };
  19. }
  20. # Create target directory if required
  21. if ( $target_dir ) {
  22. print STDERR "Target directory is $target_dir\n" unless $quiet;
  23. system ( "mkdir -p $target_dir" );
  24. chdir $target_dir;
  25. }
  26. # Use modprobe -nav to retrieve locations of modules and their dependencies
  27. print STDERR "Requested modules ". join (' ', @requested_modules)."\n" unless $quiet;
  28. my @modules_dups;
  29. foreach my $module ( @requested_modules ) {
  30. my @module_list = map { /^\S+\s+(.*)$/ ; $1 } `/sbin/modprobe -nva $module`;
  31. die "Cannot find any modules matching $module\n" unless @module_list;
  32. push @modules_dups, @module_list;
  33. }
  34. # Remove duplicates from list
  35. my %module_basenames = ();
  36. my @modules = ();
  37. foreach my $module ( @modules_dups ) {
  38. # Ugly hack : assume that dependencies are independent of kernel version
  39. # This seems to be necessary because we can't run modprobe and specify
  40. # an alternate modules.dep file; it refuses to understand lines of the
  41. # form "depfile=XXX" as documented in modules.conf(5)
  42. $module =~ s/$current_kernel_ver/$kernel_ver/ if $kernel_ver;
  43. push @modules, $module unless $module_basenames{$module};
  44. ( my $basename ) = ( $module =~ /([^\/]+)\.o/ );
  45. $module_basenames{$module} = $basename;
  46. }
  47. # Process module list
  48. print "#!/bin/sh\n";
  49. foreach my $module ( @modules ) {
  50. my $basename = $module_basenames{$module};
  51. # Report via stdout
  52. print STDERR "Using module $basename from $module\n" unless $quiet;
  53. # Copy uncompressed module to current directory
  54. system ("gunzip -c $module > $basename.o");
  55. # Print insmod line to stdout
  56. print "insmod $basename\n";
  57. }