Skip to contentSkip to conversation

boot a linux kernel from non-ide device

PATCH In review Glauber de Oliveira Costa 4 participants 4 messages Feb 8, 2008 2 messages not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 boot a linux kernel from non-ide device

Since it's now possible to use the -drive option, the test for something in the index 0 of the IDE bus is too restrictive.

A better idea, IMHO, is to check if the user specified any bootable device, and only if not, fallback to the default, compatible behaviour of checking hda regardless of the presence of a boot=on arg.

Signature · 5 lines
Glauber de Oliveira Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."

commit 65b8fcf3bc5b754b720a04fa7efed6fdcd472a6a

Author: Glauber de Oliveira Costa <[email protected]>
Date:   Fri Feb 8 05:02:47 2008 -0200

[PATCH] boot a linux kernel from non-ide device

Since it's now possible to use the -drive option, the test for something in the index 0 of the IDE bus is too restrictive.

A better idea, IMHO, is to check if the user specified any bootable device, and only if not, fallback to the default, compatible behaviour of checking hda regardless of the presence of a boot=on arg.

qemu/hw/pc.c +10 -7
index 5ce28ab..a9b0f71 100644
@@ -398,11 +398,14 @@ static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
 {
     uint8_t bootsect[512], *p;
     int i;
-    int hda;
-
-    hda = drive_get_index(IF_IDE, 0, 0);
-    if (hda == -1) {
-	fprintf(stderr, "A disk image must be given for 'hda' when booting "
+    int hda = -1, boot_device;
+
+    if (extboot_drive != -1)
+        boot_device = extboot_drive;
+    else if ((hda = drive_get_index(IF_IDE, 0, 0)) != -1) 
+	boot_device = hda;
+    else {
+	fprintf(stderr, "A bootable disk image must be given when booting "
 		"a Linux kernel\n");
 	exit(1);
     }
@@ -410,7 +413,7 @@ static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
     memset(bootsect, 0, sizeof(bootsect));
 
     /* Copy the MSDOS partition table if possible */
-    bdrv_read(drives_table[hda].bdrv, 0, bootsect, 1);
+    bdrv_read(drives_table[boot_device].bdrv, 0, bootsect, 1);
 
     /* Make sure we have a partition signature */
     bootsect[510] = 0x55;
@@ -447,7 +450,7 @@ static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
     *p++ = segs[1];		/* CS */
     *p++ = segs[1] >> 8;
 
-    bdrv_set_boot_sector(drives_table[hda].bdrv, bootsect, sizeof(bootsect));
+    bdrv_set_boot_sector(drives_table[boot_device].bdrv, bootsect, sizeof(bootsect));
 }
 
 static int load_kernel(const char *filename, uint8_t *addr,
#1 lore raw
Quoted 7 lines · Glauber de Oliveira Costa

Since it's now possible to use the -drive option, the test for something in the index 0 of the IDE bus is too restrictive.

A better idea, IMHO, is to check if the user specified any bootable device, and only if not, fallback to the default, compatible behaviour of checking hda regardless of the presence of a boot=on arg.

extboot isn't in upstream QEMU yet so this patch won't apply.

Regards,

Anthony LIguori

A message that is not in the archive (sent off-list or not yet received): 5d6222a80802072305t2d536595q97d169df9dc00a48-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#3 lore raw

PATCH 1/1 boot a linux kernel from non-ide device

Reposting to kvm-devel, since aliguori notices that I'm relying on non-upstream features of qemu

---------- Forwarded message ----------
From: Glauber de Oliveira Costa <[email protected]>
Date: Feb 8, 2008 5:05 AM
Subject: [PATCH] boot a linux kernel from non-ide device
To: [email protected]

Since it's now possible to use the -drive option, the test for something in the index 0 of the IDE bus is too restrictive.

A better idea, IMHO, is to check if the user specified any bootable device, and only if not, fallback to the default, compatible behaviour of checking hda regardless of the presence of a boot=on arg.

--
Glauber de Oliveira Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."

Signature · 5 lines
Glauber de Oliveira Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."

commit 65b8fcf3bc5b754b720a04fa7efed6fdcd472a6a

Author: Glauber de Oliveira Costa <[email protected]>
Date:   Fri Feb 8 05:02:47 2008 -0200

[PATCH] boot a linux kernel from non-ide device

Since it's now possible to use the -drive option, the test for something in the index 0 of the IDE bus is too restrictive.

A better idea, IMHO, is to check if the user specified any bootable device, and only if not, fallback to the default, compatible behaviour of checking hda regardless of the presence of a boot=on arg.

qemu/hw/pc.c +10 -7
index 5ce28ab..a9b0f71 100644
@@ -398,11 +398,14 @@ static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
 {
     uint8_t bootsect[512], *p;
     int i;
-    int hda;
-
-    hda = drive_get_index(IF_IDE, 0, 0);
-    if (hda == -1) {
-	fprintf(stderr, "A disk image must be given for 'hda' when booting "
+    int hda = -1, boot_device;
+
+    if (extboot_drive != -1)
+        boot_device = extboot_drive;
+    else if ((hda = drive_get_index(IF_IDE, 0, 0)) != -1) 
+	boot_device = hda;
+    else {
+	fprintf(stderr, "A bootable disk image must be given when booting "
 		"a Linux kernel\n");
 	exit(1);
     }
@@ -410,7 +413,7 @@ static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
     memset(bootsect, 0, sizeof(bootsect));
 
     /* Copy the MSDOS partition table if possible */
-    bdrv_read(drives_table[hda].bdrv, 0, bootsect, 1);
+    bdrv_read(drives_table[boot_device].bdrv, 0, bootsect, 1);
 
     /* Make sure we have a partition signature */
     bootsect[510] = 0x55;
@@ -447,7 +450,7 @@ static void generate_bootsect(uint32_t gpr[8], uint16_t segs[6], uint16_t ip)
     *p++ = segs[1];		/* CS */
     *p++ = segs[1] >> 8;
 
-    bdrv_set_boot_sector(drives_table[hda].bdrv, bootsect, sizeof(bootsect));
+    bdrv_set_boot_sector(drives_table[boot_device].bdrv, bootsect, sizeof(bootsect));
 }
 
 static int load_kernel(const char *filename, uint8_t *addr,

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

A message that is not in the archive (sent off-list or not yet received): 5d6222a80802080742t3dfca5bs7894648af5d528a3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#5 lore raw

This patch seems reasonable to me.

But FWIW, with extboot, it's possible to implement the -kernel option in a saner way. extboot already has code to take over int19 and load a kernel from memory on boot. It was based on the old -kernel support in QEMU (prior to hpa's rewrite) so it's not enabled at the moment. It should be pretty easy to update it though.

This approach would allow -kernel to be used without any disk (which also solves your problem, but in a different way). We can also eliminate all the boot sector hijacking silliness.

Regards,

Anthony Liguori

Quoted 17 lines · Glauber de Oliveira Costa

Reposting to kvm-devel, since aliguori notices that I'm relying on non-upstream features of qemu

---------- Forwarded message ----------
From: Glauber de Oliveira Costa <[email protected]>
Date: Feb 8, 2008 5:05 AM
Subject: [PATCH] boot a linux kernel from non-ide device
To: [email protected]

Since it's now possible to use the -drive option, the test for something in the index 0 of the IDE bus is too restrictive.

A better idea, IMHO, is to check if the user specified any bootable device, and only if not, fallback to the default, compatible behaviour of checking hda regardless of the presence of a boot=on arg.

Quoted 10 lines

--
Glauber de Oliveira Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/