installer: Add basic UEFI system setup.
[dragonfly.git] / usr.sbin / installer / dfuibe_installer / fn_disk.c
blob9d4d04c152b8a3f682d945d00d405372b0dd76a2
1 /*
2 * Copyright (c)2004 The DragonFly Project. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
16 * Neither the name of the DragonFly Project nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
35 * fn_disk.c
36 * Disk functions for installer.
37 * $Id: fn_disk.c,v 1.40 2005/03/13 01:53:58 cpressey Exp $
40 #include <stdlib.h>
41 #include <string.h>
43 #ifdef ENABLE_NLS
44 #include <libintl.h>
45 #define _(String) gettext (String)
46 #else
47 #define _(String) (String)
48 #endif
50 #include "libaura/mem.h"
51 #include "libaura/fspred.h"
53 #include "libdfui/dfui.h"
54 #include "libdfui/system.h"
56 #include "libinstaller/commands.h"
57 #include "libinstaller/diskutil.h"
58 #include "libinstaller/functions.h"
59 #include "libinstaller/uiutil.h"
61 #include "fn.h"
62 #include "pathnames.h"
64 /*** DISK-RELATED FUNCTIONS ***/
67 * Ask the user which physical disk they want.
68 * Changes ss->selected_disk if successful.
70 void
71 fn_select_disk(struct i_fn_args *a)
73 struct dfui_form *f;
74 struct dfui_action *k;
75 struct dfui_response *r;
76 struct disk *d;
78 f = dfui_form_create(
79 "select_disk",
80 _("Select Disk"),
81 a->short_desc,
82 "",
84 "p", "role", "menu",
85 "p", "special", "dfinstaller_select_disk",
87 NULL
90 for (d = storage_disk_first(a->s); d != NULL; d = disk_next(d)) {
91 dfui_form_action_add(f, disk_get_device_name(d),
92 dfui_info_new(disk_get_desc(d), "", ""));
95 k = dfui_form_action_add(f, "cancel",
96 dfui_info_new(a->cancel_desc, "", ""));
97 dfui_action_property_set(k, "accelerator", "ESC");
99 if (!dfui_be_present(a->c, f, &r))
100 abort_backend();
102 if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
103 a->result = 0;
104 } else {
105 d = disk_find(a->s, dfui_response_get_action_id(r));
106 if (d == NULL) {
107 inform(a->c, _("Internal error - response from frontend "
108 "should be a valid device name."));
109 a->result = 0;
110 } else {
111 storage_set_selected_disk(a->s, d);
112 a->result = 1;
116 dfui_form_free(f);
117 dfui_response_free(r);
121 * Ask the user which slice on a the selected disk they want.
122 * Changes ss->selected_slice.
124 void
125 fn_select_slice(struct i_fn_args *a)
127 struct dfui_form *f;
128 struct dfui_action *k;
129 struct dfui_response *r;
130 struct slice *s;
131 char string[16];
133 f = dfui_form_create(
134 "select_slice",
135 _("Select Primary Partition"),
136 a->short_desc,
139 "p", "role", "menu",
140 "p", "special", "dfinstaller_select_slice",
142 NULL
145 for (s = disk_slice_first(storage_get_selected_disk(a->s));
146 s != NULL; s = slice_next(s)) {
147 snprintf(string, 16, "%d", slice_get_number(s));
148 dfui_form_action_add(f, string,
149 dfui_info_new(slice_get_desc(s), "", ""));
152 k = dfui_form_action_add(f, "cancel",
153 dfui_info_new(a->cancel_desc, "", ""));
154 dfui_action_property_set(k, "accelerator", "ESC");
156 if (!dfui_be_present(a->c, f, &r))
157 abort_backend();
159 if (strcmp(dfui_response_get_action_id(r), "cancel") == 0) {
160 a->result = 0;
161 } else {
162 s = slice_find(storage_get_selected_disk(a->s),
163 atoi(dfui_response_get_action_id(r)));
164 if (s == NULL) {
165 inform(a->c, _("Internal error - response from frontend "
166 "should be a valid slice number."));
167 a->result = 0;
168 } else {
169 storage_set_selected_slice(a->s, s);
170 a->result = 1;
174 dfui_form_free(f);
175 dfui_response_free(r);
179 * If ss->selected_disk == NULL, user will be asked for which disk.
180 * Returns 1 if disk was formatted, 0 if it wasn't.
181 * If it was, ss->selected_disk and ss->selected_slice are set to it.
183 void
184 fn_format_disk_mbr(struct i_fn_args *a)
186 struct commands *cmds;
187 char *selected_disk_string;
189 if (storage_get_selected_disk(a->s) == NULL) {
190 a->short_desc = _("Select a disk to format.");
191 a->cancel_desc = _("Return to Utilities Menu");
192 fn_select_disk(a);
193 if (!a->result || storage_get_selected_disk(a->s) == NULL) {
194 a->result = 0;
195 return;
199 if (confirm_dangerous_action(a->c,
200 _("WARNING! ALL data in ALL partitions on the disk\n\n"
201 "%s\n\nwill be IRREVOCABLY ERASED!\n\nAre you ABSOLUTELY "
202 "SURE you wish to take this action? This is your "
203 "LAST CHANCE to cancel!"), disk_get_desc(storage_get_selected_disk(a->s)))) {
204 cmds = commands_new();
206 command_add(cmds, "%s%s -BI %s",
207 a->os_root, cmd_name(a, "FDISK"),
208 disk_get_device_name(storage_get_selected_disk(a->s)));
210 if (!commands_execute(a, cmds)) {
211 inform(a->c, _("The disk\n\n%s\n\nwas "
212 "not correctly formatted, and may "
213 "now be in an inconsistent state. "
214 "We recommend re-formatting it "
215 "before attempting to install "
216 "%s on it."),
217 disk_get_desc(storage_get_selected_disk(a->s)),
218 OPERATING_SYSTEM_NAME);
219 commands_free(cmds);
220 a->result = 0;
221 return;
223 commands_free(cmds);
226 * Since one of the disks has now changed, we must
227 * refresh our view of them and re-select the disk
228 * since the selected_disk pointer will be invalidated.
230 selected_disk_string = aura_strdup(
231 disk_get_device_name(storage_get_selected_disk(a->s)));
232 if (!survey_storage(a)) {
233 inform(a->c, _("Errors occurred while probing "
234 "the system for its storage capabilities."));
236 storage_set_selected_disk(a->s, disk_find(a->s, selected_disk_string));
237 free(selected_disk_string);
240 * Note that we formatted this disk and that we want
241 * to use the first (and only) slice of it.
243 disk_set_formatted(storage_get_selected_disk(a->s), 1);
244 storage_set_selected_slice(a->s, disk_slice_first(storage_get_selected_disk(a->s)));
246 if (!format_slice(a)) {
247 inform(a->c, _("The sole primary partition of "
248 "the disk\n\n%s\n\nwas "
249 "not correctly formatted, and may "
250 "now be in an inconsistent state. "
251 "We recommend re-formatting the "
252 "disk before attempting to install "
253 "%s on it."),
254 disk_get_desc(storage_get_selected_disk(a->s)),
255 OPERATING_SYSTEM_NAME);
256 a->result = 0;
257 return;
260 inform(a->c, _("The disk\n\n%s\n\nwas formatted."),
261 disk_get_desc(storage_get_selected_disk(a->s)));
262 a->result = 1;
263 } else {
264 inform(a->c, _("Action cancelled - no disks were formatted."));
265 a->result = 0;
269 void
270 fn_format_disk_uefi(struct i_fn_args *a)
272 struct commands *cmds;
273 char *selected_disk_string;
275 if (storage_get_selected_disk(a->s) == NULL) {
276 a->short_desc = _("Select a disk to format.");
277 a->cancel_desc = _("Return to Utilities Menu");
278 fn_select_disk(a);
279 if (!a->result || storage_get_selected_disk(a->s) == NULL) {
280 a->result = 0;
281 return;
285 if (confirm_dangerous_action(a->c,
286 _("WARNING! ALL data in ALL partitions on the disk\n\n"
287 "%s\n\nwill be IRREVOCABLY ERASED!\n\nAre you ABSOLUTELY "
288 "SURE you wish to take this action? This is your "
289 "LAST CHANCE to cancel!"), disk_get_desc(storage_get_selected_disk(a->s)))) {
290 cmds = commands_new();
292 command_add(cmds,
293 "%s%s if=/dev/zero of=/dev/%s bs=32k count=16",
294 a->os_root, cmd_name(a, "DD"),
295 disk_get_device_name(storage_get_selected_disk(a->s)));
296 command_add(cmds, "%s%s destroy %s",
297 a->os_root, cmd_name(a, "GPT"),
298 disk_get_device_name(storage_get_selected_disk(a->s)));
299 command_add(cmds, "%s%s create -f %s",
300 a->os_root, cmd_name(a, "GPT"),
301 disk_get_device_name(storage_get_selected_disk(a->s)));
302 command_add(cmds, "%s%s add -i 0 -s 262144 -t efi %s",
303 a->os_root, cmd_name(a, "GPT"),
304 disk_get_device_name(storage_get_selected_disk(a->s)));
305 command_add(cmds, "%s%s add -i 1 -t dragonfly %s",
306 a->os_root, cmd_name(a, "GPT"),
307 disk_get_device_name(storage_get_selected_disk(a->s)));
308 command_add(cmds, "%s%s -F 32 -c 2 -L EFI -m 0xf8 %ss0",
309 a->os_root, cmd_name(a, "NEWFS_MSDOS"),
310 disk_get_device_name(storage_get_selected_disk(a->s)));
311 command_add(cmds, "%s%s /dev/%ss0 %smnt",
312 a->os_root, cmd_name(a, "MOUNT_MSDOS"),
313 disk_get_device_name(storage_get_selected_disk(a->s)),
314 a->os_root);
315 command_add(cmds, "%s%s -p %smnt/EFI/BOOT",
316 a->os_root, cmd_name(a, "MKDIR"), a->os_root);
317 command_add(cmds,
318 "%s%s %s/boot/boot1.efi %smnt/EFI/BOOT/BOOTX64.EFI",
319 a->os_root, cmd_name(a, "CP"),
320 a->os_root, a->os_root);
321 command_add(cmds, "%s%s %smnt",
322 a->os_root, cmd_name(a, "UMOUNT"), a->os_root);
324 if (!commands_execute(a, cmds)) {
325 inform(a->c, _("The disk\n\n%s\n\nwas "
326 "not correctly formatted, and may "
327 "now be in an inconsistent state. "
328 "We recommend re-formatting it "
329 "before attempting to install "
330 "%s on it."),
331 disk_get_desc(storage_get_selected_disk(a->s)),
332 OPERATING_SYSTEM_NAME);
333 commands_free(cmds);
334 a->result = 0;
335 return;
337 commands_free(cmds);
340 * Since one of the disks has now changed, we must
341 * refresh our view of them and re-select the disk
342 * since the selected_disk pointer will be invalidated.
344 selected_disk_string = aura_strdup(
345 disk_get_device_name(storage_get_selected_disk(a->s)));
346 if (!survey_storage(a)) {
347 inform(a->c, _("Errors occurred while probing "
348 "the system for its storage capabilities."));
350 storage_set_selected_disk(a->s,
351 disk_find(a->s, selected_disk_string));
352 free(selected_disk_string);
355 * Note that we formatted this disk and that we want
356 * to use the first (and only) slice of it.
358 disk_set_formatted(storage_get_selected_disk(a->s), 1);
359 storage_set_selected_slice(a->s,
360 disk_slice_first(storage_get_selected_disk(a->s)));
362 inform(a->c, _("The disk\n\n%s\n\nwas formatted."),
363 disk_get_desc(storage_get_selected_disk(a->s)));
364 a->result = 1;
365 } else {
366 inform(a->c, _("Action cancelled - no disks were formatted."));
367 a->result = 0;
372 * Wipes the start of the selected disk.
374 void
375 fn_wipe_start_of_disk(struct i_fn_args *a)
377 struct commands *cmds;
379 a->short_desc = _("If you are having problems formatting a disk, "
380 "it may be because of junk that has accumulated "
381 "in the boot block and the partition table. "
382 "A cure for this is to wipe out everything on "
383 "the first few sectors of the disk. However, this "
384 "is a rather drastic action to take, so it is not "
385 "recommended unless you are otherwise "
386 "encountering problems.");
387 a->cancel_desc = _("Return to Utilities Menu");
388 fn_select_disk(a);
389 if (!a->result)
390 return;
392 /* XXX check to make sure no slices on this disk are mounted first? */
393 if (storage_get_selected_disk(a->s) != NULL && confirm_dangerous_action(a->c,
394 _("WARNING! ALL data in ALL partitions on the disk\n\n"
395 "%s\n\nwill be IRREVOCABLY ERASED!\n\nAre you ABSOLUTELY "
396 "SURE you wish to take this action? This is your "
397 "LAST CHANCE to cancel!"), disk_get_desc(storage_get_selected_disk(a->s)))) {
398 cmds = commands_new();
399 command_add(cmds,
400 "%s%s if=/dev/zero of=/dev/%s bs=32k count=16",
401 a->os_root, cmd_name(a, "DD"),
402 disk_get_device_name(storage_get_selected_disk(a->s)));
403 if (commands_execute(a, cmds)) {
404 inform(a->c, _("Start of disk was successfully wiped."));
405 } else {
406 inform(a->c, _("Some errors occurred. "
407 "Start of disk was not successfully wiped."));
409 commands_free(cmds);
414 * Wipes the start of the selected slice.
416 void
417 fn_wipe_start_of_slice(struct i_fn_args *a)
419 struct commands *cmds;
421 a->short_desc =
422 _("If you are having problems formatting a primary partition, "
423 "it may be because of junk that has accumulated in the "
424 "partition's `disklabel'. A cure for this is to wipe out "
425 "everything on the first few sectors of the primary partition. "
426 "However, this is a rather drastic action to take, so it is not "
427 "recommended unless you are otherwise encountering problems.");
428 a->cancel_desc = _("Return to Utilities Menu");
429 fn_select_slice(a);
430 if (!a->result)
431 return;
433 if (confirm_dangerous_action(a->c,
434 _("WARNING! ALL data in primary partition #%d,\n\n%s\n\non the "
435 "disk\n\n%s\n\n will be IRREVOCABLY ERASED!\n\nAre you "
436 "ABSOLUTELY SURE you wish to take this action? This is "
437 "your LAST CHANCE to cancel!"),
438 slice_get_number(storage_get_selected_slice(a->s)),
439 slice_get_desc(storage_get_selected_slice(a->s)),
440 disk_get_desc(storage_get_selected_disk(a->s)))) {
441 /* XXX check to make sure this slice is not mounted first */
442 cmds = commands_new();
443 command_add(cmds, "%s%s if=/dev/zero of=/dev/%s bs=32k count=16",
444 a->os_root, cmd_name(a, "DD"),
445 slice_get_device_name(storage_get_selected_slice(a->s)));
446 if (commands_execute(a, cmds)) {
447 inform(a->c, _("Start of primary partition was successfully wiped."));
448 } else {
449 inform(a->c, _("Some errors occurred. "
450 "Start of primary partition was not successfully wiped."));
452 commands_free(cmds);
456 static void
457 ask_to_wipe_boot_sector(struct i_fn_args *a, struct commands *fcmds)
459 struct commands *cmds;
460 struct command *cmd;
461 char *disk;
463 for (cmd = command_get_first(fcmds); cmd != NULL;
464 cmd = command_get_next(cmd)) {
465 disk = command_get_tag(cmd);
466 if (disk != NULL &&
467 command_get_result(cmd) > 0 &&
468 command_get_result(cmd) < 256) {
469 switch (dfui_be_present_dialog(a->c,
470 _("Bootblock Install Failed"),
471 _("Re-Initialize Bootblock|Cancel"),
472 _("Warning: bootblocks were not successfully "
473 "installed on the disk `%s'. This may be "
474 "because the disk is new and not yet "
475 "formatted. If this is the case, it might "
476 "help to re-initialize the boot sector, "
477 "then try installing the bootblock again. "
478 "Note that this should not affect the "
479 "partition table of the disk."),
480 disk)) {
481 case 1:
482 cmds = commands_new();
483 command_add(cmds,
484 "%s%s | %s%s -B /dev/%s",
485 a->os_root, cmd_name(a, "YES"),
486 a->os_root, cmd_name(a, "FDISK"),
487 disk);
488 if (commands_execute(a, cmds)) {
489 inform(a->c, _("Boot sector successfully initialized."));
490 } else {
491 inform(a->c, _("Some errors occurred. "
492 "Boot sector was not successfully initialized."));
494 commands_free(cmds);
495 break;
496 default:
497 break;
503 void
504 fn_install_bootblocks(struct i_fn_args *a, const char *device)
506 struct dfui_form *f;
507 struct dfui_response *r;
508 struct dfui_dataset *ds;
509 struct disk *d;
510 struct commands *cmds;
511 struct command *cmd;
512 char disk[64], boot0cfg[32], packet[32];
513 char msg_buf[1][1024];
515 snprintf(msg_buf[0], sizeof(msg_buf[0]),
516 "'Packet Mode' refers to using newer BIOS calls to boot "
517 "from a partition of the disk. It is generally not "
518 "required unless:\n\n"
519 "- your BIOS does not support legacy mode; or\n"
520 "- your %s primary partition resides on a "
521 "cylinder of the disk beyond cylinder 1024; or\n"
522 "- you just can't get it to boot without it.",
523 OPERATING_SYSTEM_NAME);
525 f = dfui_form_create(
526 "install_bootstrap",
527 _("Install Bootblock(s)"),
528 a->short_desc,
530 msg_buf[0],
532 "p", "special", "dfinstaller_install_bootstrap",
534 "f", "disk", _("Disk Drive"),
535 _("The disk on which you wish to install a bootblock"), "",
536 "p", "editable", "false",
537 "f", "boot0cfg", _("Install Bootblock?"),
538 _("Install a bootblock on this disk"), "",
539 "p", "control", "checkbox",
540 "f", "packet", _("Packet Mode?"),
541 _("Select this to use 'packet mode' to boot the disk"), "",
542 "p", "control", "checkbox",
544 "a", "ok", _("Accept and Install Bootblocks"), "", "",
545 "a", "cancel", a->cancel_desc, "", "",
546 "p", "accelerator", "ESC",
548 NULL
551 dfui_form_set_multiple(f, 1);
553 if (device != NULL) {
554 ds = dfui_dataset_new();
555 dfui_dataset_celldata_add(ds, "disk", device);
556 dfui_dataset_celldata_add(ds, "boot0cfg", "Y");
557 dfui_dataset_celldata_add(ds, "packet", "Y");
558 dfui_form_dataset_add(f, ds);
559 } else {
560 for (d = storage_disk_first(a->s); d != NULL; d = disk_next(d)) {
561 ds = dfui_dataset_new();
562 dfui_dataset_celldata_add(ds, "disk",
563 disk_get_device_name(d));
564 dfui_dataset_celldata_add(ds, "boot0cfg", "Y");
565 dfui_dataset_celldata_add(ds, "packet", "Y");
566 dfui_form_dataset_add(f, ds);
570 if (!dfui_be_present(a->c, f, &r))
571 abort_backend();
573 a->result = 0;
574 if (strcmp(dfui_response_get_action_id(r), "ok") == 0) {
575 cmds = commands_new();
577 for (ds = dfui_response_dataset_get_first(r); ds != NULL;
578 ds = dfui_dataset_get_next(ds)) {
579 strlcpy(disk, dfui_dataset_get_value(ds, "disk"), 64);
580 strlcpy(boot0cfg, dfui_dataset_get_value(ds, "boot0cfg"), 32);
581 strlcpy(packet, dfui_dataset_get_value(ds, "packet"), 32);
583 if (strcasecmp(boot0cfg, "Y") == 0) {
584 cmd = command_add(cmds, "%s%s -B -o %spacket %s",
585 a->os_root, cmd_name(a, "BOOT0CFG"),
586 strcasecmp(packet, "Y") == 0 ? "" : "no",
587 disk);
588 command_set_failure_mode(cmd, COMMAND_FAILURE_WARN);
589 command_set_tag(cmd, "%s", disk);
590 cmd = command_add(cmds, "%s%s -v %s",
591 a->os_root, cmd_name(a, "BOOT0CFG"),
592 disk);
593 command_set_failure_mode(cmd, COMMAND_FAILURE_WARN);
594 command_set_tag(cmd, "%s", disk);
598 if (!commands_execute(a, cmds)) {
599 ask_to_wipe_boot_sector(a, cmds);
600 } else {
601 inform(a->c, _("Bootblocks were successfully installed!"));
602 a->result = 1;
604 commands_free(cmds);
607 dfui_form_free(f);
608 dfui_response_free(r);
611 void
612 fn_format_msdos_floppy(struct i_fn_args *a)
614 struct commands *cmds;
616 switch (dfui_be_present_dialog(a->c, _("Format MSDOS Floppy"),
617 _("Format Floppy|Return to Utilities Menu"),
618 _("Please insert the floppy to be formatted "
619 "in unit 0 (``drive A:'')."))) {
620 case 1:
621 cmds = commands_new();
622 command_add(cmds, "%s%s -y -f 1440 /dev/fd0",
623 a->os_root, cmd_name(a, "FDFORMAT"));
624 command_add(cmds, "%s%s -f 1440 fd0",
625 a->os_root, cmd_name(a, "NEWFS_MSDOS"));
626 if (commands_execute(a, cmds))
627 inform(a->c, _("Floppy successfully formatted!"));
628 else
629 inform(a->c, _("Floppy was not successfully formatted."));
630 break;
631 case 2:
632 return;
633 default:
634 abort_backend();
638 void
639 fn_create_cdboot_floppy(struct i_fn_args *a)
641 struct commands *cmds;
642 char msg_buf[1][1024];
644 snprintf(msg_buf[0], sizeof(msg_buf[0]),
645 "%s cannot be installed from a floppy; "
646 "it must be installed from a booted CD-ROM. "
647 "However, many older systems do not support booting "
648 "from a CD-ROM. For these systems, a boot disk can be "
649 "created. This boot disk contains the Smart Boot "
650 "Manager program, which can boot a CD-ROM even "
651 "on systems with BIOSes which do not support booting "
652 "from the CD-ROM.\n\n"
653 "Smart Boot Manager is not a part of %s; "
654 "the Smart Boot Manager project can be found here:\n\n"
655 "http://btmgr.sourceforge.net/\n\n"
656 "To create a CDBoot floppy, insert a blank floppy "
657 "in unit 0 (``drive A:'') before proceeding."
659 OPERATING_SYSTEM_NAME, OPERATING_SYSTEM_NAME);
661 switch (dfui_be_present_dialog(a->c, _("Create CDBoot Floppy"),
662 _("Create CDBoot Floppy|Return to Utilities Menu"),
663 "%s", msg_buf[0])) {
664 case 1:
665 cmds = commands_new();
666 command_add(cmds, "%s%s -c %sboot/cdboot.flp.bz2 | "
667 "%s%s of=/dev/fd0 bs=32k",
668 a->os_root, cmd_name(a, "BUNZIP2"),
669 a->os_root,
670 a->os_root, cmd_name(a, "DD"));
671 if (commands_execute(a, cmds))
672 inform(a->c, _("CDBoot floppy successfully created!"));
673 else
674 inform(a->c, _("CDBoot floppy was not successfully created."));
675 break;
676 case 2:
677 return;
678 default:
679 abort_backend();
683 /**** NON-fn_ FUNCTIONS ***/
686 format_slice(struct i_fn_args *a)
688 struct commands *cmds;
689 struct command *cmd;
690 int result;
691 int cyl, hd, sec;
693 cmds = commands_new();
696 * The information in a->s NEEDS to be accurate here!
697 * Presumably we just did a survey_storage() recently.
698 * XXX should we do another one here anyway just to be paranoid?
702 * Make sure the survey did get disk info correctly or fail
704 if ((storage_get_selected_disk(a->s) == NULL) ||
705 (storage_get_selected_slice(a->s) == NULL))
706 return 0;
709 * Set the slice's sysid to 165.
711 disk_get_geometry(storage_get_selected_disk(a->s), &cyl, &hd, &sec);
712 command_add(cmds, "%s%s 'g c%d h%d s%d' >%snew.fdisk",
713 a->os_root, cmd_name(a, "ECHO"),
714 cyl, hd, sec,
715 a->tmp);
716 command_add(cmds, "%s%s 'p %d %d %lu %lu' >>%snew.fdisk",
717 a->os_root, cmd_name(a, "ECHO"),
718 slice_get_number(storage_get_selected_slice(a->s)),
719 165,
720 slice_get_start(storage_get_selected_slice(a->s)),
721 slice_get_size(storage_get_selected_slice(a->s)),
722 a->tmp);
723 if (slice_get_flags(storage_get_selected_slice(a->s)) & 0x80) {
724 command_add(cmds, "%s%s 'a %d' >>%snew.fdisk",
725 a->os_root, cmd_name(a, "ECHO"),
726 slice_get_number(storage_get_selected_slice(a->s)),
727 a->tmp);
730 command_add(cmds, "%s%s %snew.fdisk",
731 a->os_root, cmd_name(a, "CAT"), a->tmp);
732 temp_file_add(a, "new.fdisk");
735 * Execute the fdisk script.
737 cmd = command_add(cmds, "%s%s -v -f %snew.fdisk %s",
738 a->os_root, cmd_name(a, "FDISK"), a->tmp,
739 disk_get_device_name(storage_get_selected_disk(a->s)));
740 if (slice_get_size(storage_get_selected_slice(a->s)) == 0xFFFFFFFFU)
741 command_set_failure_mode(cmd, COMMAND_FAILURE_IGNORE);
744 * If there is an old 'virgin' disklabel hanging around
745 * in the temp dir, get rid of it. This won't happen
746 * from a real CD, but might happen with '-o' installs.
748 command_add(cmds, "%s%s -f %sinstall.disklabel.%s",
749 a->os_root, cmd_name(a, "RM"),
750 a->tmp,
751 slice_get_device_name(storage_get_selected_slice(a->s)));
753 result = commands_execute(a, cmds);
755 commands_free(cmds);
757 return(result);