While this is Linux specific, it's something we use here. I've patched 
the stock grub 0.90 to add support for --ipappend on the kernel command 
IF diskless support is enabled.

What does this do? It passes ip=ipnum:serverip:gateway:netmask to the 
linux kernel from a dhcp request. We use it in systems here that the on 
board ethernet card does not have the ability to do network boot. We use 
grub on a floppy to boot the  system simulate a "network boot" of Linux 
on the system. grub takes the place of a boot ROM.

While we use it with our software in a special initrd to set the IP 
number on the interface, it can be used to support nfsroot for Linux or 
just plan autoconfiguration in the Linux kernel (check 
linux/Documentation/nfsroot.txt). PXELINUX supports this option and we 
use it to boot PXE enabled systems...so we just added it to grub to 
"netboot" these boot ROMless servers.

The patch is included in the message below the sig.

It would be nice if the Grub maintainers would consider adding this 
option to the mainstream grub code.

Thanks,

-- 
==========================================================================
Mark Buckaway             Tel: 416-203-4582   http://www.platespin.com
Sr. Software Developer    Fax: 416-203-0621   Email: [EMAIL PROTECTED]
Platespin Inc.      Reception: 416-203-6565
--------------------------------------------------------------------------
The statements made in this message are the opinions of the author and
may or may not reflect the opinions of Platespin Inc.
--------------------------------------------------------------------------

diff -ur grub-0.90.orig/netboot/etherboot.h grub-0.90/netboot/etherboot.h
--- grub-0.90.orig/netboot/etherboot.h  Thu Jan 11 18:33:09 2001
+++ grub-0.90/netboot/etherboot.h       Mon Aug 27 16:24:15 2001
@@ -461,6 +461,7 @@
  /* main.c */
  #ifdef GRUB
  extern void print_network_configuration P((void));
+extern char *get_network_configuration P((void));
  extern int ifconfig P((char *ip, char *sm, char *gw, char *svr));
  #endif /* GRUB */

diff -ur grub-0.90.orig/netboot/main.c grub-0.90/netboot/main.c
--- grub-0.90.orig/netboot/main.c       Thu Jan 11 18:33:09 2001
+++ grub-0.90/netboot/main.c    Tue Aug 28 10:21:27 2001
@@ -151,15 +151,16 @@
  static const char broadcast[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

  void
-print_network_configuration (void)
+sprint_ip_addr (char *buf, unsigned long addr)
  {
-  static void sprint_ip_addr (char *buf, unsigned long addr)
-    {
        grub_sprintf (buf, "%d.%d.%d.%d",
                    addr & 0xFF, (addr >> 8) & 0xFF,
                    (addr >> 16) & 0xFF, addr >> 24);
-    }
+}

+void
+print_network_configuration (void)
+{
    if (! eth_probe ())
      grub_printf ("No ethernet card found.\n");
    else if (! network_ready)
@@ -176,6 +177,31 @@
        grub_printf ("Address: %s    Netmask: %s\nServer: %s    Gateway: 
%s\n",
                   me, my_mask, server, gw);
      }
+}
+
+
+char *
+get_network_configuration (void)
+{
+  static char ipinfo[128];
+
+  if (! eth_probe ())
+    grub_printf ("No ethernet card found.\n");
+  else if (! network_ready)
+    grub_printf ("Not initialized yet.\n");
+  else
+    {
+      char me[16], my_mask[16], server[16], gw[16];
+
+      sprint_ip_addr (me, arptable[ARP_CLIENT].ipaddr.s_addr);
+      sprint_ip_addr (my_mask, netmask);
+      sprint_ip_addr (server, arptable[ARP_SERVER].ipaddr.s_addr);
+      sprint_ip_addr (gw, arptable[ARP_GATEWAY].ipaddr.s_addr);
+ 
        
+      grub_sprintf (ipinfo,"%s:%s:%s:%s",me, server, gw, my_mask);
+      return(&ipinfo);
+    }
+    return(NULL);
  }


diff -ur grub-0.90.orig/stage2/boot.c grub-0.90/stage2/boot.c
--- grub-0.90.orig/stage2/boot.c        Thu Jul  5 06:52:59 2001
+++ grub-0.90/stage2/boot.c     Tue Aug 28 10:10:21 2001
@@ -339,7 +339,26 @@
                *(dest++) = 'K';
              }

+#ifdef SUPPORT_NETBOOT
+ 
     /* Tack on the IP information from DHCP if so requested */
+ 
     if (! grub_strstr (arg, "ip=")
+ 
        && (load_flags & KERNEL_IPAPPEND_OPTION))
+ 
       {
+ 
        char *ipinfo;
+ 
        int iplen;
+
+ 
        ipinfo = get_network_configuration();
+ 
        if (ipinfo != NULL) {
+ 
                iplen=grub_strlen(ipinfo);
+ 
                grub_sprintf (dest, " ip=%s",ipinfo );
+ 
                dest += (iplen+4);
+
+ 
        }       
+ 
       }
+
            *dest = 0;
+           grub_printf("Cmdline: %s\n",CL_MY_LOCATION);
+#endif
          }

          /* offset into file */
diff -ur grub-0.90.orig/stage2/builtins.c grub-0.90/stage2/builtins.c
--- grub-0.90.orig/stage2/builtins.c    Thu Jun 21 19:15:02 2001
+++ grub-0.90/stage2/builtins.c Tue Aug 28 14:48:20 2001
@@ -2224,7 +2224,6 @@
    "Probe I/O ports used for the drive DRIVE."
  };

-
  /* kernel */
  static int
  kernel_func (char *arg, int flags)
@@ -2271,6 +2270,10 @@
         has no effect.  */
        else if (grub_memcmp (arg, "--no-mem-option", 15) == 0)
        load_flags |= KERNEL_LOAD_NO_MEM_OPTION;
+#ifdef SUPPORT_NETBOOT
+      else if (grub_memcmp (arg, "--ipappend", 10) == 0)
+ 
load_flags |= KERNEL_IPAPPEND_OPTION;
+#endif
        else
        break;

@@ -2298,6 +2301,26 @@
    return 0;
  }

+#ifdef SUPPORT_NETBOOT
+static struct builtin builtin_kernel =
+{
+  "kernel",
+  kernel_func,
+  BUILTIN_CMDLINE,
+  "kernel [--no-mem-option] [--type=TYPE] [--ipappend] FILE [ARG ...]",
+  "Attempt to load the primary boot image from FILE. The rest of the"
+  "line is passed verbatim as the \"kernel command line\".  Any modules"
+  " must be reloaded after using this command. The option --type is used"
+  " to suggest what type of kernel to be loaded. TYPE must be either of"
+  " \"netbsd\", \"freebsd\", \"openbsd\", \"linux\", \"biglinux\" and"
+  " \"multiboot\". The option --no-mem-option tells GRUB not to pass a"
+  " Linux's mem option automatically."
+  "--ipappend adds the IP number information (\"ip=...\") to the kernel"
+  "command line if a network card is found. Run dhcp BEFORE the kenrel"
+  "command for this to work correctly."
+};
+
+#else
  static struct builtin builtin_kernel =
  {
    "kernel",
@@ -2312,6 +2335,8 @@
    " \"multiboot\". The option --no-mem-option tells GRUB not to pass a"
    " Linux's mem option automatically."
  };
+
+#endif

  
  /* lock */
diff -ur grub-0.90.orig/stage2/shared.h grub-0.90/stage2/shared.h
--- grub-0.90.orig/stage2/shared.h      Thu Jun 21 22:32:56 2001
+++ grub-0.90/stage2/shared.h   Mon Aug 27 17:13:06 2001
@@ -1001,6 +1001,7 @@
  /* Define flags for load_image here.  */
  /* Don't pass a Linux's mem option automatically.  */
  #define KERNEL_LOAD_NO_MEM_OPTION     (1 << 0)
+#define KERNEL_IPAPPEND_OPTION         (2 << 0)

  kernel_t load_image (char *kernel, char *arg, kernel_t suggested_type,
                     unsigned long load_flags);


_______________________________________________
Bug-grub mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-grub

Reply via email to