Hello!

I'm trying to build a 2.6.39 low latency kernel using make-kpkg on
lucid. The current state of kernel-package makes this a bit painful,
here are my experiences.

The first problem is that initrd is not created when the linux-image
package is installed. This can be solved by having kernel-package
include different maintainer scripts into the packages it builds, e.g.
copy the scripts from the stock 2.6.32-generic kernel package (as
described in https://help.ubuntu.com/community/Kernel/Compile).

This leads straight to the second problem: The symlink in
/lib/modules/<uname>/build is broken and does not get corrected by the
maintainer scripts copied from 2.6.32. This breaks stuff like dkms. I
solved this second problem by copying the missing code from the
original kernel-packages postinst into the postinst script copied from
2.6.32 (patch attached).

Did I miss some switch in kernel-package which makes the above
problems resolve itself? Or is there a new way to build custom kernel
packages without too much hassle?

Christoph
--- linux-2.6.32-generic/linux-2.6.32/debian/control-scripts/postinst	2011-06-21 11:07:45.000000000 +0200
+++ kernel-package/pkg/image/postinst	2011-06-22 10:46:17.864393049 +0200
@@ -32,12 +32,16 @@
 my $prerm_hook        = '';          #Normally we do not
 my $minimal_swap      = '';          # Do not swap symlinks
 my $ignore_depmod_err = '';          # normally we do not
+my $relink_src_link    = 'YES'; # There is no harm in checking the link
+my $relink_build_link  = 'YES'; # There is no harm in checking the link
+my $force_build_link   = '';    # There is no harm in checking the link
 my $kernel_arch       = "=B";
 my $ramdisk           = "/usr/sbin/update-initramfs";  # List of tools to create initial ram fs.
 my $notifier          = "/usr/share/update-notifier/notify-reboot-required";
 my $package_name      = "linux-image-$version";
 my $explicit_do_loader = 'Yes';
 
+
 my $Loader          = "NoLOADER"; #
 $Loader             = "LILO"     if $loader =~ /^lilo/io;
 $Loader             = "SILO"     if $loader =~ /^silo/io;
@@ -129,6 +133,9 @@
       $warn_reboot     = 'Yes' if /^\s*warn_reboot\s*=\s*(yes|true|1)\s*$/ig;
       $minimal_swap    = 'Yes' if /^\s*minimal_swap\s*=\s*(yes|true|1)\s*$/ig;
       $ignore_depmod_err = 'Yes' if /^\s*ignore_depmod_err\s*=\s*(yes|true|1)\s*$/ig;
+      $relink_src_link   = '' if /relink_src_link\s*=\s*(no|false|0)\s*$/ig;
+      $relink_build_link = '' if /relink_build_link\s*=\s*(no|false|0)\s*$/ig;
+      $force_build_link  = '' if /force_build_link\s*=\s*(no|false|0)\s*$/ig;
 
       $image_dest      = "$1"  if /^\s*image_dest\s*=\s*(\S+)/ig;
       $postinst_hook   = "$1"  if /^\s*postinst_hook\s*=\s*(\S+)/ig;
@@ -190,6 +197,88 @@
   . "$kimage-$version)\n" unless -e $realimageloc
   . "$kimage-$version";
 
+
+######################################################################
+## Fix the build link
+######################################################################
+sub fix_build_link {
+  return unless -d "$modules_base/$version";
+  # if we saved a build link in preinst, restore the link
+  if (! -e "$modules_base/$version/build" && 
+      -l "$modules_base/$version/build.save" ) {
+    rename("$modules_base/$version/build.save", "$modules_base/$version/build") ||
+      die "failed to move $modules_base/$version/build:$!";
+  }
+  if ($relink_build_link || $force_build_link) {
+    my $build_target;
+    my $real_target = '';
+    if (-l "$modules_base/$version/build") {
+      $build_target = readlink "$modules_base/$version/build";
+    } else {
+      return;
+    }
+    # Determine what the real file name is, and test that for existence
+    $real_target = abs_path($build_target) if defined($build_target);
+    if (!defined($build_target) || ! -d "$real_target") { # Danglink link
+      warn qq(
+ Hmm. There is a symbolic link $modules_base/$version/build
+ However, I can not read it: $!
+ Therefore, I am deleting $modules_base/$version/build\n
+);
+      my $num = unlink "$modules_base/$version/build";
+      if ($num != 1) {
+        warn "error unlinking $modules_base/$version/build";
+      } else {
+        if ($force_build_link || -d "/usr/src/=ST-headers-$version") {
+          my $result = symlink ("/usr/src/=ST-headers-$version",
+                                "$modules_base/$version/build");
+          if (! $result) {
+            warn "Could not link /usr/src/=ST-headers-$version to $modules_base/$version/build:$!"
+          }
+        }
+      }
+    }
+  }
+}
+
+if ($relink_build_link || $force_build_link) {
+  &fix_build_link();
+}
+######################################################################
+## Fix the source link
+######################################################################
+sub fix_source_link {
+  return unless -d "$modules_base/$version";
+  if ($relink_src_link) {
+    my $source_target;
+    my $real_target = '';
+
+    if (-l "$modules_base/$version/source") {
+      $source_target = readlink "$modules_base/$version/source";
+    } else {
+      return;
+    }
+    # Determine what the real file name is, and test that for existence
+    $real_target = abs_path($source_target) if defined($source_target);
+    if (!defined($source_target) || ! -d "$real_target") { # Danglink link
+      warn qq(
+ Hmm. The package shipped with a symbolic link $modules_base/$version/source
+ However, I can not read the target: $!
+ Therefore, I am deleting $modules_base/$version/source\n
+);
+      my $num = unlink "$modules_base/$version/source";
+      if ($num != 1) {
+        warn "error unlinking $modules_base/$version/source";
+      }
+    }
+  }
+}
+
+if ($relink_src_link) {
+  &fix_source_link();
+}
+
+
 # search for the boot loader in the path
 my $loader_exec;
 ($loader_exec = $loader)  =~ s|.*/||;
-- 
Ubuntu-devel-discuss mailing list
Ubuntu-devel-discuss@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss

Reply via email to