| 1 | This patch is taken from OpenWrt, see:
|
| 2 |
|
| 3 | https://github.com/openwrt/openwrt/blob/master/package/boot/grub2/patches/100-grub_setup_root.patch
|
| 4 |
|
| 5 | nckx changed `char *root' to lazily pacify -Werror=discarded-qualifiers.
|
| 6 |
|
| 7 | It allows to use grub-bios-setup on a raw disk-images, without root permissions.
|
| 8 |
|
| 9 | |
| 10 | |
| 11 | @@ -198,13 +198,13 @@ grub_install_get_image_target (const char *arg);
|
| 12 | void
|
| 13 | grub_util_bios_setup (const char *dir,
|
| 14 | const char *boot_file, const char *core_file,
|
| 15 | - const char *dest, int force,
|
| 16 | + char *root, const char *dest, int force,
|
| 17 | int fs_probe, int allow_floppy,
|
| 18 | int add_rs_codes, int warn_short_mbr_gap);
|
| 19 | void
|
| 20 | grub_util_sparc_setup (const char *dir,
|
| 21 | const char *boot_file, const char *core_file,
|
| 22 | - const char *dest, int force,
|
| 23 | + char *root, const char *dest, int force,
|
| 24 | int fs_probe, int allow_floppy,
|
| 25 | int add_rs_codes, int warn_short_mbr_gap);
|
| 26 |
|
| 27 | diff --git a/util/grub-install.c b/util/grub-install.c
|
| 28 | index 0fbe7f78c..7f06aa1e3 100644
|
| 29 | |
| 30 | |
| 31 | @@ -1721,7 +1721,7 @@ main (int argc, char *argv[])
|
| 32 | if (install_bootsector)
|
| 33 | {
|
| 34 | grub_util_bios_setup (platdir, "boot.img", "core.img",
|
| 35 | - install_drive, force,
|
| 36 | + NULL, install_drive, force,
|
| 37 | fs_probe, allow_floppy, add_rs_codes,
|
| 38 | !grub_install_is_short_mbrgap_supported ());
|
| 39 |
|
| 40 | @@ -1752,7 +1752,7 @@ main (int argc, char *argv[])
|
| 41 | if (install_bootsector)
|
| 42 | {
|
| 43 | grub_util_sparc_setup (platdir, "boot.img", "core.img",
|
| 44 | - install_drive, force,
|
| 45 | + NULL, install_drive, force,
|
| 46 | fs_probe, allow_floppy,
|
| 47 | 0 /* unused */, 0 /* unused */ );
|
| 48 |
|
| 49 | diff --git a/util/grub-setup.c b/util/grub-setup.c
|
| 50 | index 1783224dd..48cde4950 100644
|
| 51 | |
| 52 | |
| 53 | @@ -87,6 +87,8 @@ static struct argp_option options[] = {
|
| 54 | N_("install even if problems are detected"), 0},
|
| 55 | {"skip-fs-probe",'s',0, 0,
|
| 56 | N_("do not probe for filesystems in DEVICE"), 0},
|
| 57 | + {"root-device", 'r', N_("DEVICE"), 0,
|
| 58 | + N_("use DEVICE as the root device"), 0},
|
| 59 | {"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
|
| 60 | {"allow-floppy", 'a', 0, 0,
|
| 61 | /* TRANSLATORS: The potential breakage isn't limited to floppies but it's
|
| 62 | @@ -130,6 +132,7 @@ struct arguments
|
| 63 | char *core_file;
|
| 64 | char *dir;
|
| 65 | char *dev_map;
|
| 66 | + char *root_dev;
|
| 67 | int force;
|
| 68 | int fs_probe;
|
| 69 | int allow_floppy;
|
| 70 | @@ -178,6 +181,13 @@ argp_parser (int key, char *arg, struct argp_state *state)
|
| 71 | arguments->dev_map = xstrdup (arg);
|
| 72 | break;
|
| 73 |
|
| 74 | + case 'r':
|
| 75 | + if (arguments->root_dev)
|
| 76 | + free (arguments->root_dev);
|
| 77 | +
|
| 78 | + arguments->root_dev = xstrdup (arg);
|
| 79 | + break;
|
| 80 | +
|
| 81 | case 'f':
|
| 82 | arguments->force = 1;
|
| 83 | break;
|
| 84 | @@ -313,7 +323,7 @@ main (int argc, char *argv[])
|
| 85 | GRUB_SETUP_FUNC (arguments.dir ? : DEFAULT_DIRECTORY,
|
| 86 | arguments.boot_file ? : DEFAULT_BOOT_FILE,
|
| 87 | arguments.core_file ? : DEFAULT_CORE_FILE,
|
| 88 | - dest_dev, arguments.force,
|
| 89 | + arguments.root_dev, dest_dev, arguments.force,
|
| 90 | arguments.fs_probe, arguments.allow_floppy,
|
| 91 | arguments.add_rs_codes, 0);
|
| 92 |
|
| 93 | diff --git a/util/setup.c b/util/setup.c
|
| 94 | index da5f2c07f..193745a9c 100644
|
| 95 | |
| 96 | |
| 97 | @@ -252,14 +252,13 @@ identify_partmap (grub_disk_t disk __attribute__ ((unused)),
|
| 98 | void
|
| 99 | SETUP (const char *dir,
|
| 100 | const char *boot_file, const char *core_file,
|
| 101 | - const char *dest, int force,
|
| 102 | + char *root, const char *dest, int force,
|
| 103 | int fs_probe, int allow_floppy,
|
| 104 | int add_rs_codes __attribute__ ((unused)), /* unused on sparc64 */
|
| 105 | int warn_small)
|
| 106 | {
|
| 107 | char *core_path;
|
| 108 | char *boot_img, *core_img, *boot_path;
|
| 109 | - char *root = 0;
|
| 110 | size_t boot_size, core_size;
|
| 111 | grub_uint16_t core_sectors;
|
| 112 | grub_device_t root_dev = 0, dest_dev, core_dev;
|
| 113 | @@ -311,7 +310,10 @@ SETUP (const char *dir,
|
| 114 |
|
| 115 | core_dev = dest_dev;
|
| 116 |
|
| 117 | - {
|
| 118 | + if (root)
|
| 119 | + root_dev = grub_device_open(root);
|
| 120 | +
|
| 121 | + if (!root_dev) {
|
| 122 | char **root_devices = grub_guess_root_devices (dir);
|
| 123 | char **cur;
|
| 124 | int found = 0;
|
| 125 | @@ -324,6 +326,8 @@ SETUP (const char *dir,
|
| 126 | char *drive;
|
| 127 | grub_device_t try_dev;
|
| 128 |
|
| 129 | + if (root_dev)
|
| 130 | + break;
|
| 131 | drive = grub_util_get_grub_dev (*cur);
|
| 132 | if (!drive)
|
| 133 | continue;
|