Skip to contentSkip to conversation

Please support installation on Xen virtual block devices

PATCH Applied Ian Campbell 3 participants 12 messages Apr 24, 2008 – May 12, 2008

lore
Share & tools
lore
#0 lore raw

I filed this patch against the Debian grub2 package and the maintainer asked me to bring it to [email protected]. Took me an age but here I am ;-) [resending now I'm subscribed].

Quoted 9 lines · Back then I

The grub package does not currently support installation in a Xen guest domain because it does not understand the Xen virtual block devices (/dev/xvd[a-z]).

This support is mainly useful because it allows the Debian installer to work in a Xen guest without Xen specific workarounds.

It might also be useful for someone who wanted to switch between a guest between para-virtual and fully-virtualised (HVM) operation.

Patch is attached.

Ian.

Signature · 5 lines
Ian Campbell
Current Noise: Strapping Young Lad - Antiproduct

The Public is merely a multiplied "me."
		-- Mark Twain
util/biosdisk.c +7 -0
Index: grub2-1.95+20071101/util/biosdisk.c
===================================================================
@@ -640,6 +640,13 @@
 	  return path;
 	}
       
+      if ((strncmp ("xvd", p, 3) == 0) && p[3] >= 'a' && p[3] <= 'z')
+        {
+	  /* /dev/xvd[a-z][0-9]* */
+	  p[4] = '\0';
+	  return path;
+	}
+
       /* If this is an IDE disk or a SCSI disk.  */
       if ((strncmp ("hd", p, 2) == 0
 	   || strncmp ("sd", p, 2) == 0)
util/grub-mkdevicemap.c +25 -0
Index: grub2-1.95+20071101/util/grub-mkdevicemap.c
===================================================================
@@ -273,6 +273,13 @@
 {
   sprintf (name, "/dev/i2o/hd%c", unit);
 }
+
+static void
+get_xvd_disk_name (char *name, int unit)
+{
+  sprintf (name, "/dev/xvd%c", unit + 'a');
+}
+
 #endif
 
 /* Check if DEVICE can be read. If an error occurs, return zero,
@@ -515,6 +522,24 @@
   }
 #endif /* __linux__ */
 
+#ifdef __linux__
+  /* Xen Virtual Disks. */
+  for (i = 0; i < 16; i++)
+    {
+      char name[16];
+
+      get_xvd_disk_name (name, i);
+      if (check_device (name))
+        {
+            char *p;
+            p = grub_util_get_disk_name (num_hd, name);
+            fprintf (fp, "(%s)\t%s\n", p, name);
+            free (p);
+            num_hd++;
+        }
+    }
+#endif
+
  finish:
   if (fp != stdout)
     fclose (fp);
#1 lore raw

Any comments on this patch?

Cheers,
Ian.

Quoted 22 lines · Ian Campbell

I filed this patch against the Debian grub2 package and the maintainer asked me to bring it to [email protected]. Took me an age but here I am ;-) [resending now I'm subscribed].

Quoted 9 lines · Back then I

The grub package does not currently support installation in a Xen guest domain because it does not understand the Xen virtual block devices (/dev/xvd[a-z]).

This support is mainly useful because it allows the Debian installer to work in a Xen guest without Xen specific workarounds.

It might also be useful for someone who wanted to switch between a guest between para-virtual and fully-virtualised (HVM) operation.

Patch is attached.

Ian.
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 6 lines
Ian Campbell
Current Noise: Celtic Frost - Dawn of Megiddo

QOTD:
	"This is a one line proof... if we start sufficiently far to the
	left."
#2 lore raw
Quoted 1 line · Ian Campbell

Any comments on this patch?

It's basically OK, bug please provide the GNU style ChangeLog entry. The second part of the patch doesn't need preprocessor conditionals because it's already compiled for Linux only. Please use tabs for indentation rather than 8 spaces. The innermost block is indented two spaces too far.

In the long term, I would prefer that we don't need device.map at all. This is discussed in a separate thread.

Signature · 2 lines
Regards,
Pavel Roskin
#3 lore raw
Quoted 8 lines · Pavel Roskin
Quoted 1 line · Ian Campbell

Any comments on this patch?

It's basically OK, bug please provide the GNU style ChangeLog entry. The second part of the patch doesn't need preprocessor conditionals because it's already compiled for Linux only. Please use tabs for indentation rather than 8 spaces. The innermost block is indented two spaces too far.

Ian, it looks like you copied this style from existing code. Is that so?

In that case, I don't think the indentation issue concerns your patch (if we have to fix indentation, we could just do it in the whole file).

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#4 lore raw
Quoted 10 lines · Robert Millan
Quoted 8 lines · Pavel Roskin
Quoted 1 line · Ian Campbell

Any comments on this patch?

It's basically OK, bug please provide the GNU style ChangeLog entry. The second part of the patch doesn't need preprocessor conditionals because it's already compiled for Linux only. Please use tabs for indentation rather than 8 spaces. The innermost block is indented two spaces too far.

Quoted 4 lines

Ian, it looks like you copied this style from existing code. Is that so?

In that case, I don't think the indentation issue concerns your patch (if we have to fix indentation, we could just do it in the whole file).

Apparently, it was copied from the code that was inside an extra "for" loop. Anyway, it's a very minor issue, and I would just apply the patch right now, but I prefer not to write changelog entries for others.

Signature · 2 lines
Regards,
Pavel Roskin
#5 lore raw
Quoted 3 lines · Pavel Roskin

Apparently, it was copied from the code that was inside an extra "for" loop. Anyway, it's a very minor issue, and I would just apply the patch right now, but I prefer not to write changelog entries for others.

Sorry about that. An updated version is attached with changelog and (hopefully) correct indentation.

I wasn't sure about the pre-processor conditionals, there seems to be lots of existing ifdef __linux__ in there and the device path is pretty Linux specific. I merged it into the one above but if you want them gone I will redo.

Ian.

Signature · 5 lines
Ian Campbell

omnibiblious, adj.:
	Indifferent to type of drink.  Ex: "Oh, you can get me anything.
	I'm omnibiblious."
ChangeLog +6 -0
diff -purN -X /home/ijc/development/dontdiff.txt grub2-1.96+20080430.orig/ChangeLog grub2-1.96+20080430/ChangeLog
@@ -1,3 +1,9 @@
+2008-05-07  Ian Campbell  <[email protected]>
+
+	* util/biosdisk.c (get_os_disk): Recognise xvd type disks.
+	* util/grub-mkdevicemap.c (get_xvd_disk_name): New function.
+	(make_device_map): Output entries for xvd type disks.
+	
 2008-04-30  Robert Millan  <[email protected]>
 
 	Based on patch from Fabian Greffrath <[email protected]>
util/biosdisk.c +7 -0
diff -purN -X /home/ijc/development/dontdiff.txt grub2-1.96+20080430.orig/util/biosdisk.c grub2-1.96+20080430/util/biosdisk.c
@@ -645,6 +645,13 @@ get_os_disk (const char *os_dev)
 	  return path;
 	}
       
