1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
gboolean _ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot, int bootversion, int target_fd, GCancellable *cancellable, GError **error) { static const char hardcoded_video[] = "load_video\n" "set gfxpayload=keep\n"; static const char hardcoded_insmods[] = "insmod gzio\n"; const char *grub2_boot_device_id = g_getenv ("GRUB2_BOOT_DEVICE_ID"); const char *grub2_prepare_root_cache = g_getenv ("GRUB2_PREPARE_ROOT_CACHE");
g_assert (grub2_boot_device_id != NULL); g_assert (grub2_prepare_root_cache != NULL);
gboolean is_efi = g_getenv ("_OSTREE_GRUB2_IS_EFI") != NULL;
g_autoptr(GOutputStream) out_stream = g_unix_output_stream_new (target_fd, FALSE);
g_autoptr(GPtrArray) loader_configs = NULL; if (!_ostree_sysroot_read_boot_loader_configs (sysroot, bootversion, &loader_configs, cancellable, error)) return FALSE;
g_autoptr(GString) output = g_string_new (""); for (guint i = 0; i < loader_configs->len; i++) { OstreeBootconfigParser *config = loader_configs->pdata[i]; const char *title; const char *options; const char *kernel; const char *initrd; const char *devicetree; char *quoted_title = NULL; char *uuid = NULL; char *quoted_uuid = NULL;
title = ostree_bootconfig_parser_get (config, "title"); if (!title) title = "(Untitled)";
kernel = ostree_bootconfig_parser_get (config, "linux");
quoted_title = g_shell_quote (title); uuid = g_strdup_printf ("ostree-%u-%s", (guint)i, grub2_boot_device_id); quoted_uuid = g_shell_quote (uuid); g_string_append_printf (output, "menuentry %s --class gnu-linux --class gnu --class os --unrestricted %s {\n", quoted_title, quoted_uuid); g_free (uuid); g_free (quoted_title); g_free (quoted_uuid);
g_string_append (output, hardcoded_video); g_string_append (output, hardcoded_insmods); g_string_append (output, grub2_prepare_root_cache); g_string_append_c (output, '\n');
if (!kernel) return glnx_throw (error, "No \"linux\" key in bootloader config"); g_string_append (output, "linux"); if (is_efi) g_string_append (output, GRUB2_EFI_SUFFIX); else g_string_append (output, GRUB2_SUFFIX); g_string_append_c (output, ' '); g_string_append (output, kernel);
options = ostree_bootconfig_parser_get (config, "options"); if (options) { g_string_append_c (output, ' '); g_string_append (output, options); } g_string_append_c (output, '\n');
initrd = ostree_bootconfig_parser_get (config, "initrd"); if (initrd) { g_string_append (output, "initrd"); if (is_efi) g_string_append (output, GRUB2_EFI_SUFFIX); else g_string_append (output, GRUB2_SUFFIX); g_string_append_c (output, ' '); g_string_append (output, initrd); g_string_append_c (output, '\n'); }
devicetree = ostree_bootconfig_parser_get (config, "devicetree"); if (devicetree) { g_string_append (output, "devicetree"); g_string_append_c (output, ' '); g_string_append (output, devicetree); g_string_append_c (output, '\n'); }
g_string_append (output, "}\n"); }
gsize bytes_written; if (!g_output_stream_write_all (out_stream, output->str, output->len, &bytes_written, cancellable, error)) return FALSE;
return TRUE; }
|