[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[patch 2/2] Use dhcp root-path information for netboot



This patch extends mkinitrd with the possibility of extracting the nfs root-path option received via dhcp. By booting the kernel with "root=/dev/nfs" nash would extract the root-path information. Otherwise it would behave as usual. The pseudo-device "/dev/nfs" is also used in the Kernel based IP autoconfiguration. This patch makes it possible to create only one zImage.initrd resp. initrd for many diskless blades. This patch depends on a little change in libdhcp which adds "root-path" to the list of dhcp requests.
Signed-off-by: Jochen Roth <jroth linux vnet ibm com>
Index: mkinitrd-6.0.9/nash/nash.c
===================================================================
--- mkinitrd-6.0.9.orig/nash/nash.c
+++ mkinitrd-6.0.9/nash/nash.c
@@ -1443,10 +1443,58 @@ resumeCommand(char * cmd, char * end)
    return 0;
}

+static void
+get_dhcp_root_path(char **root_path, char **root_options)
+{
+    FILE *lease_file;
+    int file_length;
+    char *buf = NULL;
+    char *path;
+
+    lease_file = fopen("/var/lib/dhclient/dhclient.leases", "r");
+    if (!lease_file)
+        goto out;
+
+    if (fseek(lease_file, 0, SEEK_END))
+        goto out;
+    file_length = ftell(lease_file);
+    if (file_length < 0)
+        goto out;
+    if (fseek(lease_file, 0, SEEK_SET))
+        goto out;
+
+    buf = malloc(sizeof(char) * file_length);
+    if (!buf)
+        goto out;
+
+    if (fread(buf, file_length, 1, lease_file) != 1)
+        goto out;
+
+    path = strstr(buf, "option root-path");
+    if (!path)
+        goto out;
+
+    path = strchr(path, '\"') + sizeof(char);
+    if (strchr(path, ',')) {
+        *root_path = strndup(path, strchr(path, ',') - path);
+ *root_options = strndup(strchr(path, ',') + sizeof(char), + strchr(path, '\"') - path);
+    } else {
+        *root_path = strndup(path, strchr(path, '\"') - path);
+    }
+out:
+    if (buf)
+        free(buf);
+    if (lease_file)
+        fclose(lease_file);
+}
+
static int
mkrootdevCommand(char *cmd, char *end)
{
    char *chptr = NULL, *root;
+    char *dhcp_root_path = NULL;
+    char *dhcp_root_options = NULL;
    int i;
    FILE *fstab;
    struct mntent mnt = {
@@ -1518,6 +1566,17 @@ mkrootdevCommand(char *cmd, char *end)
    if (!strncmp(mnt.mnt_type, "nfs", 3)) {
        mnt.mnt_fsname = strdup(root);
    }
+    if (!strcmp(mnt.mnt_fsname, "/dev/nfs")) {
+        get_dhcp_root_path(&dhcp_root_path, &dhcp_root_options);
+        if (dhcp_root_path) {
+            mnt.mnt_fsname = dhcp_root_path;
+            if (dhcp_root_options)
+                mnt.mnt_opts = dhcp_root_options;
+
+ printf("mkrootdev: using dhcp_root_path: %s options: %s\n", + dhcp_root_path, dhcp_root_options ? dhcp_root_options : "");
+        }
+    }

    umask(0122);
    fstab = fopen("/etc/fstab", "w+");
@@ -1526,6 +1585,12 @@ mkrootdevCommand(char *cmd, char *end)
        return 1;
    }
    addmntent(fstab, &mnt);
+
+    if (dhcp_root_path)
+        free(dhcp_root_path);
+    if (dhcp_root_options)
+        free(dhcp_root_options);
+
    fclose(fstab);

if (!strncmp(mnt.mnt_type, "nfs", 3)) return 0;
--


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]