]>
git.proxmox.com Git - grub2.git/blob - util/grub-emu.c
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2003, 2004, 2005 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 2 of the License, or
8 * (at your option) any later version.
10 * This program 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, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <grub/setjmp.h>
30 #include <grub/i386/pc/util/biosdisk.h>
32 #include <grub/machine/console.h>
33 #include <grub/util/misc.h>
34 #include <grub/kernel.h>
35 #include <grub/normal.h>
36 #include <grub/util/getroot.h>
38 #include <grub/partition.h>
41 /* NetBSD uses /boot for its boot block. */
42 # define DEFAULT_DIRECTORY "/grub"
44 # define DEFAULT_DIRECTORY "/boot/grub"
47 #define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
49 /* Used for going back to the main function. */
53 grub_arch_modules_addr (void)
59 grub_arch_dl_check_header (void *ehdr
)
63 return GRUB_ERR_BAD_MODULE
;
67 grub_arch_dl_relocate_symbols (grub_dl_t mod
, void *ehdr
)
72 return GRUB_ERR_BAD_MODULE
;
76 grub_machine_init (void)
78 signal (SIGINT
, SIG_IGN
);
83 grub_machine_fini (void)
89 const char *argp_program_version
= PACKAGE_STRING
;
90 const char *argp_program_bug_address
= PACKAGE_BUGREPORT
;
91 static char doc
[] = "GRUB emulator";
93 static struct argp_option options
[] = {
94 {"root-device", 'r', "DEV", 0, "use DEV as the root device [default=guessed]", 0},
95 {"device-map", 'm', "FILE", 0, "use FILE as the device map", 0},
96 {"directory", 'd', "DIR", 0, "use GRUB files in the directory DIR", 0},
97 {"verbose", 'v', 0 , 0, "print verbose messages", 0},
109 parse_opt (int key
, char *arg
, struct argp_state
*state
)
111 struct arguments
*args
= state
->input
;
116 args
->root_dev
= arg
;
130 return ARGP_ERR_UNKNOWN
;
135 static struct argp argp
= {options
, parse_opt
, 0, doc
, 0, 0, 0};
139 main (int argc
, char *argv
[])
142 char rootprefix
[100];
143 struct arguments args
=
145 .dir
= DEFAULT_DIRECTORY
,
146 .dev_map
= DEFAULT_DEVICE_MAP
149 progname
= "grub-emu";
151 argp_parse (&argp
, argc
, argv
, 0, 0, &args
);
153 /* Make sure that there is a root device. */
156 args
.root_dev
= grub_guess_root_device (args
.dir
? : DEFAULT_DIRECTORY
);
159 grub_util_info ("guessing the root device failed, because of `%s'",
161 grub_util_error ("Cannot guess the root device. Specify the option ``--root-device''.");
165 prefix
= grub_get_prefix (args
.dir
? : DEFAULT_DIRECTORY
);
166 sprintf (rootprefix
, "%s%s", args
.root_dev
, prefix
);
168 grub_env_set ("prefix", rootprefix
);
170 /* XXX: This is a bit unportable. */
171 grub_util_biosdisk_init (args
.dev_map
);
172 grub_pc_partition_map_init ();
173 grub_amiga_partition_map_init ();
174 grub_apple_partition_map_init ();
175 grub_sun_partition_map_init ();
177 /* Initialize the default modules. */
178 grub_iso9660_init ();
189 grub_terminal_init ();
194 grub_default_init ();
195 grub_timeout_init ();
197 /* XXX: Should normal mode be started by default? */
201 if (setjmp (main_env
) == 0)
204 grub_timeout_fini ();
205 grub_default_fini ();
210 grub_util_biosdisk_fini ();
221 grub_terminal_fini ();
222 grub_amiga_partition_map_fini ();
223 grub_pc_partition_map_fini ();
224 grub_apple_partition_map_fini ();
225 grub_sun_partition_map_fini ();
227 grub_machine_fini ();