+      if ((strncmp ("xvd", p, 3) == 0) && p[3] >= 'a' && p[3] <= 'z')
+        {
+	  /* /dev/xvd[a-z][0-9]* */
+	  p[4] = '\0';
+	  return path;
+	}
+
       /* If this is an IDE disk or a SCSI disk.  */
       if ((strncmp ("hd", p, 2) == 0
 	   || strncmp ("sd", p, 2) == 0)
util/grub-mkdevicemap.c +22 -0
diff -purN -X /home/ijc/development/dontdiff.txt grub2-1.96+20080430.orig/util/grub-mkdevicemap.c grub2-1.96+20080430/util/grub-mkdevicemap.c
@@ -273,6 +273,12 @@ get_i2o_disk_name (char *name, char unit
 {
   sprintf (name, "/dev/i2o/hd%c", unit);
 }
+
+static void
+get_xvd_disk_name (char *name, int unit)
+{
+  sprintf (name, "/dev/xvd%c", unit + 'a');
+}
 #endif
 
 /* Check if DEVICE can be read. If an error occurs, return zero,
@@ -513,6 +519,22 @@ make_device_map (const char *device_map,
 	  }
       }
   }
+
+  /* Xen Virtual Disks. */
+  for (i = 0; i < 16; i++)
+    {
+      char name[16];
+
+      get_xvd_disk_name (name, i);
+      if (check_device (name))
+	{
+	  char *p;
+	  p = grub_util_get_disk_name (num_hd, name);
+	  fprintf (fp, "(%s)\t%s\n", p, name);
+	  free (p);
+	  num_hd++;
+	}
+    }
 #endif /* __linux__ */
 
  finish:
Applied
#6 lore raw
Quoted 5 lines · Ian Campbell
Quoted 3 lines · Pavel Roskin

Apparently, it was copied from the code that was inside an extra "for" loop. Anyway, it's a very minor issue, and I would just apply the patch right now, but I prefer not to write changelog entries for others.

Quoted 7 lines

Sorry about that. An updated version is attached with changelog and (hopefully) correct indentation.

I wasn't sure about the pre-processor conditionals, there seems to be lots of existing ifdef __linux__ in there and the device path is pretty Linux specific. I merged it into the one above but if you want them gone I will redo.

Applied.

It looks like you missed changes to linux_find_partition(). I'll fix it myself (if indeed necessary).

Signature · 2 lines
Regards,
Pavel Roskin
#7 lore raw
Quoted 9 lines · Pavel Roskin
Quoted 8 lines · Ian Campbell
Quoted 3 lines · Pavel Roskin

Apparently, it was copied from the code that was inside an extra "for" loop. Anyway, it's a very minor issue, and I would just apply the patch right now, but I prefer not to write changelog entries for others.

Sorry about that. An updated version is attached with changelog and (hopefully) correct indentation.

Quoted 6 lines
Quoted 4 lines

I wasn't sure about the pre-processor conditionals, there seems to be lots of existing ifdef __linux__ in there and the device path is pretty Linux specific. I merged it into the one above but if you want them gone I will redo.

Applied.

Awesome thanks!

Quoted 2 lines

It looks like you missed changes to linux_find_partition(). I'll fix it myself (if indeed necessary).

It doesn't seem to be needed for my simplistic test of installing the grub-pc .deb and running "install-grub /dev/xvda":

        # dpkg -l grub-pc
        Desired=Unknown/Install/Remove/Purge/Hold
        | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
        |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
        ||/ Name           Version        Description
        +++-==============-==============-============================================
        ii  grub-pc        1.96+20080430- GRand Unified Bootloader, version 2 (PC/BIOS
        # grub-install /dev/xvda
        Installation finished. No error reported.
        This is the contents of the device map /boot/grub/device.map.
        Check if this is correct or not. If any of the lines is incorrect,
        fix it and re-run the script `grub-install'.

(hd0) /dev/xvda
# grub-install /dev/xvda1
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'.

(hd0) /dev/xvda

However to my not-so-familiar-with-grub eyes it does look like such a change would make sense.

Cheers,
Ian.

Signature · 4 lines
Ian Campbell

I love you more than anything in this world.  I don't expect that will last.
		-- Elvis Costello
#8 lore raw
Quoted 22 lines · Ian Campbell

It doesn't seem to be needed for my simplistic test of installing the grub-pc .deb and running "install-grub /dev/xvda":

        # dpkg -l grub-pc
        Desired=Unknown/Install/Remove/Purge/Hold
        | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
        |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
        ||/ Name           Version        Description
        +++-==============-==============-============================================
        ii  grub-pc        1.96+20080430- GRand Unified Bootloader, version 2 (PC/BIOS
        # grub-install /dev/xvda
        Installation finished. No error reported.
        This is the contents of the device map /boot/grub/device.map.
        Check if this is correct or not. If any of the lines is incorrect,
        fix it and re-run the script `grub-install'.

(hd0) /dev/xvda
# grub-install /dev/xvda1
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'.

Quoted 4 lines

(hd0) /dev/xvda

However to my not-so-familiar-with-grub eyes it does look like such a change would make sense.

If you want to test the full functionality, try using grub-probe to convert /dev/xvda1 to a grub drive (this checks GRUB knows how to count partitions in Xen devices).

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)
#9 lore raw
Quoted 3 lines · Robert Millan

If you want to test the full functionality, try using grub-probe to convert /dev/xvda1 to a grub drive (this checks GRUB knows how to count partitions in Xen devices).

I get these results:

        d-i:~# grub-probe -t drive /
        (hd0,1)
        d-i:~# grub-probe -t drive -d /dev/xvda
        (hd0)
        d-i:~# grub-probe -t drive -d /dev/xvda1
        (hd0,1)

Seems correct to me, right?

Ian.

Signature · 4 lines
Ian Campbell

It is not best to swap horses while crossing the river.
		-- Abraham Lincoln
#10 lore raw
Quoted 6 lines · Ian Campbell
Quoted 3 lines · Robert Millan

If you want to test the full functionality, try using grub-probe to convert /dev/xvda1 to a grub drive (this checks GRUB knows how to count partitions in Xen devices).

I get these results:

Quoted 8 lines
        d-i:~# grub-probe -t drive /
        (hd0,1)
        d-i:~# grub-probe -t drive -d /dev/xvda
        (hd0)
        d-i:~# grub-probe -t drive -d /dev/xvda1
        (hd0,1)

Seems correct to me, right?

Actually, linux_find_partition() does something different - it converts an offset on the disk to a partition in Linux notation.

I understand that linux_find_partition() is only used for cache synchronization. It may fail in more subtle ways. And it looks like support for other devices, such as /dev/i2o, is also missing.

Perhaps linux_find_partition() should default to adding the bare number (format="%d") and only specifically handle the cases where something different is needed.

Signature · 2 lines
Regards,
Pavel Roskin
#11 lore raw
In reply to Ian Campbell
Quoted 6 lines · Ian Campbell
Quoted 3 lines · Robert Millan

If you want to test the full functionality, try using grub-probe to convert /dev/xvda1 to a grub drive (this checks GRUB knows how to count partitions in Xen devices).

I get these results:

Quoted 8 lines
        d-i:~# grub-probe -t drive /
        (hd0,1)
        d-i:~# grub-probe -t drive -d /dev/xvda
        (hd0)
        d-i:~# grub-probe -t drive -d /dev/xvda1
        (hd0,1)

Seems correct to me, right?

Yep

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)