From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1UjJXj-0006CX-3H for mharc-grub-devel@gnu.org; Sun, 02 Jun 2013 21:26:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58064) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjJXg-0006C3-33 for grub-devel@gnu.org; Sun, 02 Jun 2013 21:26:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjJXe-0007aY-A6 for grub-devel@gnu.org; Sun, 02 Jun 2013 21:26:36 -0400 Received: from mail-ea0-x233.google.com ([2a00:1450:4013:c01::233]:59228) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjJXe-0007aP-0c for grub-devel@gnu.org; Sun, 02 Jun 2013 21:26:34 -0400 Received: by mail-ea0-f179.google.com with SMTP id z16so3008476ead.10 for ; Sun, 02 Jun 2013 18:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; bh=HvvA/qjyaKJeYoaS2cg2Xp8/WN5L1pBqsyQcSTae6hM=; b=QROZrVci1qYGsci+NBUX2MDGmisKZBAi86D4j1BTTWznIp6tLzBN3DPLg84x93wJH9 0lkRZmsWbeB1VAglQHJCjujZDi/ZICtHTBL0BjFyb9GVYoTd7UUfywf7Q//sopxAPugF kr4D0vl2qGmwViibBZs0C6PZw5wUX7dYWz+sdj0CYJbda8rhsw3ruDjK93YSEAtoHaLP HgqLTbFx733H3Z4l0yxq6csaSgeg8UUqkV7YRbgKWXI/+2vmI9tKL8fAI0m3B7NnfXci a4AA2IDtXL5hWDYs8u9VfqNpGXxpTvTuZg+zD86Qvi9ZtwFDg7I3wbRkZ7q/SBy4Eo9S Snvg== X-Received: by 10.14.7.66 with SMTP id 42mr21409998eeo.130.1370222792732; Sun, 02 Jun 2013 18:26:32 -0700 (PDT) Received: from [192.168.1.113] (31-249.1-85.cust.bluewin.ch. [85.1.249.31]) by mx.google.com with ESMTPSA id a5sm81259762ees.6.2013.06.02.18.26.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 02 Jun 2013 18:26:31 -0700 (PDT) Message-ID: <51ABF0BF.6050508@gmail.com> Date: Mon, 03 Jun 2013 03:26:23 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130518 Icedove/17.0.5 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: Re: [RFC] Dedicated LVM volume as alternative to embedding References: In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="----enig2ENBRMAKJCPATOCFDAWSH" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::233 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Jun 2013 01:26:37 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2ENBRMAKJCPATOCFDAWSH Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable This solution wouldn't play well with LVM layers. A better solution is being jointly developped with lvm guys. On 03.06.2013 02:58, Piotras wrote: > Hi, >=20 > Attached patch allows for using alternative disk area when usual embedd= ing > is not possible. It helps for case where LVM is used on boot disk and u= ser > can create new volume for exclusive use by GRUB. >=20 > I currently require for the volume to use contiguous sectors on single = disk > (boot disk). Name of the volume is passed with additional parameter for= > grub-setup: >> grub-bios-setup --dedicated-loader-volume=3Dlvm/myVG-myLoaderLV --skip= -fs-probe ... /dev/sda > Parameter "--skip-fs-probe" is required for current version of the patc= h. >=20 > The implementation is inspired by existing function grub_util_ldm_embed= in > grub-core/disk/ldm.c (notice that this function is not working in curre= nt > form). >=20 > It should be possible to generalize my patch to cover both LVM and LDM = with > common function, but I didn't test it. It may also be extend for using = with > traditional partition tables (where use can create new partition for > exclusing use by GRUB). >=20 > I'd like to check if this feature can be added to official GRUB and wha= t > changes would be required for the attached patch to be merged. >=20 >=20 > Best regards, >=20 > Piotr Krysiuk >=20 >=20 > --- > grub-core/disk/lvm.c | 75 +++++++++++++++++++++++++++++++++++= +++++++- > include/grub/emu/hostdisk.h | 7 ++++ > util/grub-setup.c | 24 +++++++++++--- > 3 files changed, 100 insertions(+), 6 deletions(-) >=20 > diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c > index 508e94a..8b7ff44 100644 > --- a/grub-core/disk/lvm.c > +++ b/grub-core/disk/lvm.c > @@ -746,7 +746,80 @@ grub_lvm_detect (grub_disk_t disk, > return NULL; > } >=20 > - > +#ifdef GRUB_UTIL > + > +grub_err_t > +grub_util_lvm_embed (struct grub_disk *disk, > + const char *loader_lv_name, > + unsigned int *nsectors, > + unsigned int max_nsectors, > + grub_embed_type_t embed_type, > + grub_disk_addr_t **sectors) > +{ > + grub_disk_t loader_disk; > + struct grub_diskfilter_lv *loader_lv; > + unsigned i; > + > + if (embed_type !=3D GRUB_EMBED_PCBIOS) > + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, > + "LVM curently supports only PC-BIOS embedding")= ; > + > + loader_disk =3D grub_disk_open (loader_lv_name); > + if (! loader_disk) > + grub_util_error ("%s", grub_errmsg); > + > + if (loader_disk->dev->id !=3D GRUB_DISK_DEVICE_DISKFILTER_ID) > + goto unable_to_embed; > + > + loader_lv =3D loader_disk->data; > + > + if (loader_lv->size > (1U << 15)) > + return grub_error (GRUB_ERR_OUT_OF_RANGE, > + N_("your dedicated loader volume is larger > then 16MBytes;" > + " grub won't use it to prevent > unintentional corruption" > + " of user data")); > + > + if (!loader_lv->visible || !loader_lv->fullname) > + goto unable_to_embed; > + > + if (loader_lv->segment_count !=3D 1) > + goto unable_to_embed; > + > + if (loader_lv->segments->type !=3D GRUB_DISKFILTER_STRIPED > + || loader_lv->segments->node_count !=3D 1 > + || loader_lv->segments->start_extent !=3D 0) > + goto unable_to_embed; > + > + if (disk->partition > + || grub_strcmp (loader_lv->segments->nodes->pv->disk->name, disk= ->name)) > + goto unable_to_embed; > + > + if (loader_lv->size < *nsectors) > + return grub_error (GRUB_ERR_OUT_OF_RANGE, > + N_("your dedicated loader volume is too small;"= > + " grub can't use it")); > + *nsectors =3D loader_lv->size; > + if (*nsectors > max_nsectors) > + *nsectors =3D max_nsectors; > + *sectors =3D grub_malloc (*nsectors * sizeof (**sectors)); > + if (!*sectors) > + return grub_errno; > + for (i =3D 0; i < *nsectors; i++) > + (*sectors)[i] =3D (loader_lv->segments->nodes->start > + + loader_lv->segments->nodes->pv->start_sector > + + i); > + > + grub_disk_close (loader_disk); > + return GRUB_ERR_NONE; > + > + unable_to_embed: > + > + return grub_error (GRUB_ERR_FILE_NOT_FOUND, > + N_("your dedicated loader volume is invalid;" > + " grub can't use it")); > +} > + > +#endif >=20 > static struct grub_diskfilter grub_lvm_dev =3D { > .name =3D "lvm", > diff --git a/include/grub/emu/hostdisk.h b/include/grub/emu/hostdisk.h > index 058973b..af59b9e 100644 > --- a/include/grub/emu/hostdisk.h > +++ b/include/grub/emu/hostdisk.h > @@ -51,6 +51,13 @@ grub_util_ldm_embed (struct grub_disk *disk, > unsigned int *nsectors, > unsigned int max_nsectors, > grub_embed_type_t embed_type, > grub_disk_addr_t **sectors); > +grub_err_t > +grub_util_lvm_embed (struct grub_disk *disk, > + const char *loader_lv_name, > + unsigned int *nsectors, > + unsigned int max_nsectors, > + grub_embed_type_t embed_type, > + grub_disk_addr_t **sectors); > #endif > grub_disk_addr_t > grub_hostdisk_find_partition_start (const char *dev); > diff --git a/util/grub-setup.c b/util/grub-setup.c > index 27a815f..b95d05b 100644 > --- a/util/grub-setup.c > +++ b/util/grub-setup.c > @@ -85,6 +85,7 @@ >=20 > #define DEFAULT_BOOT_FILE "boot.img" > #define DEFAULT_CORE_FILE "core.img" > +#define OPT_LOADER_VOLUME -3 >=20 > #ifdef GRUB_SETUP_SPARC64 > #define grub_target_to_host16(x) grub_be_to_cpu16(x) > @@ -243,7 +244,7 @@ identify_partmap (grub_disk_t disk __attribute__ ((= unused)), > static void > setup (const char *dir, > const char *boot_file, const char *core_file, > - const char *dest, int force, > + const char *dest, const char *loader_volume, int force, > int fs_probe, int allow_floppy) > { > char *boot_path, *core_path, *core_path_dev, *core_path_dev_full; > @@ -459,12 +460,12 @@ setup (const char *dir, >=20 > free (tmp_img); >=20 > - if (! ctx.dest_partmap && ! fs && !is_ldm) > + if (! ctx.dest_partmap && ! fs && !is_ldm && !loader_volume) > { > grub_util_warn ("%s", _("Attempting to install GRUB to a > partitionless disk or to a partition. This is a BAD idea.")); > goto unable_to_embed; > } > - if (ctx.multiple_partmaps || (ctx.dest_partmap && fs) || (is_ldm &= & fs)) > + if (ctx.multiple_partmaps || (ctx.dest_partmap && fs) || (is_ldm > && fs) || (loader_volume && fs)) > { > grub_util_warn ("%s", _("Attempting to install GRUB to a disk with > multiple partition labels. This is not supported yet.")); > goto unable_to_embed; > @@ -492,7 +493,10 @@ setup (const char *dir, > maxsec =3D ((0x78000 - GRUB_KERNEL_I386_PC_LINK_ADDR) > >> GRUB_DISK_SECTOR_BITS); >=20 > - if (is_ldm) > + if (loader_volume) > + err =3D grub_util_lvm_embed (dest_dev->disk, loader_volume, &nse= c, maxsec, > + GRUB_EMBED_PCBIOS, §ors); > + else if (is_ldm) > err =3D grub_util_ldm_embed (dest_dev->disk, &nsec, maxsec, > GRUB_EMBED_PCBIOS, §ors); > else if (ctx.dest_partmap) > @@ -983,6 +987,8 @@ static struct argp_option options[] =3D { > N_("use GRUB files in the directory DIR [default=3D%s]"), 0}, > {"device-map", 'm', N_("FILE"), 0, > N_("use FILE as the device map [default=3D%s]"), 0}, > + {"dedicated-loader-volume", OPT_LOADER_VOLUME, N_("VOLUME"), 0, > + N_("allocate VOLUME for exclusive use by GRUB. Existing data on > VOLUME will be overwritten!"), 0}, > {"force", 'f', 0, 0, > N_("install even if problems are detected"), 0}, > {"skip-fs-probe",'s',0, 0, > @@ -1024,6 +1030,7 @@ struct arguments > char *core_file; > char *dir; > char *dev_map; > + char *loader_volume; > int force; > int fs_probe; > int allow_floppy; > @@ -1071,6 +1078,13 @@ argp_parser (int key, char *arg, struct > argp_state *state) > arguments->dev_map =3D xstrdup (arg); > break; >=20 > + case OPT_LOADER_VOLUME: > + if (arguments->loader_volume) > + free (arguments->loader_volume); > + > + arguments->loader_volume =3D xstrdup (arg); > + break; > + > case 'f': > arguments->force =3D 1; > break; > @@ -1203,7 +1217,7 @@ main (int argc, char *argv[]) > setup (arguments.dir ? : DEFAULT_DIRECTORY, > arguments.boot_file ? : DEFAULT_BOOT_FILE, > arguments.core_file ? : DEFAULT_CORE_FILE, > - dest_dev, arguments.force, > + dest_dev, arguments.loader_volume, arguments.force, > arguments.fs_probe, arguments.allow_floppy); >=20 > /* Free resources. */ > -- > 1.7.9.5 >=20 > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel >=20 ------enig2ENBRMAKJCPATOCFDAWSH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iF4EAREKAAYFAlGr8MYACgkQNak7dOguQglb+AEAoPzcpen66M1AlieX+P+bzn3z rON6acEQXs+Q+S2x9xAA/j2jRrK0TVaeY1sYFmqh7Vtbk+zBOuUvtLQ6sStuug2T =g0Fu -----END PGP SIGNATURE----- ------enig2ENBRMAKJCPATOCFDAWSH--