Skip to contentSkip to conversation

porting Grub to Xen

DISCUSSION Ferenc Wagner 2 participants 9 messages May 18, 2009 – Jun 18, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

Last week we had a very interesting chat on #grub, discussing various possibilities to run Grub in a Xen paravirtual domain. You showed some interest in properly porting Grub to this architecture instead of my misguided attempts to go through grub-emu and kexec. You asked for the interface docs to be able to assess the task. Please find it under

http://www.cl.cam.ac.uk/research/srg/netos/xen/documentation.html

referenced as "Developer Manual" in HTML and PDF. I put online the current MiniOS source at http://apt.niif.hu/minios.tgz, which is bundled with Xen, and provides a running example of the interface specification. Porting could mean taking the necessary parts or this, and adding the Grub interface. Please find attached my current disk interface, which works under grub-emu (under MiniOS).

So, what do you think about this? I'm afraid I don't have the necessary low-level knowledge to be of much help starting, but at least have a definite need, so I'll try my best.

Thanks,
Feri.

#include <grub/disk.h>

#include <grub/util/xendisk.h>

/* Parts stolen from stubdom/grub/mini-os.c */

#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <assert.h>

#include <hypervisor.h>
#include <blkfront.h>

unsigned int blk_nb;
struct blkfront_dev **blk_dev;
struct blkfront_info *blk_info;

static int vbdcmp(const void *_vbd1, const void *_vbd2) {
    char *vbd1 = *(char **)_vbd1;
    char *vbd2 = *(char **)_vbd2;
    int vbdn1 = atoi(vbd1);
    int vbdn2 = atoi(vbd2);
    return vbdn1 - vbdn2;
}

static unsigned int
init_disk (void)

{
    char **list;
    char *msg;
    unsigned int i;
    char *path;

    msg = xenbus_ls(XBT_NIL, "device/vbd", &list);
    if (msg) {
        printk("Error %s while reading list of disks\n", msg);
        free(msg);
        return 0;
    }
    blk_nb = 0;
    while (list[blk_nb])
        blk_nb++;
    blk_dev = malloc(blk_nb * sizeof(*blk_dev));
    blk_info = malloc(blk_nb * sizeof(*blk_info));

    qsort(list, blk_nb, sizeof(*list), vbdcmp);

    for (i = 0; i < blk_nb; i++) {
        printk("vbd %s is hd%d\n", list[i], i);
        asprintf(&path, "device/vbd/%s", list[i]);
        blk_dev[i] = init_blkfront(path, &blk_info[i]);
        free(path);
        free(list[i]);
    }
    return blk_nb;
}

static grub_err_t
read_sectors (unsigned int drive, void *data, size_t count, off_t from)

{
	struct blkfront_aiocb aio;

	if (drive >= blk_nb) return GRUB_ERR_UNKNOWN_DEVICE;

	aio.aio_dev = blk_dev[drive];
	aio.aio_buf = data;
	aio.aio_nbytes = count * blk_info[drive].sector_size;
	aio.aio_offset =  from * blk_info[drive].sector_size;
	aio.aio_cb = NULL;
	blkfront_read (&aio);
	return GRUB_ERR_NONE; /* FIXME report error */
}

/* Grub interface */

static int
grub_util_xendisk_iterate (int (*hook) (const char *name))

{
    unsigned int i;
    char buf[10];

    for (i = 0; i < blk_nb; i++) {
        int ret;

        snprintf (buf, sizeof buf, "%d", i);
        ret = hook (buf);
        if (ret) return 1;
    }
    return 0;
}

static grub_err_t
grub_util_xendisk_open (const char *name, grub_disk_t disk)

{
    unsigned int drive = atoi (name);

    if (drive >= blk_nb) return GRUB_ERR_UNKNOWN_DEVICE;
    disk->has_partitions = 0;
    disk->id = drive;
    disk->total_sectors = blk_info[drive].sectors;
    return GRUB_ERR_NONE;
}

