[Libguestfs] ArchLinux port

Richard W.M. Jones rjones at redhat.com
Sun Dec 12 10:42:20 UTC 2010


On Sun, Dec 12, 2010 at 01:19:35AM -0700, Thomas S Hatch wrote:
> Ok, I got it all working, the supermin builds and guestfish
> is operating wonderfully. I altered the febootstrap module to download all
> packages and I fixed the augeus problem.

Thanks - I pushed it with some more argument quoting to make it safer.
It should still work OK, but please check I didn't break anything.

http://git.annexia.org/?p=febootstrap.git;a=commitdiff;h=5989c6746ae10b1da2a15dbefc3cf360a02e7a08

Thanks for your contribution.

> The only problem I am having is in the febootstrap-supermin-helper, in the
> helper/kernel.c the kernel to link into the supermin appliance is
> detected,but Arch uses a different kernel naming system. In Arch the kernel
> is always named vmlinuz26 and the only way I have found so far to derive the
> kernel version that the modules are stored under is to execute file on the
> kernel and awk out the version (file /boot/vmlinuz26 | awk '{print $9}').

It's a shame that the LSB/FHS doesn't standardize these names, to stop
downstream packagers from making random changes like this.

In any case, please try the attached patch which is based on your
description but has not been tested.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
-------------- next part --------------
>From 6b67bb5841e47acd6ce06d664bbca12341a126b0 Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones at redhat.com>
Date: Sun, 12 Dec 2010 10:40:57 +0000
Subject: [PATCH] helper: Add support for ArchLinux kernels.

---
 helper/kernel.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/helper/kernel.c b/helper/kernel.c
index 0903805..ef56133 100644
--- a/helper/kernel.c
+++ b/helper/kernel.c
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <fnmatch.h>
 #include <unistd.h>
 #include <errno.h>
@@ -77,6 +78,8 @@ has_modpath (const char *kernel_name)
   }
 }
 
+static char *create_kernel_archlinux (const char *hostcpu, const char *kernel);
+
 /* Create the kernel.  This chooses an appropriate kernel and makes a
  * symlink to it.
  *
@@ -96,6 +99,10 @@ create_kernel (const char *hostcpu, const char *kernel)
 {
   char **all_files = read_dir (KERNELDIR);
 
+  /* In ArchLinux, kernel is always named /boot/vmlinuz26. */
+  if (access ("/boot/vmlinuz26", F_OK) == 0)
+    return create_kernel_archlinux (hostcpu, kernel);
+
   /* In original: ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen */
   const char *patt;
   if (hostcpu[0] == 'i' && hostcpu[2] == '8' && hostcpu[3] == '6' &&
@@ -148,3 +155,54 @@ create_kernel (const char *hostcpu, const char *kernel)
            "febootstrap use, you shouldn't boot the Xen guest with it).\n");
   exit (EXIT_FAILURE);
 }
+
+/* In ArchLinux, kernel is always named /boot/vmlinuz26, and we have
+ * to use the 'file' command to work out what version it is.
+ */
+static char *
+create_kernel_archlinux (const char *hostcpu, const char *kernel)
+{
+  const char *file_cmd = "file /boot/vmlinuz26 | awk '{print $9}'";
+  FILE *pp;
+  char modversion[256];
+  char *modpath;
+  size_t len;
+
+  pp = popen (file_cmd, "r");
+  if (pp == NULL) {
+  error:
+    fprintf (stderr, "febootstrap-supermin-helper: %s: command failed\n",
+             file_cmd);
+    exit (EXIT_FAILURE);
+  }
+
+  if (fgets (modversion, sizeof modversion, pp) == NULL)
+    goto error;
+
+  if (pclose (pp) == -1)
+    goto error;
+
+  /* Chomp final \n */
+  len = strlen (modversion);
+  if (len > 0 && modversion[len-1] == '\n') {
+    modversion[len-1] = '\0';
+    len--;
+  }
+
+  /* Generate module path. */
+  modpath = xasprintf (MODULESDIR "/%s", modversion);
+
+  /* Check module path is a directory. */
+  if (!isdir (modpath)) {
+    fprintf (stderr, "febootstrap-supermin-helper: /boot/vmlinuz26 kernel exists but %s is not a valid module path\n",
+             modpath);
+    exit (EXIT_FAILURE);
+  }
+
+  /* Symlink from kernel to /boot/vmlinuz26. */
+  if (symlink ("/boot/vmlinuz26", kernel) == -1)
+    error (EXIT_FAILURE, errno, "symlink kernel");
+
+  /* Return module path. */
+  return modpath;
+}
-- 
1.7.3.2



More information about the Libguestfs mailing list