bootadm.c (08db0dbc) bootadm.c (1a902ef8)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 10 unchanged lines hidden (view full) ---

19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2012 Milan Jurik. All rights reserved.
24 */
25
26/*
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 10 unchanged lines hidden (view full) ---

19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2012 Milan Jurik. All rights reserved.
24 */
25
26/*
27 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
27 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
28 */
29
30/*
31 * bootadm(1M) is a new utility for managing bootability of
32 * Solaris *Newboot* environments. It has two primary tasks:
33 * - Allow end users to manage bootability of Newboot Solaris instances
34 * - Provide services to other subsystems in Solaris (primarily Install)
35 */

--- 75 unchanged lines hidden (view full) ---

111 error_t (*handler)();
112 int unpriv; /* is this an unprivileged command */
113} subcmd_defn_t;
114
115#define LINE_INIT 0 /* lineNum initial value */
116#define ENTRY_INIT -1 /* entryNum initial value */
117#define ALL_ENTRIES -2 /* selects all boot entries */
118
28 */
29
30/*
31 * bootadm(1M) is a new utility for managing bootability of
32 * Solaris *Newboot* environments. It has two primary tasks:
33 * - Allow end users to manage bootability of Newboot Solaris instances
34 * - Provide services to other subsystems in Solaris (primarily Install)
35 */

--- 75 unchanged lines hidden (view full) ---

111 error_t (*handler)();
112 int unpriv; /* is this an unprivileged command */
113} subcmd_defn_t;
114
115#define LINE_INIT 0 /* lineNum initial value */
116#define ENTRY_INIT -1 /* entryNum initial value */
117#define ALL_ENTRIES -2 /* selects all boot entries */
118
119#define PARTNO_NOTFOUND -1 /* Solaris partition not found */
120#define PARTNO_EFI -2 /* EFI partition table found */
121
119#define GRUB_DIR "/boot/grub"
120#define GRUB_STAGE2 GRUB_DIR "/stage2"
121#define GRUB_MENU "/boot/grub/menu.lst"
122#define MENU_TMP "/boot/grub/menu.lst.tmp"
123#define GRUB_BACKUP_MENU "/etc/lu/GRUB_backup_menu"
124#define RAMDISK_SPECIAL "/dev/ramdisk/"
125#define STUBBOOT "/stubboot"
126#define MULTIBOOT "/platform/i86pc/multiboot"

--- 4784 unchanged lines hidden (view full) ---