char buffer[GRUB_DISK_SECTOR_SIZE] __attribute__((aligned(PAGE_SIZE)));

static grub_err_t
grub_util_xendisk_read (grub_disk_t disk, grub_disk_addr_t sector,
grub_size_t count, char *buf)

{
    grub_size_t i;

    for (i=0; i<count; i++) {
        if (read_sectors (disk->id, buffer, 1, sector+i))
            return GRUB_ERR_READ_ERROR;
        memcpy (buf+i*GRUB_DISK_SECTOR_SIZE, buffer, GRUB_DISK_SECTOR_SIZE);
    }
    return GRUB_ERR_NONE;

}

static struct grub_disk_dev grub_util_xendisk_dev = {
.name = "xendisk",
.id = GRUB_DISK_DEVICE_XEN_ID,
.iterate = grub_util_xendisk_iterate, .open = grub_util_xendisk_open,
.close = 0,
.read = grub_util_xendisk_read,
.write = 0,
.next = 0
};

void
grub_util_xendisk_init ()

{
    grub_disk_dev_register (&grub_util_xendisk_dev);
}
#1 lore raw

Hello

Quoted 8 lines · Ferenc Wagner

Hi,

Last week we had a very interesting chat on #grub, discussing various possibilities to run Grub in a Xen paravirtual domain.  You showed some interest in properly porting Grub to this architecture instead of my misguided attempts to go through grub-emu and kexec.  You asked for the interface docs to be able to assess the task.  Please find it under

Quoted 4 lines

http://www.cl.cam.ac.uk/research/srg/netos/xen/documentation.html

referenced as "Developer Manual" in HTML and PDF.  I put online the current MiniOS source at http://apt.niif.hu/minios.tgz,

Xen is under GPLv2. Unless otherwise stated minios is under GPLv2 too. In quick look I haven't found a separate license for minios. grub2 is under GPLv3+ which makes it incompatible with gplv2. So this code can't be used by grub2. If you really need a reference implementation I suggest taking a look at freebsd. Ensure however that it's under new BSD license before taking any code from it. If it contains the advertising clause (old BSD license) then it's not GPLv3+-compatible. Normally whole BSD is under new BSD license but check it. Also when you borrow any code put borrowed code into separate files and clearly indicate the origin and the original license. Also it's much better in licensing and technical point of view to do it from scratch: it usually results in a much cleaner code and it's not encumbered by additional clauses

Quoted 20 lines

which is
bundled with Xen, and provides a running example of the interface specification.  Porting could mean taking the necessary parts or this, and adding the Grub interface.  Please find attached my current disk interface, which works under grub-emu (under MiniOS).

So, what do you think about this?  I'm afraid I don't have the necessary low-level knowledge to be of much help starting, but at least have a definite need, so I'll try my best.

Thanks,
Feri.

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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#8 lore raw
In reply to Ferenc Wagner
Quoted 1 line · Ferenc Wagner

my misguided attempts to go through grub-emu and kexec.

Just to clear up a possible miscommunication: the above kexec doesn't have too much to do with the Linux kexec mechanism. Rather, it's a separate implementation to fully replace some software running in a paravirtual domain with another. It isn't necessarily Linux specific, though there aren't too many paravitual OS-es yet. Its author explicitly suggested its use in Grub, so relicensing shouldn't be a problem (similarly for MiniOS), but I asked for clarification.

Signature · 2 lines
Thanks,
Feri.
#2 lore raw
In reply to Vladimir 'phcoder' Serbinenko
Quoted 8 lines · Vladimir 'phcoder' Serbinenko
Quoted 6 lines · Ferenc Wagner

Last week we had a very interesting chat on #grub, discussing various possibilities to run Grub in a Xen paravirtual domain.  You showed some interest in properly porting Grub to this architecture instead of my misguided attempts to go through grub-emu and kexec.  You asked for the interface docs to be able to assess the task.  Please find it under

Quoted 7 lines
Quoted 4 lines

http://www.cl.cam.ac.uk/research/srg/netos/xen/documentation.html

