2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
5
* GRUB is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* GRUB is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20
#include <grub/types.h>
21
#include <grub/emu/misc.h>
22
#include <grub/util/misc.h>
23
#include <grub/misc.h>
24
#include <grub/device.h>
25
#include <grub/disk.h>
26
#include <grub/file.h>
29
#include <grub/term.h>
31
#include <grub/lib/hexdump.h>
32
#include <grub/crypto.h>
33
#include <grub/command.h>
34
#include <grub/i18n.h>
35
#include <grub/zfs/zfs.h>
36
#include <grub/util/install.h>
37
#include <grub/emu/getroot.h>
38
#include <grub/diskfilter.h>
39
#include <grub/cryptodisk.h>
40
#include <grub/legacy_parse.h>
41
#include <grub/gpt_partition.h>
42
#include <grub/emu/config.h>
43
#include <grub/util/ofpath.h>
44
#include <grub/hfsplus.h>
45
#include <grub/emu/hostfile.h>
49
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
50
#pragma GCC diagnostic ignored "-Wmissing-declarations"
52
#pragma GCC diagnostic error "-Wmissing-prototypes"
53
#pragma GCC diagnostic error "-Wmissing-declarations"
58
static int removable = 0;
59
static int recheck = 0;
60
static int update_nvram = 1;
61
static char *install_device = NULL;
62
static char *debug_image = NULL;
63
static char *rootdir = NULL;
64
static char *bootdir = NULL;
65
static int allow_floppy = 0;
66
static int force_file_id = 0;
67
static char *disk_module = NULL;
68
static char *efidir = NULL;
69
static char *macppcdir = NULL;
71
static int have_abstractions = 0;
72
static int have_cryptodisk = 0;
73
static char * bootloader_id;
74
static int have_load_cfg = 0;
75
static FILE * load_cfg_f = NULL;
76
static char *load_cfg;
77
static int install_bootsector = 1;
78
static char *label_font;
79
static char *label_color;
80
static char *label_bgcolor;
81
static char *product_version;
82
static int add_rs_codes = 1;
83
static int uefi_secure_boot = 1;
87
OPTION_BOOT_DIRECTORY = 0x301,
88
OPTION_ROOT_DIRECTORY,
102
OPTION_BOOTLOADER_ID,
103
OPTION_EFI_DIRECTORY,
109
OPTION_NO_BOOTSECTOR,
111
OPTION_MACPPC_DIRECTORY,
114
OPTION_LABEL_BGCOLOR,
115
OPTION_PRODUCT_VERSION,
116
OPTION_UEFI_SECURE_BOOT,
117
OPTION_NO_UEFI_SECURE_BOOT
120
static int fs_probe = 1;
123
argp_parser (int key, char *arg, struct argp_state *state)
125
if (grub_install_parse (key, arg))
129
case OPTION_FORCE_FILE_ID:
137
if (!grub_strstr (arg, "setup"))
138
install_bootsector = 0;
141
case OPTION_PRODUCT_VERSION:
142
free (product_version);
143
product_version = xstrdup (arg);
145
case OPTION_LABEL_FONT:
147
label_font = xstrdup (arg);
150
case OPTION_LABEL_COLOR:
152
label_color = xstrdup (arg);
155
case OPTION_LABEL_BGCOLOR:
156
free (label_bgcolor);
157
label_bgcolor = xstrdup (arg);
160
/* Accept and ignore for compatibility. */
162
case OPTION_MKRELPATH:
165
case OPTION_MKDEVICEMAP:
166
case OPTION_NO_FLOPPY:
168
case OPTION_ROOT_DIRECTORY:
169
/* Accept for compatibility. */
171
rootdir = xstrdup (arg);
174
case OPTION_BOOT_DIRECTORY:
176
bootdir = xstrdup (arg);
179
case OPTION_MACPPC_DIRECTORY:
181
macppcdir = xstrdup (arg);
184
case OPTION_EFI_DIRECTORY:
186
efidir = xstrdup (arg);
189
case OPTION_DISK_MODULE:
191
disk_module = xstrdup (arg);
196
target = xstrdup (arg);
199
case OPTION_DEBUG_IMAGE:
201
debug_image = xstrdup (arg);
204
case OPTION_NO_NVRAM:
216
case OPTION_REMOVABLE:
220
case OPTION_ALLOW_FLOPPY:
224
case OPTION_NO_BOOTSECTOR:
225
install_bootsector = 0;
228
case OPTION_NO_RS_CODES:
236
case OPTION_BOOTLOADER_ID:
237
free (bootloader_id);
238
bootloader_id = xstrdup (arg);
241
case OPTION_UEFI_SECURE_BOOT:
242
uefi_secure_boot = 1;
245
case OPTION_NO_UEFI_SECURE_BOOT:
246
uefi_secure_boot = 0;
251
grub_util_error ("%s", _("More than one install device?"));
252
install_device = xstrdup (arg);
256
return ARGP_ERR_UNKNOWN;
261
static struct argp_option options[] = {
262
GRUB_INSTALL_OPTIONS,
263
{"boot-directory", OPTION_BOOT_DIRECTORY, N_("DIR"),
264
0, N_("install GRUB images under the directory DIR/%s instead of the %s directory"), 2},
265
{"root-directory", OPTION_ROOT_DIRECTORY, N_("DIR"),
266
OPTION_HIDDEN, 0, 2},
267
{"font", OPTION_FONT, N_("FILE"),
268
OPTION_HIDDEN, 0, 2},
269
{"target", OPTION_TARGET, N_("TARGET"),
270
/* TRANSLATORS: "TARGET" as in "target platform". */
271
0, N_("install GRUB for TARGET platform [default=%s]"), 2},
272
{"grub-setup", OPTION_SETUP, "FILE", OPTION_HIDDEN, 0, 2},
273
{"grub-mkrelpath", OPTION_MKRELPATH, "FILE", OPTION_HIDDEN, 0, 2},
274
{"grub-mkdevicemap", OPTION_MKDEVICEMAP, "FILE", OPTION_HIDDEN, 0, 2},
275
{"grub-probe", OPTION_PROBE, "FILE", OPTION_HIDDEN, 0, 2},
276
{"grub-editenv", OPTION_EDITENV, "FILE", OPTION_HIDDEN, 0, 2},
277
{"allow-floppy", OPTION_ALLOW_FLOPPY, 0, 0,
278
/* TRANSLATORS: "may break" doesn't just mean that option wouldn't have any
279
effect but that it will make the resulting install unbootable from HDD. */
280
N_("make the drive also bootable as floppy (default for fdX devices)."
281
" May break on some BIOSes."), 2},
282
{"recheck", OPTION_RECHECK, 0, 0,
283
N_("delete device map if it already exists"), 2},
284
{"force", OPTION_FORCE, 0, 0,
285
N_("install even if problems are detected"), 2},
286
{"force-file-id", OPTION_FORCE_FILE_ID, 0, 0,
287
N_("use identifier file even if UUID is available"), 2},
288
{"disk-module", OPTION_MODULE, N_("MODULE"), 0,
289
N_("disk module to use (biosdisk or native). "
290
"This option is only available on BIOS target."), 2},
291
{"no-nvram", OPTION_NO_NVRAM, 0, 0,
292
N_("don't update the `boot-device'/`Boot*' NVRAM variables. "
293
"This option is only available on EFI and IEEE1275 targets."), 2},
294
{"skip-fs-probe",'s',0, 0,
295
N_("do not probe for filesystems in DEVICE"), 0},
296
{"no-bootsector", OPTION_NO_BOOTSECTOR, 0, 0,
297
N_("do not install bootsector"), 0},
298
{"no-rs-codes", OPTION_NO_RS_CODES, 0, 0,
299
N_("Do not apply any reed-solomon codes when embedding core.img. "
300
"This option is only available on x86 BIOS targets."), 0},
302
{"debug", OPTION_DEBUG, 0, OPTION_HIDDEN, 0, 2},
303
{"no-floppy", OPTION_NO_FLOPPY, 0, OPTION_HIDDEN, 0, 2},
304
{"debug-image", OPTION_DEBUG_IMAGE, N_("STRING"), OPTION_HIDDEN, 0, 2},
305
{"removable", OPTION_REMOVABLE, 0, 0,
306
N_("the installation device is removable. "
307
"This option is only available on EFI."), 2},
308
{"bootloader-id", OPTION_BOOTLOADER_ID, N_("ID"), 0,
309
N_("the ID of bootloader. This option is only available on EFI and Macs."), 2},
310
{"efi-directory", OPTION_EFI_DIRECTORY, N_("DIR"), 0,
311
N_("use DIR as the EFI System Partition root."), 2},
312
{"macppc-directory", OPTION_MACPPC_DIRECTORY, N_("DIR"), 0,
313
N_("use DIR for PPC MAC install."), 2},
314
{"label-font", OPTION_LABEL_FONT, N_("FILE"), 0, N_("use FILE as font for label"), 2},
315
{"label-color", OPTION_LABEL_COLOR, N_("COLOR"), 0, N_("use COLOR for label"), 2},
316
{"label-bgcolor", OPTION_LABEL_BGCOLOR, N_("COLOR"), 0, N_("use COLOR for label background"), 2},
317
{"product-version", OPTION_PRODUCT_VERSION, N_("STRING"), 0, N_("use STRING as product version"), 2},
318
{"uefi-secure-boot", OPTION_UEFI_SECURE_BOOT, 0, 0,
319
N_("install an image usable with UEFI Secure Boot. "
320
"This option is only available on EFI and if the grub-efi-amd64-signed "
321
"package is installed."), 2},
322
{"no-uefi-secure-boot", OPTION_NO_UEFI_SECURE_BOOT, 0, 0,
323
N_("do not install an image usable with UEFI Secure Boot, even if the "
324
"system was currently started using it. "
325
"This option is only available on EFI."), 2},
330
get_default_platform (void)
333
return "powerpc-ieee1275";
334
#elif defined (__sparc__) || defined (__sparc64__)
335
return "sparc64-ieee1275";
336
#elif defined (__MIPSEL__)
337
return "mipsel-loongson";
338
#elif defined (__MIPSEB__)
340
#elif defined (__ia64__)
342
#elif defined (__arm__)
344
#elif defined (__aarch64__)
346
#elif defined (__amd64__) || defined (__x86_64__) || defined (__i386__)
347
return grub_install_get_default_x86_platform ();
353
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
356
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
360
case OPTION_BOOT_DIRECTORY:
361
return xasprintf (text, GRUB_DIR_NAME, GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME);
363
return xasprintf (text, get_default_platform ());
364
case ARGP_KEY_HELP_POST_DOC:
365
return xasprintf (text, program_name, GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME);
367
return grub_install_help_filter (key, text, input);
371
#pragma GCC diagnostic error "-Wformat-nonliteral"
373
/* TRANSLATORS: INSTALL_DEVICE isn't an identifier and is the DEVICE you
376
options, argp_parser, N_("[OPTION] [INSTALL_DEVICE]"),
377
N_("Install GRUB on your drive.")"\v"
378
N_("INSTALL_DEVICE must be system device filename.\n"
379
"%s copies GRUB images into %s. On some platforms, it"
380
" may also install GRUB into the boot sector."),
381
NULL, help_filter, NULL
385
probe_raid_level (grub_disk_t disk)
387
/* disk might be NULL in the case of a LVM physical volume with no LVM
388
signature. Ignore such cases here. */
392
if (disk->dev->id != GRUB_DISK_DEVICE_DISKFILTER_ID)
395
if (disk->name[0] != 'm' || disk->name[1] != 'd')
398
if (!((struct grub_diskfilter_lv *) disk->data)->segments)
400
return ((struct grub_diskfilter_lv *) disk->data)->segments->type;
404
push_partmap_module (const char *map, void *data __attribute__ ((unused)))
408
if (strcmp (map, "openbsd") == 0 || strcmp (map, "netbsd") == 0)
410
grub_install_push_module ("part_bsd");
414
snprintf (buf, sizeof (buf), "part_%s", map);
415
grub_install_push_module (buf);
419
push_cryptodisk_module (const char *mod, void *data __attribute__ ((unused)))
421
grub_install_push_module (mod);
425
probe_mods (grub_disk_t disk)
427
grub_partition_t part;
428
grub_disk_memberlist_t list = NULL, tmp;
431
if (disk->partition == NULL)
432
grub_util_info ("no partition map found for %s", disk->name);
434
for (part = disk->partition; part; part = part->parent)
435
push_partmap_module (part->partmap->name, NULL);
437
if (disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID)
439
grub_diskfilter_get_partmap (disk, push_partmap_module, NULL);
440
have_abstractions = 1;
443
if (disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID
444
&& (grub_memcmp (disk->name, "lvm/", sizeof ("lvm/") - 1) == 0 ||
445
grub_memcmp (disk->name, "lvmid/", sizeof ("lvmid/") - 1) == 0))
446
grub_install_push_module ("lvm");
448
if (disk->dev->id == GRUB_DISK_DEVICE_DISKFILTER_ID
449
&& grub_memcmp (disk->name, "ldm/", sizeof ("ldm/") - 1) == 0)
450
grub_install_push_module ("ldm");
452
if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID)
454
grub_util_cryptodisk_get_abstraction (disk,
455
push_cryptodisk_module, NULL);
456
have_abstractions = 1;
460
raid_level = probe_raid_level (disk);
463
grub_install_push_module ("diskfilter");
464
if (disk->dev->raidname)
465
grub_install_push_module (disk->dev->raidname (disk));
468
grub_install_push_module ("raid5rec");
470
grub_install_push_module ("raid6rec");
472
/* In case of LVM/RAID, check the member devices as well. */
473
if (disk->dev->memberlist)
474
list = disk->dev->memberlist (disk);
477
probe_mods (list->disk);
485
have_bootdev (enum grub_install_plat pl)
489
case GRUB_INSTALL_PLATFORM_I386_PC:
490
case GRUB_INSTALL_PLATFORM_I386_EFI:
491
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
492
case GRUB_INSTALL_PLATFORM_IA64_EFI:
493
case GRUB_INSTALL_PLATFORM_ARM_EFI:
494
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
495
case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
496
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
497
case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
498
case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
499
case GRUB_INSTALL_PLATFORM_MIPS_ARC:
502
case GRUB_INSTALL_PLATFORM_I386_QEMU:
503
case GRUB_INSTALL_PLATFORM_I386_COREBOOT:
504
case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
505
case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
506
case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
508
case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON:
509
case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
511
case GRUB_INSTALL_PLATFORM_I386_XEN:
512
case GRUB_INSTALL_PLATFORM_X86_64_XEN:
515
/* pacify warning. */
516
case GRUB_INSTALL_PLATFORM_MAX:
523
probe_cryptodisk_uuid (grub_disk_t disk)
525
grub_disk_memberlist_t list = NULL, tmp;
527
/* In case of LVM/RAID, check the member devices as well. */
528
if (disk->dev->memberlist)
530
list = disk->dev->memberlist (disk);
534
probe_cryptodisk_uuid (list->disk);
539
if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID)
541
const char *uuid = grub_util_cryptodisk_get_uuid (disk);
543
load_cfg_f = grub_util_fopen (load_cfg, "wb");
546
fprintf (load_cfg_f, "cryptomount -u %s\n",
552
is_same_disk (const char *a, const char *b)
556
if ((*a == ',' || *a == '\0') && (*b == ',' || *b == '\0'))
576
grub_uint8_t rnd[15];
577
const size_t sz = sizeof (rnd) * GRUB_CHAR_BIT / 5;
578
char * ret = xmalloc (sz + 1);
580
if (grub_get_random (rnd, sizeof (rnd)))
581
grub_util_error ("%s", _("couldn't retrieve random data"));
582
for (i = 0; i < sz; i++)
584
grub_size_t b = i * 5;
586
grub_size_t f1 = GRUB_CHAR_BIT - b % GRUB_CHAR_BIT;
591
r = (rnd[b / GRUB_CHAR_BIT] >> (b % GRUB_CHAR_BIT)) & ((1 << f1) - 1);
593
r |= (rnd[b / GRUB_CHAR_BIT + 1] & ((1 << f2) - 1)) << f1;
597
ret[i] = 'a' + (r - 10);
604
escape (const char *in)
610
for (ptr = (char*)in; *ptr; ptr++)
613
ret = grub_malloc (ptr - in + overhead + 1);
617
grub_strchrsub (ret, in, '\'', "'\\''");
621
static struct grub_util_config config;
624
device_map_check_duplicates (const char *dev_map)
627
char buf[1024]; /* XXX */
633
d = xmalloc (alloced * sizeof (d[0]));
635
if (dev_map[0] == '\0')
638
fp = grub_util_fopen (dev_map, "r");
642
while (fgets (buf, sizeof (buf), fp))
647
/* Skip leading spaces. */
648
while (*p && grub_isspace (*p))
651
/* If the first character is `#' or NUL, skip this line. */
652
if (*p == '\0' || *p == '#')
665
if (filled >= alloced)
668
d = xrealloc (d, alloced * sizeof (d[0]));
673
d[filled++] = xstrdup (e);
678
qsort (d, filled, sizeof (d[0]), grub_qsort_strcmp);
680
for (i = 0; i + 1 < filled; i++)
681
if (strcmp (d[i], d[i+1]) == 0)
683
grub_util_error (_("the drive %s is defined multiple times in the device map %s"),
687
for (i = 0; i < filled; i++)
694
write_to_disk (grub_device_t dev, const char *fn)
700
core_size = grub_util_get_image_size (fn);
702
core_img = grub_util_read_image (fn);
704
err = grub_disk_write (dev->disk, 0, 0,
705
core_size, core_img);
711
is_prep_partition (grub_device_t dev)
715
if (!dev->disk->partition)
717
if (strcmp(dev->disk->partition->partmap->name, "msdos") == 0)
718
return (dev->disk->partition->msdostype == 0x41);
720
if (strcmp (dev->disk->partition->partmap->name, "gpt") == 0)
722
struct grub_gpt_partentry gptdata;
723
grub_partition_t p = dev->disk->partition;
725
dev->disk->partition = dev->disk->partition->parent;
727
if (grub_disk_read (dev->disk, p->offset, p->index,
728
sizeof (gptdata), &gptdata) == 0)
730
const grub_gpt_part_type_t template = {
731
grub_cpu_to_le32_compile_time (0x9e1a2d38),
732
grub_cpu_to_le16_compile_time (0xc612),
733
grub_cpu_to_le16_compile_time (0x4316),
734
{ 0xaa, 0x26, 0x8b, 0x49, 0x52, 0x1e, 0x5a, 0x8b }
737
ret = grub_memcmp (&template, &gptdata.type,
738
sizeof (template)) == 0;
740
dev->disk->partition = p;
748
is_prep_empty (grub_device_t dev)
750
grub_disk_addr_t dsize, addr;
751
grub_uint32_t buffer[32768];
753
dsize = grub_disk_get_size (dev->disk);
754
for (addr = 0; addr < dsize;
755
addr += sizeof (buffer) / GRUB_DISK_SECTOR_SIZE)
757
grub_size_t sz = sizeof (buffer);
760
if (sizeof (buffer) / GRUB_DISK_SECTOR_SIZE > dsize - addr)
761
sz = (dsize - addr) * GRUB_DISK_SECTOR_SIZE;
762
grub_disk_read (dev->disk, addr, 0, sz, buffer);
764
if (addr == 0 && grub_memcmp (buffer, ELFMAG, SELFMAG) == 0)
767
for (ptr = buffer; ptr < buffer + sz / sizeof (*buffer); ptr++)
776
bless (grub_device_t dev, const char *path, int x86)
781
grub_util_info ("blessing %s", path);
783
if (stat (path, &st) < 0)
784
grub_util_error (N_("cannot stat `%s': %s"),
785
path, strerror (errno));
787
err = grub_mac_bless_inode (dev, st.st_ino, S_ISDIR (st.st_mode), x86);
789
grub_util_error ("%s", grub_errmsg);
790
grub_util_info ("blessed\n");
794
fill_core_services (const char *core_services)
799
char *label_string = xasprintf ("%s %s", bootloader_id, product_version);
802
label = grub_util_path_concat (2, core_services, ".disk_label");
803
grub_util_info ("rendering label %s", label_string);
804
grub_util_render_label (label_font, label_bgcolor ? : "white",
805
label_color ? : "black", label_string, label);
806
grub_util_info ("label rendered");
808
label_text = grub_util_path_concat (2, core_services, ".disk_label.contentDetails");
809
f = grub_util_fopen (label_text, "wb");
810
fprintf (f, "%s\n", label_string);
815
sysv_plist = grub_util_path_concat (2, core_services, "SystemVersion.plist");
816
f = grub_util_fopen (sysv_plist, "wb");
818
"<plist version=\"1.0\">\n"
820
" <key>ProductBuildVersion</key>\n"
821
" <string></string>\n"
822
" <key>ProductName</key>\n"
823
" <string>%s</string>\n"
824
" <key>ProductVersion</key>\n"
825
" <string>%s</string>\n"
827
"</plist>\n", bootloader_id, product_version);
833
main (int argc, char *argv[])
836
const char *efi_distributor = NULL;
837
const char *efi_suffix = NULL, *efi_suffix_upper = NULL;
838
char *efi_file = NULL;
841
grub_device_t grub_dev = NULL;
842
enum grub_install_plat platform;
843
char *grubdir, *device_map;
844
char **curdev, **curdrive;
846
char *relative_grubdir;
847
char **efidir_device_names = NULL;
848
grub_device_t efidir_grub_dev = NULL;
849
char *efidir_grub_devname;
850
int efidir_is_mac = 0;
852
const char *pkgdatadir;
854
grub_util_host_init (&argc, &argv);
855
product_version = xstrdup (PACKAGE_VERSION);
856
pkgdatadir = grub_util_get_pkgdatadir ();
857
label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2");
859
argp_parse (&argp, argc, argv, 0, 0, 0);
862
grub_env_set ("debug", "all");
864
grub_util_load_config (&config);
866
if (!bootloader_id && config.grub_distributor)
869
bootloader_id = xstrdup (config.grub_distributor);
870
for (ptr = bootloader_id; *ptr && *ptr != ' '; ptr++)
871
if (*ptr >= 'A' && *ptr <= 'Z')
872
*ptr = *ptr - 'A' + 'a';
875
if (!bootloader_id || bootloader_id[0] == '\0')
877
free (bootloader_id);
878
bootloader_id = xstrdup ("grub");
881
if (!grub_install_source_directory)
886
t = get_default_platform ();
888
grub_util_error ("%s",
889
_("Unable to determine your platform."
892
target = xstrdup (t);
894
grub_install_source_directory
895
= grub_util_path_concat (2, grub_util_get_pkglibdir (), target);
898
platform = grub_install_get_target (grub_install_source_directory);
901
char *platname = grub_install_get_platform_name (platform);
902
fprintf (stderr, _("Installing for %s platform.\n"), platname);
908
case GRUB_INSTALL_PLATFORM_I386_PC:
910
disk_module = xstrdup ("biosdisk");
912
case GRUB_INSTALL_PLATFORM_I386_EFI:
913
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
914
case GRUB_INSTALL_PLATFORM_ARM_EFI:
915
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
916
case GRUB_INSTALL_PLATFORM_IA64_EFI:
917
case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
918
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
919
case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
920
case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
921
case GRUB_INSTALL_PLATFORM_MIPS_ARC:
922
case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
923
case GRUB_INSTALL_PLATFORM_I386_XEN:
924
case GRUB_INSTALL_PLATFORM_X86_64_XEN:
927
case GRUB_INSTALL_PLATFORM_I386_QEMU:
928
case GRUB_INSTALL_PLATFORM_I386_COREBOOT:
929
case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
930
case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON:
931
case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
932
case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
933
disk_module = xstrdup ("native");
936
/* pacify warning. */
937
case GRUB_INSTALL_PLATFORM_MAX:
943
case GRUB_INSTALL_PLATFORM_I386_PC:
944
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
946
grub_util_error ("%s", _("install device isn't specified"));
948
case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
952
case GRUB_INSTALL_PLATFORM_MIPS_ARC:
953
case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
955
case GRUB_INSTALL_PLATFORM_I386_EFI:
956
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
957
case GRUB_INSTALL_PLATFORM_ARM_EFI:
958
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
959
case GRUB_INSTALL_PLATFORM_IA64_EFI:
960
case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
961
case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
962
case GRUB_INSTALL_PLATFORM_I386_QEMU:
963
case GRUB_INSTALL_PLATFORM_I386_COREBOOT:
964
case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
965
case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON:
966
case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
967
case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
968
case GRUB_INSTALL_PLATFORM_I386_XEN:
969
case GRUB_INSTALL_PLATFORM_X86_64_XEN:
970
free (install_device);
971
install_device = NULL;
974
/* pacify warning. */
975
case GRUB_INSTALL_PLATFORM_MAX:
980
bootdir = grub_util_path_concat (3, "/", rootdir, GRUB_BOOT_DIR_NAME);
983
char * t = grub_util_path_concat (2, bootdir, GRUB_DIR_NAME);
984
grub_install_mkdir_p (t);
985
grubdir = canonicalize_file_name (t);
987
grub_util_error (_("failed to get canonical path of `%s'"), t);
990
device_map = grub_util_path_concat (2, grubdir, "device.map");
993
grub_util_unlink (device_map);
995
device_map_check_duplicates (device_map);
996
grub_util_biosdisk_init (device_map);
998
/* Initialize all modules. */
1000
grub_gcry_init_all ();
1001
grub_hostfs_init ();
1006
case GRUB_INSTALL_PLATFORM_I386_EFI:
1007
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
1008
case GRUB_INSTALL_PLATFORM_ARM_EFI:
1009
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
1010
case GRUB_INSTALL_PLATFORM_IA64_EFI:
1017
/* pacify warning. */
1018
case GRUB_INSTALL_PLATFORM_MAX:
1022
/* Find the EFI System Partition. */
1027
free (install_device);
1028
install_device = NULL;
1031
char *d = grub_util_path_concat (2, bootdir, "efi");
1033
if (!grub_util_is_directory (d))
1036
d = grub_util_path_concat (2, bootdir, "EFI");
1039
The EFI System Partition may have been given directly using
1042
if (!grub_util_is_directory (d)
1043
&& rootdir && grub_strcmp (rootdir, "/") != 0)
1046
d = xstrdup (rootdir);
1048
if (grub_util_is_directory (d))
1049
dr = grub_make_system_path_relative_to_its_root (d);
1050
/* Is it a mount point? */
1051
if (dr && dr[0] == '\0')
1058
grub_util_error ("%s", _("cannot find EFI directory"));
1059
efidir_device_names = grub_guess_root_devices (efidir);
1060
if (!efidir_device_names || !efidir_device_names[0])
1061
grub_util_error (_("cannot find a device for %s (is /dev mounted?)"),
1063
install_device = efidir_device_names[0];
1065
for (curdev = efidir_device_names; *curdev; curdev++)
1066
grub_util_pull_device (*curdev);
1068
efidir_grub_devname = grub_util_get_grub_dev (efidir_device_names[0]);
1069
if (!efidir_grub_devname)
1070
grub_util_error (_("cannot find a GRUB drive for %s. Check your device.map"),
1071
efidir_device_names[0]);
1073
efidir_grub_dev = grub_device_open (efidir_grub_devname);
1074
if (! efidir_grub_dev)
1075
grub_util_error ("%s", grub_errmsg);
1077
fs = grub_fs_probe (efidir_grub_dev);
1079
grub_util_error ("%s", grub_errmsg);
1083
if (grub_strcmp (fs->name, "hfs") == 0
1084
|| grub_strcmp (fs->name, "hfsplus") == 0)
1087
if (!efidir_is_mac && grub_strcmp (fs->name, "fat") != 0)
1088
grub_util_error (_("%s doesn't look like an EFI partition.\n"), efidir);
1090
/* The EFI specification requires that an EFI System Partition must
1091
contain an "EFI" subdirectory, and that OS loaders are stored in
1092
subdirectories below EFI. Vendors are expected to pick names that do
1093
not collide with other vendors. To minimise collisions, we use the
1094
name of our distributor if possible.
1097
efi_distributor = bootloader_id;
1098
if (strcmp (efi_distributor, "kubuntu") == 0)
1099
efi_distributor = "ubuntu";
1102
case GRUB_INSTALL_PLATFORM_I386_EFI:
1103
efi_suffix = "ia32";
1104
efi_suffix_upper = "IA32";
1106
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
1108
efi_suffix_upper = "X64";
1110
case GRUB_INSTALL_PLATFORM_IA64_EFI:
1111
efi_suffix = "ia64";
1112
efi_suffix_upper = "IA64";
1114
case GRUB_INSTALL_PLATFORM_ARM_EFI:
1116
efi_suffix_upper = "ARM";
1118
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
1119
efi_suffix = "aa64";
1120
efi_suffix_upper = "AA64";
1127
/* The specification makes stricter requirements of removable
1128
devices, in order that only one image can be automatically loaded
1129
from them. The image must always reside under /EFI/BOOT, and it
1130
must have a specific file name depending on the architecture.
1132
efi_distributor = "BOOT";
1134
grub_util_error ("%s", _("You've found a bug"));
1135
efi_file = xasprintf ("BOOT%s.EFI", efi_suffix_upper);
1139
/* It is convenient for each architecture to have a different
1140
efi_file, so that different versions can be installed in parallel.
1142
efi_file = xasprintf ("grub%s.efi", efi_suffix);
1144
t = grub_util_path_concat (3, efidir, "EFI", efi_distributor);
1147
grub_install_mkdir_p (efidir);
1150
if (platform == GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275)
1152
const char *machtype = grub_install_get_default_powerpc_machtype ();
1155
if (strcmp (machtype, "pmac_oldworld") == 0)
1157
else if (strcmp (machtype, "cell") == 0)
1159
else if (strcmp (machtype, "generic") == 0)
1161
else if (strcmp (machtype, "chrp_ibm_qemu") == 0)
1169
d = grub_util_path_concat (2, bootdir, "macppc");
1170
if (!grub_util_is_directory (d))
1173
d = grub_util_path_concat (2, bootdir, "efi");
1175
/* Find the Mac HFS(+) System Partition. */
1176
if (!grub_util_is_directory (d))
1179
d = grub_util_path_concat (2, bootdir, "EFI");
1181
if (!grub_util_is_directory (d))
1191
char **macppcdir_device_names = NULL;
1192
grub_device_t macppcdir_grub_dev = NULL;
1193
char *macppcdir_grub_devname;
1196
macppcdir_device_names = grub_guess_root_devices (macppcdir);
1197
if (!macppcdir_device_names || !macppcdir_device_names[0])
1198
grub_util_error (_("cannot find a device for %s (is /dev mounted?)"),
1201
for (curdev = macppcdir_device_names; *curdev; curdev++)
1202
grub_util_pull_device (*curdev);
1204
macppcdir_grub_devname = grub_util_get_grub_dev (macppcdir_device_names[0]);
1205
if (!macppcdir_grub_devname)
1206
grub_util_error (_("cannot find a GRUB drive for %s. Check your device.map"),
1207
macppcdir_device_names[0]);
1209
macppcdir_grub_dev = grub_device_open (macppcdir_grub_devname);
1210
if (! macppcdir_grub_dev)
1211
grub_util_error ("%s", grub_errmsg);
1213
fs = grub_fs_probe (macppcdir_grub_dev);
1215
grub_util_error ("%s", grub_errmsg);
1217
if (grub_strcmp (fs->name, "hfs") != 0
1218
&& grub_strcmp (fs->name, "hfsplus") != 0
1220
grub_util_error (_("filesystem on %s is neither HFS nor HFS+"),
1222
if (grub_strcmp (fs->name, "hfs") == 0
1223
|| grub_strcmp (fs->name, "hfsplus") == 0)
1225
install_device = macppcdir_device_names[0];
1231
grub_install_copy_files (grub_install_source_directory,
1234
char *envfile = grub_util_path_concat (2, grubdir, "grubenv");
1235
if (!grub_util_is_regular (envfile))
1236
grub_util_create_envblk_file (envfile);
1240
/* Write device to a variable so we don't have to traverse /dev every time. */
1241
grub_devices = grub_guess_root_devices (grubdir);
1242
if (!grub_devices || !grub_devices[0])
1243
grub_util_error (_("cannot find a device for %s (is /dev mounted?)"),
1246
for (curdev = grub_devices; *curdev; curdev++)
1248
grub_util_pull_device (*curdev);
1252
grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1));
1254
for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++,
1257
*curdrive = grub_util_get_grub_dev (*curdev);
1259
grub_util_error (_("cannot find a GRUB drive for %s. Check your device.map"),
1264
grub_dev = grub_device_open (grub_drives[0]);
1266
grub_util_error ("%s", grub_errmsg);
1268
grub_fs = grub_fs_probe (grub_dev);
1270
grub_util_error ("%s", grub_errmsg);
1272
grub_install_push_module (grub_fs->name);
1275
probe_mods (grub_dev->disk);
1277
for (curdrive = grub_drives + 1; *curdrive; curdrive++)
1279
grub_device_t dev = grub_device_open (*curdrive);
1283
probe_mods (dev->disk);
1284
grub_device_close (dev);
1287
if (!config.is_cryptodisk_enabled && have_cryptodisk)
1288
grub_util_error (_("attempt to install to encrypted disk without cryptodisk enabled. "
1289
"Set `%s' in file `%s'."), "GRUB_ENABLE_CRYPTODISK=1",
1290
grub_util_get_config_filename ());
1292
if (disk_module && grub_strcmp (disk_module, "ata") == 0)
1293
grub_install_push_module ("pata");
1294
else if (disk_module && grub_strcmp (disk_module, "native") == 0)
1296
grub_install_push_module ("pata");
1297
grub_install_push_module ("ahci");
1298
grub_install_push_module ("ohci");
1299
grub_install_push_module ("uhci");
1300
grub_install_push_module ("usbms");
1302
else if (disk_module && disk_module[0])
1303
grub_install_push_module (disk_module);
1305
relative_grubdir = grub_make_system_path_relative_to_its_root (grubdir);
1306
if (relative_grubdir[0] == '\0')
1308
free (relative_grubdir);
1309
relative_grubdir = xstrdup ("/");
1312
char *platname = grub_install_get_platform_name (platform);
1315
char *t = grub_util_path_concat (2, grubdir,
1317
platdir = canonicalize_file_name (t);
1319
grub_util_error (_("failed to get canonical path of `%s'"),
1323
load_cfg = grub_util_path_concat (2, platdir,
1326
grub_util_unlink (load_cfg);
1328
if (debug_image && debug_image[0])
1330
load_cfg_f = grub_util_fopen (load_cfg, "wb");
1332
fprintf (load_cfg_f, "set debug='%s'\n",
1335
char *prefix_drive = NULL;
1336
char *install_drive = NULL;
1340
if (install_device[0] == '('
1341
&& install_device[grub_strlen (install_device) - 1] == ')')
1343
size_t len = grub_strlen (install_device) - 2;
1344
install_drive = xmalloc (len + 1);
1345
memcpy (install_drive, install_device + 1, len);
1346
install_drive[len] = '\0';
1350
grub_util_pull_device (install_device);
1351
install_drive = grub_util_get_grub_dev (install_device);
1353
grub_util_error (_("cannot find a GRUB drive for %s. Check your device.map"),
1358
char *efi_signed = NULL;
1361
case GRUB_INSTALL_PLATFORM_I386_EFI:
1362
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
1363
case GRUB_INSTALL_PLATFORM_ARM_EFI:
1364
case GRUB_INSTALL_PLATFORM_IA64_EFI:
1366
char *dir = xasprintf ("%s-signed", grub_install_source_directory);
1369
signed_image = xasprintf ("gcd%s.efi.signed", efi_suffix);
1371
signed_image = xasprintf ("grub%s.efi.signed", efi_suffix);
1372
efi_signed = grub_util_path_concat (2, dir, signed_image);
1380
if (!efi_signed || !grub_util_is_regular (efi_signed))
1381
uefi_secure_boot = 0;
1383
if (!have_abstractions || uefi_secure_boot)
1385
if ((disk_module && grub_strcmp (disk_module, "biosdisk") != 0)
1388
&& platform != GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275)
1389
|| (install_drive && !is_same_disk (grub_drives[0], install_drive))
1390
|| !have_bootdev (platform)
1391
|| uefi_secure_boot)
1394
/* generic method (used on coreboot and ata mod). */
1395
if (!force_file_id && grub_fs->uuid && grub_fs->uuid (grub_dev,
1398
grub_print_error ();
1404
load_cfg_f = grub_util_fopen (load_cfg, "wb");
1408
fprintf (load_cfg_f, "search.fs_uuid %s root ",
1410
grub_install_push_module ("search_fs_uuid");
1414
char *rndstr = get_rndstr ();
1415
char *fl = grub_util_path_concat (3, grubdir,
1417
char *fldir = grub_util_path_concat (2, grubdir,
1421
grub_install_mkdir_p (fldir);
1422
flf = grub_util_fopen (fl, "w");
1424
grub_util_error (_("Can't create file: %s"), strerror (errno));
1426
relfl = grub_make_system_path_relative_to_its_root (fl);
1427
fprintf (load_cfg_f, "search.file %s root ",
1429
grub_install_push_module ("search_fs_file");
1431
for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++,
1437
if (curdrive == grub_drives)
1440
dev = grub_device_open (*curdrive);
1444
if (dev->disk->dev->id != GRUB_DISK_DEVICE_HOSTDISK_ID)
1446
grub_util_fprint_full_disk_name (load_cfg_f,
1449
fprintf (load_cfg_f, " ");
1450
if (dev != grub_dev)
1451
grub_device_close (dev);
1455
map = grub_util_biosdisk_get_compatibility_hint (dev->disk);
1459
grub_util_fprint_full_disk_name (load_cfg_f, map, dev);
1460
fprintf (load_cfg_f, " ");
1464
if (disk_module && disk_module[0]
1465
&& grub_strcmp (disk_module, "biosdisk") != 0)
1466
g = grub_util_guess_baremetal_drive (*curdev);
1470
case GRUB_INSTALL_PLATFORM_I386_PC:
1471
g = grub_util_guess_bios_drive (*curdev);
1473
case GRUB_INSTALL_PLATFORM_I386_EFI:
1474
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
1475
case GRUB_INSTALL_PLATFORM_ARM_EFI:
1476
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
1477
case GRUB_INSTALL_PLATFORM_IA64_EFI:
1478
g = grub_util_guess_efi_drive (*curdev);
1480
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
1481
case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
1482
case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
1484
const char * ofpath = grub_util_devname_to_ofpath (*curdev);
1485
g = xasprintf ("ieee1275/%s", ofpath);
1488
case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON:
1489
case GRUB_INSTALL_PLATFORM_I386_QEMU:
1490
case GRUB_INSTALL_PLATFORM_I386_COREBOOT:
1491
case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
1492
case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
1493
case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
1494
g = grub_util_guess_baremetal_drive (*curdev);
1496
case GRUB_INSTALL_PLATFORM_MIPS_ARC:
1497
case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
1498
case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
1499
case GRUB_INSTALL_PLATFORM_I386_XEN:
1500
case GRUB_INSTALL_PLATFORM_X86_64_XEN:
1501
grub_util_warn ("%s", _("no hints available for your platform. Expect reduced performance"));
1503
/* pacify warning. */
1504
case GRUB_INSTALL_PLATFORM_MAX:
1509
grub_util_fprint_full_disk_name (load_cfg_f, g, dev);
1510
fprintf (load_cfg_f, " ");
1512
if (dev != grub_dev)
1513
grub_device_close (dev);
1515
fprintf (load_cfg_f, "\n");
1516
char *escaped_relpath = escape (relative_grubdir);
1517
fprintf (load_cfg_f, "set prefix=($root)'%s'\n",
1522
/* We need to hardcode the partition number in the core image's prefix. */
1524
for (p = grub_drives[0]; *p; )
1526
if (*p == '\\' && p[1])
1531
if (*p == ',' || *p == '\0')
1535
prefix_drive = xasprintf ("(%s)", p);
1540
if (config.is_cryptodisk_enabled)
1543
probe_cryptodisk_uuid (grub_dev->disk);
1545
for (curdrive = grub_drives + 1; *curdrive; curdrive++)
1547
grub_device_t dev = grub_device_open (*curdrive);
1551
probe_cryptodisk_uuid (dev->disk);
1552
grub_device_close (dev);
1555
prefix_drive = xasprintf ("(%s)", grub_drives[0]);
1558
char mkimage_target[200];
1559
const char *core_name = NULL;
1563
case GRUB_INSTALL_PLATFORM_I386_EFI:
1564
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
1565
case GRUB_INSTALL_PLATFORM_ARM_EFI:
1566
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
1567
case GRUB_INSTALL_PLATFORM_IA64_EFI:
1568
core_name = "core.efi";
1569
snprintf (mkimage_target, sizeof (mkimage_target),
1571
grub_install_get_platform_cpu (platform),
1572
grub_install_get_platform_platform (platform));
1574
case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON:
1575
case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
1576
case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
1577
core_name = "core.elf";
1578
snprintf (mkimage_target, sizeof (mkimage_target),
1580
grub_install_get_platform_cpu (platform),
1581
grub_install_get_platform_platform (platform));
1584
case GRUB_INSTALL_PLATFORM_I386_COREBOOT:
1585
case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
1586
case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
1587
case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
1588
case GRUB_INSTALL_PLATFORM_I386_XEN:
1589
case GRUB_INSTALL_PLATFORM_X86_64_XEN:
1590
core_name = "core.elf";
1591
snprintf (mkimage_target, sizeof (mkimage_target),
1593
grub_install_get_platform_cpu (platform),
1594
grub_install_get_platform_platform (platform));
1598
case GRUB_INSTALL_PLATFORM_I386_PC:
1599
case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
1600
case GRUB_INSTALL_PLATFORM_MIPS_ARC:
1601
case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
1602
case GRUB_INSTALL_PLATFORM_I386_QEMU:
1603
snprintf (mkimage_target, sizeof (mkimage_target),
1605
grub_install_get_platform_cpu (platform),
1606
grub_install_get_platform_platform (platform));
1607
core_name = "core.img";
1609
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
1610
strcpy (mkimage_target, "sparc64-ieee1275-raw");
1611
core_name = "core.img";
1613
/* pacify warning. */
1614
case GRUB_INSTALL_PLATFORM_MAX:
1619
grub_util_error ("%s", _("You've found a bug"));
1622
fclose (load_cfg_f);
1624
char *imgfile = grub_util_path_concat (2, platdir,
1626
char *prefix = xasprintf ("%s%s", prefix_drive ? : "",
1628
grub_install_make_image_wrap (/* source dir */ grub_install_source_directory,
1630
/* output */ imgfile,
1632
have_load_cfg ? load_cfg : NULL,
1633
/* image target */ mkimage_target, 0);
1634
/* Backward-compatibility kludges. */
1637
case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON:
1639
char *dst = grub_util_path_concat (2, bootdir, "grub.elf");
1640
grub_install_copy_file (imgfile, dst, 1);
1645
case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
1646
case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
1648
char *dst = grub_util_path_concat (2, grubdir, "grub");
1649
grub_install_copy_file (imgfile, dst, 1);
1654
case GRUB_INSTALL_PLATFORM_I386_EFI:
1655
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
1657
char *dst = grub_util_path_concat (2, platdir, "grub.efi");
1658
grub_install_make_image_wrap (/* source dir */ grub_install_source_directory,
1662
have_load_cfg ? load_cfg : NULL,
1663
/* image target */ mkimage_target, 0);
1666
case GRUB_INSTALL_PLATFORM_ARM_EFI:
1667
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
1668
case GRUB_INSTALL_PLATFORM_IA64_EFI:
1669
case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
1670
case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
1671
case GRUB_INSTALL_PLATFORM_I386_COREBOOT:
1672
case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
1673
case GRUB_INSTALL_PLATFORM_I386_PC:
1674
case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
1675
case GRUB_INSTALL_PLATFORM_MIPS_ARC:
1676
case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
1677
case GRUB_INSTALL_PLATFORM_I386_QEMU:
1678
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
1679
case GRUB_INSTALL_PLATFORM_I386_XEN:
1680
case GRUB_INSTALL_PLATFORM_X86_64_XEN:
1682
/* pacify warning. */
1683
case GRUB_INSTALL_PLATFORM_MAX:
1687
/* Perform the platform-dependent install */
1691
case GRUB_INSTALL_PLATFORM_I386_PC:
1693
char *boot_img_src = grub_util_path_concat (2,
1694
grub_install_source_directory,
1696
char *boot_img = grub_util_path_concat (2, platdir,
1698
grub_install_copy_file (boot_img_src, boot_img, 1);
1700
grub_util_info ("%sgrub-bios-setup %s %s %s %s %s --directory='%s' --device-map='%s' '%s'",
1701
/* TRANSLATORS: This is a prefix in the log to indicate that usually
1702
a command would be executed but due to an option was skipped. */
1703
install_bootsector ? "" : _("NOT RUNNING: "),
1704
allow_floppy ? "--allow-floppy " : "",
1705
verbosity ? "--verbose " : "",
1706
force ? "--force " : "",
1707
!fs_probe ? "--skip-fs-probe" : "",
1708
!add_rs_codes ? "--no-rs-codes" : "",
1713
/* Now perform the installation. */
1714
if (install_bootsector)
1715
grub_util_bios_setup (platdir, "boot.img", "core.img",
1716
install_drive, force,
1717
fs_probe, allow_floppy, add_rs_codes);
1719
/* If vestiges of GRUB Legacy still exist, tell the Debian packaging
1720
that they can ignore them. */
1721
if (!rootdir && grub_util_is_regular ("/boot/grub/stage2") &&
1722
grub_util_is_regular ("/boot/grub/menu.lst"))
1726
fd = grub_util_fd_open ("/boot/grub/grub2-installed",
1727
GRUB_UTIL_FD_O_WRONLY);
1728
grub_util_fd_close (fd);
1733
case GRUB_INSTALL_PLATFORM_SPARC64_IEEE1275:
1735
char *boot_img_src = grub_util_path_concat (2,
1736
grub_install_source_directory,
1738
char *boot_img = grub_util_path_concat (2, platdir,
1740
grub_install_copy_file (boot_img_src, boot_img, 1);
1742
grub_util_info ("%sgrub-sparc64-setup %s %s %s %s --directory='%s' --device-map='%s' '%s'",
1743
install_bootsector ? "" : "NOT RUNNING: ",
1744
allow_floppy ? "--allow-floppy " : "",
1745
verbosity ? "--verbose " : "",
1746
force ? "--force " : "",
1747
!fs_probe ? "--skip-fs-probe" : "",
1752
/* Now perform the installation. */
1753
if (install_bootsector)
1754
grub_util_sparc_setup (platdir, "boot.img", "core.img",
1755
install_device, force,
1756
fs_probe, allow_floppy,
1761
case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275:
1764
char *core_services = grub_util_path_concat (4, macppcdir,
1765
"System", "Library",
1767
char *mach_kernel = grub_util_path_concat (2, macppcdir,
1769
char *grub_elf, *bootx;
1771
grub_device_t ins_dev;
1772
char *grub_chrp = grub_util_path_concat (2,
1773
grub_install_source_directory,
1776
grub_install_mkdir_p (core_services);
1778
bootx = grub_util_path_concat (2, core_services, "BootX");
1779
grub_install_copy_file (grub_chrp, bootx, 1);
1781
grub_elf = grub_util_path_concat (2, core_services, "grub.elf");
1782
grub_install_copy_file (imgfile, grub_elf, 1);
1784
f = grub_util_fopen (mach_kernel, "r+");
1786
grub_util_error (_("Can't create file: %s"), strerror (errno));
1789
fill_core_services (core_services);
1791
ins_dev = grub_device_open (install_drive);
1793
bless (ins_dev, core_services, 0);
1800
partno = ins_dev->disk->partition
1801
? ins_dev->disk->partition->number + 1 : 0;
1802
dev = grub_util_get_os_disk (install_device);
1803
grub_install_register_ieee1275 (0, dev, partno,
1806
grub_device_close (ins_dev);
1813
/* If a install device is defined, copy the core.elf to PReP partition. */
1814
if (is_prep && install_device && install_device[0])
1816
grub_device_t ins_dev;
1817
ins_dev = grub_device_open (install_drive);
1818
if (!ins_dev || !is_prep_partition (ins_dev))
1820
grub_util_error ("%s", _("the chosen partition is not a PReP partition"));
1822
if (is_prep_empty (ins_dev))
1824
if (write_to_disk (ins_dev, imgfile))
1825
grub_util_error ("%s", _("failed to copy Grub to the PReP partition"));
1829
char *s = xasprintf ("dd if=/dev/zero of=%s", install_device);
1830
grub_util_error (_("the PReP partition is not empty. If you are sure you want to use it, run dd to clear it: `%s'"),
1833
grub_device_close (ins_dev);
1835
grub_install_register_ieee1275 (1, grub_util_get_os_disk (install_device),
1840
case GRUB_INSTALL_PLATFORM_I386_IEEE1275:
1846
relpath = grub_make_system_path_relative_to_its_root (imgfile);
1847
partno = grub_dev->disk->partition
1848
? grub_dev->disk->partition->number + 1 : 0;
1849
dev = grub_util_get_os_disk (grub_devices[0]);
1850
grub_install_register_ieee1275 (0, dev,
1854
case GRUB_INSTALL_PLATFORM_MIPS_ARC:
1855
grub_install_sgi_setup (install_device, imgfile, "grub");
1858
case GRUB_INSTALL_PLATFORM_I386_EFI:
1861
char *dst = grub_util_path_concat (2, efidir, "grub.efi");
1862
/* For old macs. Suggested by Peter Jones. */
1863
grub_install_copy_file (imgfile, dst, 1);
1867
case GRUB_INSTALL_PLATFORM_X86_64_EFI:
1871
char *core_services = grub_util_path_concat (4, efidir,
1872
"System", "Library",
1874
char *mach_kernel = grub_util_path_concat (2, efidir,
1877
grub_device_t ins_dev;
1879
grub_install_mkdir_p (core_services);
1881
boot_efi = grub_util_path_concat (2, core_services, "boot.efi");
1882
grub_install_copy_file (imgfile, boot_efi, 1);
1884
f = grub_util_fopen (mach_kernel, "r+");
1886
grub_util_error (_("Can't create file: %s"), strerror (errno));
1889
fill_core_services(core_services);
1891
ins_dev = grub_device_open (install_drive);
1893
bless (ins_dev, boot_efi, 1);
1894
if (!removable && update_nvram)
1896
/* Try to make this image bootable using the EFI Boot Manager, if available. */
1897
grub_install_register_efi (efidir_grub_dev,
1898
"\\System\\Library\\CoreServices",
1902
grub_device_close (ins_dev);
1907
case GRUB_INSTALL_PLATFORM_ARM_EFI:
1908
case GRUB_INSTALL_PLATFORM_ARM64_EFI:
1909
case GRUB_INSTALL_PLATFORM_IA64_EFI:
1911
char *dst = grub_util_path_concat (2, efidir, efi_file);
1912
if (uefi_secure_boot)
1914
const char *shim_signed = "/usr/lib/shim/shim.efi.signed";
1918
if (grub_util_is_regular (shim_signed))
1920
char *chained_base, *chained_dst, *mok_signed;
1924
efi_file = xasprintf ("shim%s.efi", efi_suffix);
1926
dst = grub_util_path_concat (2, efidir, efi_file);
1928
grub_install_copy_file (shim_signed, dst, 1);
1929
chained_base = xasprintf ("grub%s.efi", efi_suffix);
1930
chained_dst = grub_util_path_concat (2, efidir, chained_base);
1931
grub_install_copy_file (efi_signed, chained_dst, 1);
1932
/* Not critical, so not an error if it's not present (as it
1933
won't be for older releases); but if we have it, make
1934
sure it's installed. */
1935
mok_signed = grub_util_path_concat (2, efidir,
1937
grub_install_copy_file ("/usr/lib/shim/MokManager.efi.signed",
1941
free (chained_base);
1944
grub_install_copy_file (efi_signed, dst, 1);
1946
config_dst = grub_util_path_concat (2, efidir, "grub.cfg");
1947
grub_install_copy_file (load_cfg, config_dst, 1);
1948
config_dst_f = grub_util_fopen (config_dst, "ab");
1949
fprintf (config_dst_f, "configfile $prefix/grub.cfg\n");
1950
fclose (config_dst_f);
1954
grub_install_copy_file (imgfile, dst, 1);
1957
if (!removable && update_nvram)
1959
char * efifile_path;
1962
/* Try to make this image bootable using the EFI Boot Manager, if available. */
1963
if (!efi_distributor || efi_distributor[0] == '\0')
1964
grub_util_error ("%s", _("EFI bootloader id isn't specified."));
1965
efifile_path = xasprintf ("\\EFI\\%s\\%s",
1968
part = (efidir_grub_dev->disk->partition
1969
? grub_partition_get_name (efidir_grub_dev->disk->partition)
1971
grub_util_info ("Registering with EFI: distributor = `%s',"
1972
" path = `%s', ESP at %s%s%s",
1973
efi_distributor, efifile_path,
1974
efidir_grub_dev->disk->name,
1975
(part ? ",": ""), (part ? : ""));
1977
grub_install_register_efi (efidir_grub_dev,
1978
efifile_path, efi_distributor);
1982
case GRUB_INSTALL_PLATFORM_I386_XEN:
1984
char *path = grub_util_path_concat (2, bootdir, "xen");
1985
char *dst = grub_util_path_concat (2, path, "pvboot-i386.elf");
1986
grub_install_mkdir_p (path);
1987
grub_install_copy_file (imgfile, dst, 1);
1993
case GRUB_INSTALL_PLATFORM_X86_64_XEN:
1995
char *path = grub_util_path_concat (2, bootdir, "xen");
1996
char *dst = grub_util_path_concat (2, path, "pvboot-x86_64.elf");
1997
grub_install_mkdir_p (path);
1998
grub_install_copy_file (imgfile, dst, 1);
2004
case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON:
2005
case GRUB_INSTALL_PLATFORM_MIPSEL_QEMU_MIPS:
2006
case GRUB_INSTALL_PLATFORM_MIPS_QEMU_MIPS:
2007
case GRUB_INSTALL_PLATFORM_I386_COREBOOT:
2008
case GRUB_INSTALL_PLATFORM_I386_MULTIBOOT:
2009
case GRUB_INSTALL_PLATFORM_MIPSEL_ARC:
2010
case GRUB_INSTALL_PLATFORM_ARM_UBOOT:
2011
case GRUB_INSTALL_PLATFORM_I386_QEMU:
2012
grub_util_warn ("%s",
2013
_("WARNING: no platform-specific install was performed"));
2015
/* pacify warning. */
2016
case GRUB_INSTALL_PLATFORM_MAX:
2020
fprintf (stderr, "%s\n", _("Installation finished. No error reported."));
2022
/* Free resources. */
2023
grub_gcry_fini_all ();