4911 return (fp);
4912}
4913
4914#define SECTOR_SIZE 512
4915
4916static int
4917get_partition(char *device)
4918{
122#define GRUB_DIR "/boot/grub"
123#define GRUB_STAGE2 GRUB_DIR "/stage2"
124#define GRUB_MENU "/boot/grub/menu.lst"
125#define MENU_TMP "/boot/grub/menu.lst.tmp"
126#define GRUB_BACKUP_MENU "/etc/lu/GRUB_backup_menu"
127#define RAMDISK_SPECIAL "/dev/ramdisk/"
128#define STUBBOOT "/stubboot"
129#define MULTIBOOT "/platform/i86pc/multiboot"

--- 4784 unchanged lines hidden (view full) ---

4914 return (fp);
4915}
4916
4917#define SECTOR_SIZE 512
4918
4919static int
4920get_partition(char *device)
4921{
4919 int i, fd, is_pcfs, partno = -1;
4922 int i, fd, is_pcfs, partno = PARTNO_NOTFOUND;
4920 struct mboot *mboot;
4921 char boot_sect[SECTOR_SIZE];
4922 char *wholedisk, *slice;
4923#ifdef i386
4924 ext_part_t *epp;
4925 uint32_t secnum, numsec;
4923 struct mboot *mboot;
4924 char boot_sect[SECTOR_SIZE];
4925 char *wholedisk, *slice;
4926#ifdef i386
4927 ext_part_t *epp;
4928 uint32_t secnum, numsec;
4926 int rval, pno, ext_partno = -1;
4929 int rval, pno, ext_partno = PARTNO_NOTFOUND;
4927#endif
4928
4929 /* form whole disk (p0) */
4930 slice = device + strlen(device) - 2;
4931 is_pcfs = (*slice != 's');
4932 if (!is_pcfs)
4933 *slice = '\0';
4934 wholedisk = s_calloc(1, strlen(device) + 3);

--- 39 unchanged lines hidden (view full) ---

4974 struct ipart *part =
4975 (struct ipart *)(uintptr_t)mboot->parts + i;
4976 if (is_pcfs) { /* looking for solaris boot part */
4977 if (part->systid == 0xbe) {
4978 partno = i;
4979 break;
4980 }
4981 } else { /* look for solaris partition, old and new */
4930#endif
4931
4932 /* form whole disk (p0) */
4933 slice = device + strlen(device) - 2;
4934 is_pcfs = (*slice != 's');
4935 if (!is_pcfs)
4936 *slice = '\0';
4937 wholedisk = s_calloc(1, strlen(device) + 3);

--- 39 unchanged lines hidden (view full) ---

4977 struct ipart *part =
4978 (struct ipart *)(uintptr_t)mboot->parts + i;
4979 if (is_pcfs) { /* looking for solaris boot part */
4980 if (part->systid == 0xbe) {
4981 partno = i;
4982 break;
4983 }
4984 } else { /* look for solaris partition, old and new */
4985 if (part->systid == EFI_PMBR) {
4986 partno = PARTNO_EFI;
4987 break;
4988 }
4989
4982#ifdef i386
4983 if ((part->systid == SUNIXOS &&
4984 (fdisk_is_linux_swap(epp, part->relsect,
4985 NULL) != 0)) || part->systid == SUNIXOS2) {
4986#else
4987 if (part->systid == SUNIXOS ||
4988 part->systid == SUNIXOS2) {
4989#endif

--- 4 unchanged lines hidden (view full) ---

4994#ifdef i386
4995 if (fdisk_is_dos_extended(part->systid))
4996 ext_partno = i;
4997#endif
4998 }
4999 }
5000#ifdef i386
5001 /* If no primary solaris partition, check extended partition */
4990#ifdef i386
4991 if ((part->systid == SUNIXOS &&
4992 (fdisk_is_linux_swap(epp, part->relsect,
4993 NULL) != 0)) || part->systid == SUNIXOS2) {
4994#else
4995 if (part->systid == SUNIXOS ||
4996 part->systid == SUNIXOS2) {
4997#endif

--- 4 unchanged lines hidden (view full) ---

5002#ifdef i386
5003 if (fdisk_is_dos_extended(part->systid))
5004 ext_partno = i;
5005#endif
5006 }
5007 }
5008#ifdef i386
5009 /* If no primary solaris partition, check extended partition */
5002 if ((partno == -1) && (ext_partno != -1)) {
5010 if ((partno == PARTNO_NOTFOUND) && (ext_partno != PARTNO_NOTFOUND)) {
5003 rval = fdisk_get_solaris_part(epp, &pno, &secnum, &numsec);
5004 if (rval == FDISK_SUCCESS) {
5005 partno = pno - 1;
5006 }
5007 }
5008 libfdisk_fini(&epp);
5009#endif
5010 return (partno);

--- 56 unchanged lines hidden (view full) ---

5067
5068 INJECT_ERROR1("GRUBROOT_BIOSDEV_FAIL", found = 0);
5069 if (found == 0) {
5070 bam_error(BIOSDEV_SKIP, osdev);
5071 return (NULL);
5072 }
5073
5074 fdiskpart = get_partition(osdev);
5011 rval = fdisk_get_solaris_part(epp, &pno, &secnum, &numsec);
5012 if (rval == FDISK_SUCCESS) {
5013 partno = pno - 1;
5014 }
5015 }
5016 libfdisk_fini(&epp);
5017#endif
5018 return (partno);

--- 56 unchanged lines hidden (view full) ---

5075
5076 INJECT_ERROR1("GRUBROOT_BIOSDEV_FAIL", found = 0);
5077 if (found == 0) {
5078 bam_error(BIOSDEV_SKIP, osdev);
5079 return (NULL);
5080 }
5081
5082 fdiskpart = get_partition(osdev);
5075 INJECT_ERROR1("GRUBROOT_FDISK_FAIL", fdiskpart = -1);
5076 if (fdiskpart == -1) {
5083 INJECT_ERROR1("GRUBROOT_FDISK_FAIL", fdiskpart = PARTNO_NOTFOUND);
5084 if (fdiskpart == PARTNO_NOTFOUND) {
5077 bam_error(FDISKPART_FAIL, osdev);
5078 return (NULL);
5079 }
5080
5081 grubroot = s_calloc(1, 10);
5085 bam_error(FDISKPART_FAIL, osdev);
5086 return (NULL);
5087 }
5088
5089 grubroot = s_calloc(1, 10);
5090 if (fdiskpart == PARTNO_EFI) {
5091 fdiskpart = atoi(&slice[1]);
5092 slice = NULL;
5093 }
5094
5082 if (slice) {
5083 (void) snprintf(grubroot, 10, "(hd%s,%d,%c)",
5084 grubhd, fdiskpart, slice[1] + 'a' - '0');
5085 } else
5086 (void) snprintf(grubroot, 10, "(hd%s,%d)",
5087 grubhd, fdiskpart);
5088
5089 assert(fp == NULL);

--- 2008 unchanged lines hidden (view full) ---

7098 }
7099
7100 free(fstype);
7101
7102 if (bam_verbose)
7103 bam_print(GRUBSIGN_FOUND_OR_CREATED, sign, osdev);
7104
7105 fdiskpart = get_partition(osdev);
5095 if (slice) {
5096 (void) snprintf(grubroot, 10, "(hd%s,%d,%c)",
5097 grubhd, fdiskpart, slice[1] + 'a' - '0');
5098 } else
5099 (void) snprintf(grubroot, 10, "(hd%s,%d)",
5100 grubhd, fdiskpart);
5101
5102 assert(fp == NULL);

--- 2008 unchanged lines hidden (view full) ---

7111 }
7112
7113 free(fstype);
7114
7115 if (bam_verbose)
7116 bam_print(GRUBSIGN_FOUND_OR_CREATED, sign, osdev);
7117
7118 fdiskpart = get_partition(osdev);
7106 INJECT_ERROR1("GET_GRUBSIGN_FDISK", fdiskpart = -1);
7107 if (fdiskpart == -1) {
7119 INJECT_ERROR1("GET_GRUBSIGN_FDISK", fdiskpart = PARTNO_NOTFOUND);
7120 if (fdiskpart == PARTNO_NOTFOUND) {
7108 bam_error(FDISKPART_FAIL, osdev);
7109 free(sign);
7110 return (NULL);
7111 }
7112
7113 slice = strrchr(osdev, 's');
7114
7121 bam_error(FDISKPART_FAIL, osdev);
7122 free(sign);
7123 return (NULL);
7124 }
7125
7126 slice = strrchr(osdev, 's');
7127
7128 if (fdiskpart == PARTNO_EFI) {
7129 fdiskpart = atoi(&slice[1]);
7130 slice = NULL;
7131 }
7132
7115 grubsign = s_calloc(1, MAXNAMELEN + 10);
7116 if (slice) {
7117 (void) snprintf(grubsign, MAXNAMELEN + 10, "(%s,%d,%c)",
7118 sign, fdiskpart, slice[1] + 'a' - '0');
7119 } else
7120 (void) snprintf(grubsign, MAXNAMELEN + 10, "(%s,%d)",
7121 sign, fdiskpart);
7122

--- 2552 unchanged lines hidden ---
7133 grubsign = s_calloc(1, MAXNAMELEN + 10);
7134 if (slice) {
7135 (void) snprintf(grubsign, MAXNAMELEN + 10, "(%s,%d,%c)",
7136 sign, fdiskpart, slice[1] + 'a' - '0');
7137 } else
7138 (void) snprintf(grubsign, MAXNAMELEN + 10, "(%s,%d)",
7139 sign, fdiskpart);
7140

--- 2552 unchanged lines hidden ---