referenced as "Developer Manual" in HTML and PDF.  I put online the current MiniOS source at http://apt.niif.hu/minios.tgz,

Xen is under GPLv2. Unless otherwise stated minios is under GPLv2 too. In quick look I haven't found a separate license for minios.

Neither have I, but xen-devel says MiniOS is BSD, and should be acceptable for Grub.

Quoted 3 lines

Also it's much better in licensing and technical point of view to do it from scratch: it usually results in a much cleaner code and it's not encumbered by additional clauses

Like I said, realistically I'm rather far from being able to implement this from scratch. Unless a low-level expert lays down the groundwork, I'll have to go back bolting the "kexec" code unto grub-emu and running that.

Actually, I wonder if Grub could do any better booting paravirtual
domains: you said Grub already knows how to boot Linux, it's even multiboot compliant, but I'm not sure that really helps much in this situation, where it has to replace a PV image with another.

Signature · 2 lines
Thanks,
Feri.
#3 lore raw
Quoted 3 lines

Neither have I, but xen-devel says MiniOS is BSD, and should be acceptable for Grub.

If it's under MIT or new BSD license it is. However no code with unclear licensing can be used in grub2

Quoted 10 lines
Quoted 4 lines

Also it's much better in licensing and technical point of view to do it from scratch: it usually results in a much cleaner code and it's not encumbered by additional clauses

Like I said, realistically I'm rather far from being able to implement this from scratch. Unless a low-level expert lays down the groundwork, I'll have to go back bolting the "kexec" code unto grub-emu and running that.

Quoted 4 lines

Actually, I wonder if Grub could do any better booting paravirtual
domains: you said Grub already knows how to boot Linux, it's even multiboot compliant, but I'm not sure that really helps much in this situation, where it has to replace a PV image with another.

It really depends on how much xen is similar to normal environment. Unfortunately I have no deep knowledge of xen

Quoted 10 lines

--
Thanks,
Feri.

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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#4 lore raw
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines

Neither have I, but xen-devel says MiniOS is BSD, and should be acceptable for Grub.

If it's under MIT or new BSD license it is. However no code with unclear licensing can be used in grub2

The mini-os code has been reviewed and gained an explicit BSD license just now to clear this issue up.

Quoted 7 lines
Quoted 4 lines

Actually, I wonder if Grub could do any better booting paravirtual
domains: you said Grub already knows how to boot Linux, it's even multiboot compliant, but I'm not sure that really helps much in this situation, where it has to replace a PV image with another.

It really depends on how much xen is similar to normal environment. Unfortunately I have no deep knowledge of xen

Neither have I, but I'm willing to dig up info on this, just provide some explicit questions, please. Anyway, I've got the IRC logs of nyu promising to get Grub going on Xen for me. :) On the other hand, Grub 0.97 has been ported to Xen already, the code is available in the Xen tree under stubdom/grub{.patches}, if you are willing to take a look.

Signature · 2 lines
Regards,
Feri.
#5 lore raw
Quoted 10 lines · Ferenc Wagner
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines

Neither have I, but xen-devel says MiniOS is BSD, and should be acceptable for Grub.

If it's under MIT or new BSD license it is. However no code with unclear licensing can be used in grub2

The mini-os code has been reviewed and gained an explicit BSD license just now to clear this issue up.

Can you post the link? There are different BSD licenses and we need to check that it's really compatible. Even if the license is ok I feel however against making a whole port depending on non-FSF code. If someone agrees to make is from scratch I would prefer it. If noone does then I would be ok with you making this port based on stubdom. However I don't want grub2 to depend on stubdom (this could be discussed). Then all files based on stubdom will have to be separated from the main code and correctly aknowledged where it comes from. We will need a copyright assignment from you. Also we need a permission from Yoshinori K Okuji or Marco Gerards

Quoted 5 lines

Neither have I, but I'm willing to dig up info on this, just provide some explicit questions, please.  Anyway, I've got the IRC logs of nyu promising to get Grub going on Xen for me. :)  On the other hand, Grub 0.97 has been ported to Xen already, the code is available in the Xen tree under stubdom/grub{.patches}, if you are willing to take a look.

