qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Allow -kernel without -hda
@ 2006-05-01  3:11 Ed Swierk
  2006-05-01 12:29 ` Fabrice Bellard
  0 siblings, 1 reply; 2+ messages in thread
From: Ed Swierk @ 2006-05-01  3:11 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 767 bytes --]

The qemu -kernel option currently requires specifying a hard disk
image with -hda. Ostensibly at least one hard disk is needed for
qemu's boot loader to populate the partition table in its array of
boot sectors.

Passing -hda /dev/zero tricks qemu into booting, which demonstrates
that the requirement is unnecessary. Booting with no disk image is
needed to support diskless configurations where a remote NFS directory
is used as the root filesystem. In this scenario, the user invokes
qemu with -kernel and -initrd options, with a specially configured
initrd that NFS-mounts a filesystem on / before passing control to the
real init.

The attached patch permits using the -kernel option with no disk
images, and skips copying the partition table in this case.

--Ed

[-- Attachment #2: qemu-kernel-without-hda.patch --]
[-- Type: text/x-patch, Size: 1399 bytes --]

diff -BurN qemu-snapshot-2006-03-27_23.orig/hw/pc.c qemu-snapshot-2006-03-27_23/hw/pc.c
--- qemu-snapshot-2006-03-27_23.orig/hw/pc.c	2006-04-05 13:05:17.000000000 +0000
+++ qemu-snapshot-2006-03-27_23/hw/pc.c	2006-04-05 13:12:40.000000000 +0000
@@ -707,10 +707,6 @@
         uint8_t bootsect[512];
         uint8_t old_bootsect[512];
 
-        if (bs_table[0] == NULL) {
-            fprintf(stderr, "A disk image must be given for 'hda' when booting a Linux kernel\n");
-            exit(1);
-        }
         snprintf(buf, sizeof(buf), "%s/%s", bios_dir, LINUX_BOOT_FILENAME);
         ret = load_image(buf, bootsect);
         if (ret != sizeof(bootsect)) {
@@ -719,12 +715,14 @@
             exit(1);
         }
 
-        if (bdrv_read(bs_table[0], 0, old_bootsect, 1) >= 0) {
-            /* copy the MSDOS partition table */
-            memcpy(bootsect + 0x1be, old_bootsect + 0x1be, 0x40);
-        }
+        if (bs_table[0]) {
+            if (bdrv_read(bs_table[0], 0, old_bootsect, 1) >= 0) {
+                /* copy the MSDOS partition table */
+                memcpy(bootsect + 0x1be, old_bootsect + 0x1be, 0x40);
+            }
 
-        bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect));
+            bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect));
+        }
 
         /* now we can load the kernel */
         ret = load_kernel(kernel_filename, 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] Allow -kernel without -hda
  2006-05-01  3:11 [Qemu-devel] [PATCH] Allow -kernel without -hda Ed Swierk
@ 2006-05-01 12:29 ` Fabrice Bellard
  0 siblings, 0 replies; 2+ messages in thread
From: Fabrice Bellard @ 2006-05-01 12:29 UTC (permalink / raw)
  To: qemu-devel

I agree that the feature is useful, but your patch is incomplete: 
without bs_table[0], the boot sector cannot be created and the Linux 
kernel cannot be launched. Maybe you have a specific Ethernet BIOS to 
enable that ? Someone submitted a new block driver which simulated 
"/dev/zero" and it may be another solution.

Regards,

Fabrice.

Ed Swierk wrote:
> The qemu -kernel option currently requires specifying a hard disk
> image with -hda. Ostensibly at least one hard disk is needed for
> qemu's boot loader to populate the partition table in its array of
> boot sectors.
> 
> Passing -hda /dev/zero tricks qemu into booting, which demonstrates
> that the requirement is unnecessary. Booting with no disk image is
> needed to support diskless configurations where a remote NFS directory
> is used as the root filesystem. In this scenario, the user invokes
> qemu with -kernel and -initrd options, with a specially configured
> initrd that NFS-mounts a filesystem on / before passing control to the
> real init.
> 
> The attached patch permits using the -kernel option with no disk
> images, and skips copying the partition table in this case.
> 
> --Ed
> 
> 
> ------------------------------------------------------------------------
> 
> diff -BurN qemu-snapshot-2006-03-27_23.orig/hw/pc.c qemu-snapshot-2006-03-27_23/hw/pc.c
> --- qemu-snapshot-2006-03-27_23.orig/hw/pc.c	2006-04-05 13:05:17.000000000 +0000
> +++ qemu-snapshot-2006-03-27_23/hw/pc.c	2006-04-05 13:12:40.000000000 +0000
> @@ -707,10 +707,6 @@
>          uint8_t bootsect[512];
>          uint8_t old_bootsect[512];
>  
> -        if (bs_table[0] == NULL) {
> -            fprintf(stderr, "A disk image must be given for 'hda' when booting a Linux kernel\n");
> -            exit(1);
> -        }
>          snprintf(buf, sizeof(buf), "%s/%s", bios_dir, LINUX_BOOT_FILENAME);
>          ret = load_image(buf, bootsect);
>          if (ret != sizeof(bootsect)) {
> @@ -719,12 +715,14 @@
>              exit(1);
>          }
>  
> -        if (bdrv_read(bs_table[0], 0, old_bootsect, 1) >= 0) {
> -            /* copy the MSDOS partition table */
> -            memcpy(bootsect + 0x1be, old_bootsect + 0x1be, 0x40);
> -        }
> +        if (bs_table[0]) {
> +            if (bdrv_read(bs_table[0], 0, old_bootsect, 1) >= 0) {
> +                /* copy the MSDOS partition table */
> +                memcpy(bootsect + 0x1be, old_bootsect + 0x1be, 0x40);
> +            }
>  
> -        bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect));
> +            bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect));
> +        }
>  
>          /* now we can load the kernel */
>          ret = load_kernel(kernel_filename, 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Qemu-devel mailing list
> Qemu-devel@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/qemu-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-05-01 12:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-01  3:11 [Qemu-devel] [PATCH] Allow -kernel without -hda Ed Swierk
2006-05-01 12:29 ` Fabrice Bellard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).