They can be used only if they didn't drop "or later" clause of grub1's license and only under same terms as BSD code

Quoted 10 lines

--
Regards,
Feri.

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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#6 lore raw
Quoted 6 lines · Vladimir 'phcoder' Serbinenko
Quoted 5 lines · Ferenc Wagner
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines

Neither have I, but xen-devel says MiniOS is BSD, and should be acceptable for Grub.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If it's under MIT or new BSD license it is. However no code with unclear licensing can be used in grub2

The mini-os code has been reviewed and gained an explicit BSD license just now to clear this issue up.

Can you post the link? There are different BSD licenses and we need to check that it's really compatible.

xen-unstable.hg/extras/minios/COPYING contains the following:

Copyright (c) 2009 Citrix Systems, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Quoted 9 lines

Even if the license is ok I feel however against making a whole port depending on non-FSF code. If someone agrees to make is from scratch I would prefer it. If noone does then I would be ok with you making this port based on stubdom. However I don't want grub2 to depend on stubdom (this could be discussed). Then all files based on stubdom will have to be separated from the main code and correctly aknowledged where it comes from. We will need a copyright assignment from you. Also we need a permission from Yoshinori K Okuji or Marco Gerards

I can't really comment on the above apart from that I've already signed a copyright assignment to FSF.

Quoted 8 lines
Quoted 5 lines

Neither have I, but I'm willing to dig up info on this, just provide some explicit questions, please.  Anyway, I've got the IRC logs of nyu promising to get Grub going on Xen for me. :)  On the other hand, Grub 0.97 has been ported to Xen already, the code is available in the Xen tree under stubdom/grub{.patches}, if you are willing to take a look.

They can be used only if they didn't drop "or later" clause of grub1's license and only under same terms as BSD code.

OMG. Who/what are the two "they"s above? But only if it's really important. This legal stuff is such a drag...

Signature · 2 lines
Thanks,
Feri.
#7 lore raw
Quoted 30 lines · Ferenc Wagner
Quoted 6 lines · Vladimir 'phcoder' Serbinenko
Quoted 5 lines · Ferenc Wagner
Quoted 3 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines

Neither have I, but xen-devel says MiniOS is BSD, and should be acceptable for Grub.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If it's under MIT or new BSD license it is. However no code with unclear licensing can be used in grub2

The mini-os code has been reviewed and gained an explicit BSD license just now to clear this issue up.

Can you post the link? There are different BSD licenses and we need to check that it's really compatible.

xen-unstable.hg/extras/minios/COPYING contains the following:

Copyright (c) 2009 Citrix Systems, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Quoted 12 lines

THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This license is GPLv3 compatible and as such can be linked with grub2. To incorporate to grub2 a non-originl code we would need a maintainer or co-maintainer approval. In any case it won't be merged unless you present something which actually works (e.g. shows menu in xen w/o need of MiniOS). I haven't tested your patch at all because I still haven't familarized myself with xen. I recommend to setup a your own repository under repo.or.czand upload there your WIP.
I also inform you that if someone wants to reimplement it we would prefer a reimplementation

Quoted 7 lines
Quoted 4 lines

They can be used only if they didn't drop "or later" clause of grub1's license and only under same terms as BSD code.

OMG. Who/what are the two "they"s above? But only if it's really important. This legal stuff is such a drag..

The patches released with xen contain no license header. Unless XenSource clearly states that grub patches is under gplv2+ you can't use this code directly or indirectly and shouldn't even look at it. You can take the code from MiniOS though if the license attached to it is the one you posted in your e-mail. Be sure to mark copied parts as such.
It's not my decision if current amount of uncertainty and BSDL code resage is ok, it's not my decision. But even if it isn't added to mainstream it is still a nice feature to have and yo can distribute your code through other channels

Quoted 11 lines

.
--
Thanks,
Feri.

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

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko