Print this page
backup vers
bootadm.c updated
bootadm ba_path->module

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/boot/bootadm/bootadm.c
          +++ new/usr/src/cmd/boot/bootadm/bootadm.c
↓ open down ↓ 110 lines elided ↑ open up ↑
 111  111          error_t (*handler)();
 112  112          int     unpriv;                 /* is this an unprivileged command */
 113  113  } subcmd_defn_t;
 114  114  
 115  115  #define LINE_INIT       0       /* lineNum initial value */
 116  116  #define ENTRY_INIT      -1      /* entryNum initial value */
 117  117  #define ALL_ENTRIES     -2      /* selects all boot entries */
 118  118  
 119  119  #define GRUB_DIR                "/boot/grub"
 120  120  #define GRUB_STAGE2             GRUB_DIR "/stage2"
 121      -#define GRUB_MENU               "/boot/grub/menu.lst"
 122      -#define MENU_TMP                "/boot/grub/menu.lst.tmp"
      121 +#define GRUB_MENU               "/boot/illumos.cfg"
      122 +#define MENU_TMP                "/boot/illumos.cfg.tmp"
 123  123  #define GRUB_BACKUP_MENU        "/etc/lu/GRUB_backup_menu"
 124  124  #define RAMDISK_SPECIAL         "/ramdisk"
 125  125  #define STUBBOOT                "/stubboot"
 126  126  #define MULTIBOOT               "/platform/i86pc/multiboot"
 127  127  #define GRUBSIGN_DIR            "/boot/grub/bootsign"
 128  128  #define GRUBSIGN_BACKUP         "/etc/bootsign"
 129  129  #define GRUBSIGN_UFS_PREFIX     "rootfs"
 130  130  #define GRUBSIGN_ZFS_PREFIX     "pool_"
 131  131  #define GRUBSIGN_LU_PREFIX      "BE_"
 132  132  #define UFS_SIGNATURE_LIST      "/var/run/grub_ufs_signatures"
↓ open down ↓ 38 lines elided ↑ open up ↑
 171  171   */
 172  172  #define DEFAULT_DEV_MODE        0644    /* default permissions */
 173  173  #define DEFAULT_DEV_UID         0       /* user root */
 174  174  #define DEFAULT_DEV_GID         3       /* group sys */
 175  175  
 176  176  /*
 177  177   * Menu related
 178  178   * menu_cmd_t and menu_cmds must be kept in sync
 179  179   */
 180  180  char *menu_cmds[] = {
 181      -        "default",      /* DEFAULT_CMD */
      181 +        "default_entry",/* DEFAULT_CMD */
 182  182          "timeout",      /* TIMEOUT_CMD */
 183      -        "title",        /* TITLE_CMD */
 184      -        "root",         /* ROOT_CMD */
 185      -        "kernel",       /* KERNEL_CMD */
 186      -        "kernel$",      /* KERNEL_DOLLAR_CMD */
 187      -        "module",       /* MODULE_CMD */
 188      -        "module$",      /* MODULE_DOLLAR_CMD */
 189      -        " ",            /* SEP_CMD */
      183 +        "entry_name",   /* TITLE_CMD */
      184 +        "pool_uuid",    /* ROOT_CMD */
      185 +        "kernel_path$", /* KERNEL_CMD */
      186 +        "kernel_path",  /* KERNEL_DOLLAR_CMD */
      187 +        "module$",      /* MODULE_CMD */
      188 +        "module",       /* MODULE_DOLLAR_CMD */
      189 +        "=",            /* SEP_CMD */
 190  190          "#",            /* COMMENT_CMD */
 191  191          "chainloader",  /* CHAINLOADER_CMD */
 192  192          "args",         /* ARGS_CMD */
 193      -        "findroot",     /* FINDROOT_CMD */
 194      -        "bootfs",       /* BOOTFS_CMD */
      193 +        "pool_label",   /* FINDROOT_CMD */
      194 +        "dataset",      /* BOOTFS_CMD */
      195 +        "kernel_options",/* KERNEL_OPTIONS_CMD */
 195  196          NULL
 196  197  };
 197  198  
 198  199  #define OPT_ENTRY_NUM   "entry"
 199  200  
 200  201  /*
 201  202   * exec_cmd related
 202  203   */
 203  204  typedef struct {
 204  205          line_t *head;
↓ open down ↓ 4478 lines elided ↑ open up ↑
4683 4684          char *mod_kernel,
4684 4685          char *module,
4685 4686          char *bootfs)
4686 4687  {
4687 4688          int             lineNum;
4688 4689          int             entryNum;
4689 4690          char            linebuf[BAM_MAXLINE];
4690 4691          menu_cmd_t      k_cmd;
4691 4692          menu_cmd_t      m_cmd;
4692 4693          const char      *fcn = "add_boot_entry()";
     4694 +        char * options;
4693 4695  
4694 4696          assert(mp);
4695 4697  
4696 4698          INJECT_ERROR1("ADD_BOOT_ENTRY_FINDROOT_NULL", findroot = NULL);
4697 4699          if (findroot == NULL) {
4698 4700                  bam_error(NULL_FINDROOT);
4699 4701                  return (BAM_ERROR);
4700 4702          }
4701 4703  
4702 4704          if (title == NULL) {
↓ open down ↓ 46 lines elided ↑ open up ↑
4749 4751              menu_cmds[FINDROOT_CMD], menu_cmds[SEP_CMD], findroot);
4750 4752          line_parser(mp, linebuf, &lineNum, &entryNum);
4751 4753          BAM_DPRINTF((D_ADD_FINDROOT_NUM, fcn, lineNum, entryNum));
4752 4754  
4753 4755          if (bootfs != NULL) {
4754 4756                  (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
4755 4757                      menu_cmds[BOOTFS_CMD], menu_cmds[SEP_CMD], bootfs);
4756 4758                  line_parser(mp, linebuf, &lineNum, &entryNum);
4757 4759          }
4758 4760  
     4761 +        options = strpbrk(kernel, " \t");
     4762 +        if (options)
     4763 +                *options++ = 0;
     4764 +
4759 4765          (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
4760 4766              menu_cmds[k_cmd], menu_cmds[SEP_CMD], kernel);
4761 4767          line_parser(mp, linebuf, &lineNum, &entryNum);
4762 4768  
     4769 +        if (options) {
     4770 +                (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
     4771 +                    menu_cmds[KERNEL_OPTIONS_CMD], menu_cmds[SEP_CMD], options);
     4772 +                line_parser(mp, linebuf, &lineNum, &entryNum);
     4773 +        }
     4774 +
4763 4775          if (mod_kernel != NULL) {
4764 4776                  (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
4765 4777                      menu_cmds[m_cmd], menu_cmds[SEP_CMD], mod_kernel);
4766 4778                  line_parser(mp, linebuf, &lineNum, &entryNum);
4767 4779          }
4768 4780  
4769 4781          (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
4770 4782              menu_cmds[m_cmd], menu_cmds[SEP_CMD], module);
4771 4783          line_parser(mp, linebuf, &lineNum, &entryNum);
4772 4784  
↓ open down ↓ 2332 lines elided ↑ open up ↑
7105 7117          INJECT_ERROR1("GET_GRUBSIGN_FDISK", fdiskpart = -1);
7106 7118          if (fdiskpart == -1) {
7107 7119                  bam_error(FDISKPART_FAIL, osdev);
7108 7120                  free(sign);
7109 7121                  return (NULL);
7110 7122          }
7111 7123  
7112 7124          slice = strrchr(osdev, 's');
7113 7125  
7114 7126          grubsign = s_calloc(1, MAXNAMELEN + 10);
7115      -        if (slice) {
     7127 +/*      if (slice) {
7116 7128                  (void) snprintf(grubsign, MAXNAMELEN + 10, "(%s,%d,%c)",
7117 7129                      sign, fdiskpart, slice[1] + 'a' - '0');
7118 7130          } else
7119 7131                  (void) snprintf(grubsign, MAXNAMELEN + 10, "(%s,%d)",
7120      -                    sign, fdiskpart);
     7132 +                    sign, fdiskpart);*/
     7133 +        grubsign = strdup(sign);
7121 7134  
7122 7135          free(sign);
7123 7136  
7124 7137          BAM_DPRINTF((D_GET_GRUBSIGN_SUCCESS, fcn, grubsign));
7125 7138  
7126      -        return (grubsign);
     7139 +        return (strchr(grubsign,'_') + 1);
7127 7140  }
7128 7141  
7129 7142  static char *
7130 7143  get_title(char *rootdir)
7131 7144  {
7132 7145          static char     title[80];
7133 7146          char            *cp = NULL;
7134 7147          char            release[PATH_MAX];
7135 7148          FILE            *fp;
7136 7149          const char      *fcn = "get_title()";
↓ open down ↓ 668 lines elided ↑ open up ↑
7805 7818                  } else if (lp->cmd != NULL &&
7806 7819                      strcmp(lp->cmd, menu_cmds[FINDROOT_CMD]) == 0) {
7807 7820                          INJECT_ERROR1("FIND_BOOT_ENTRY_NULL_FINDROOT",
7808 7821                              findroot = NULL);
7809 7822                          if (findroot == NULL) {
7810 7823                                  BAM_DPRINTF((D_NOMATCH_FINDROOT_NULL,
7811 7824                                      fcn, lp->arg));
7812 7825                                  continue;
7813 7826                          }
7814 7827                          /* findroot command found, try match  */
7815      -                        if (strcmp(lp->arg, findroot) != 0) {
     7828 +                        if (strncmp(lp->arg, strchr(findroot, '_') + 1, strlen(lp->arg)) != 0) {
7816 7829                                  BAM_DPRINTF((D_NOMATCH_FINDROOT,
7817 7830                                      fcn, findroot, lp->arg));
7818 7831                                  continue;
7819 7832                          }
7820 7833                          BAM_DPRINTF((D_MATCHED_FINDROOT, fcn, findroot));
7821 7834                          lp = lp->next;  /* advance to kernel line */
7822 7835                  } else if (lp->cmd != NULL &&
7823 7836                      strcmp(lp->cmd, menu_cmds[ROOT_CMD]) == 0) {
7824 7837                          INJECT_ERROR1("FIND_BOOT_ENTRY_NULL_ROOT", root = NULL);
7825 7838                          if (root == NULL) {
↓ open down ↓ 37 lines elided ↑ open up ↑
7863 7876  
7864 7877                  }
7865 7878                  BAM_DPRINTF((D_KERNEL_MATCH, fcn, kernel, lp->arg));
7866 7879  
7867 7880                  /*
7868 7881                   * Check for matching module entry (failsafe or normal).
7869 7882                   * If it fails to match, we go around the loop again.
7870 7883                   * For xpv entries, there are two module lines, so we
7871 7884                   * do the check twice.
7872 7885                   */
     7886 +                lp = lp->next;  /* advance to options line */
7873 7887                  lp = lp->next;  /* advance to module line */
7874 7888                  if (check_cmd(lp->cmd, MODULE_CMD, lp->arg, module) ||
7875 7889                      (((lp = lp->next) != NULL) &&
7876 7890                      check_cmd(lp->cmd, MODULE_CMD, lp->arg, module))) {
7877 7891                          /* match found */
7878 7892                          BAM_DPRINTF((D_MODULE_MATCH, fcn, module, lp->arg));
7879 7893                          break;
7880 7894                  }
7881 7895  
7882 7896                  if (strcmp(module, FAILSAFE_ARCHIVE) == 0 &&
↓ open down ↓ 21 lines elided ↑ open up ↑
7904 7918  update_boot_entry(menu_t *mp, char *title, char *findroot, char *root,
7905 7919      char *kernel, char *mod_kernel, char *module, int root_opt)
7906 7920  {
7907 7921          int             i;
7908 7922          int             change_kernel = 0;
7909 7923          entry_t         *ent;
7910 7924          line_t          *lp;
7911 7925          line_t          *tlp;
7912 7926          char            linebuf[BAM_MAXLINE];
7913 7927          const char      *fcn = "update_boot_entry()";
     7928 +        char            *label;
7914 7929  
7915 7930          /* note: don't match on title, it's updated on upgrade */
7916 7931          ent = find_boot_entry(mp, NULL, kernel, findroot, root, module,
7917 7932              root_opt, &i);
7918 7933          if ((ent == NULL) && (bam_direct == BAM_DIRECT_DBOOT)) {
7919 7934                  /*
7920 7935                   * We may be upgrading a kernel from multiboot to
7921 7936                   * directboot.  Look for a multiboot entry. A multiboot
7922 7937                   * entry will not have a findroot line.
7923 7938                   */
↓ open down ↓ 36 lines elided ↑ open up ↑
7960 7975                  if (lp->cmd != NULL)
7961 7976                          free(lp->cmd);
7962 7977  
7963 7978                  free(lp->sep);
7964 7979                  free(lp->arg);
7965 7980                  free(lp->line);
7966 7981          }
7967 7982  
7968 7983          lp->cmd = s_strdup(menu_cmds[FINDROOT_CMD]);
7969 7984          lp->sep = s_strdup(menu_cmds[SEP_CMD]);
7970      -        lp->arg = s_strdup(findroot);
     7985 +        label = s_strdup(strchr(findroot, '_') + 1);
     7986 +        *(strchr(label,',')) = 0;
     7987 +        lp->arg = s_strdup(label);
7971 7988          (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
7972      -            menu_cmds[FINDROOT_CMD], menu_cmds[SEP_CMD], findroot);
     7989 +            menu_cmds[FINDROOT_CMD], menu_cmds[SEP_CMD], label);
7973 7990          lp->line = s_strdup(linebuf);
     7991 +        free(label);
7974 7992          BAM_DPRINTF((D_ADDING_FINDROOT_LINE, fcn, findroot));
7975 7993  
7976 7994          /* kernel line */
7977 7995          lp = lp->next;
7978 7996  
7979 7997          if (ent->flags & BAM_ENTRY_UPGFSKERNEL) {
7980 7998                  char            *params = NULL;
     7999 +                char            *opts = NULL;
7981 8000  
7982      -                params = strstr(lp->line, "-s");
7983      -                if (params != NULL)
7984      -                        (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s%s",
7985      -                            menu_cmds[KERNEL_DOLLAR_CMD], menu_cmds[SEP_CMD],
7986      -                            kernel, params+2);
7987      -                else
7988      -                        (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
7989      -                            menu_cmds[KERNEL_DOLLAR_CMD], menu_cmds[SEP_CMD],
7990      -                            kernel);
     8001 +                opts = strpbrk(kernel, " \t");
     8002 +                *opts++ = '\0';
     8003 +                (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
     8004 +                    menu_cmds[KERNEL_DOLLAR_CMD], menu_cmds[SEP_CMD],
     8005 +                    kernel);
7991 8006  
7992 8007                  if (lp->cmd != NULL)
7993 8008                          free(lp->cmd);
7994 8009  
7995 8010                  free(lp->arg);
7996 8011                  free(lp->line);
7997 8012                  lp->cmd = s_strdup(menu_cmds[KERNEL_DOLLAR_CMD]);
7998 8013                  lp->arg = s_strdup(strstr(linebuf, "/"));
7999 8014                  lp->line = s_strdup(linebuf);
8000 8015                  ent->flags &= ~BAM_ENTRY_UPGFSKERNEL;
8001 8016                  BAM_DPRINTF((D_ADDING_KERNEL_DOLLAR, fcn, lp->prev->cmd));
     8017 +
     8018 +                lp = lp->next;
     8019 +                params = strstr(lp->arg, "-s");
     8020 +                free(lp->arg);
     8021 +                free(lp->line);
     8022 +                if (params)
     8023 +                        (void) snprintf(linebuf, sizeof(linebuf), "%s%s%s -s",
     8024 +                                lp->cmd, menu_cmds[SEP_CMD],opts);
     8025 +                else
     8026 +                        (void) snprintf(linebuf, sizeof(linebuf), "%s%s%s",
     8027 +                                lp->cmd, menu_cmds[SEP_CMD],opts);
     8028 +                lp->line = s_strdup(linebuf);
     8029 +                lp->arg = s_strdup(strchr(linebuf, '=') + 1);
8002 8030          }
8003 8031  
8004 8032          if (change_kernel) {
     8033 +                char            *opts = NULL;
8005 8034                  /*
8006 8035                   * We're upgrading from multiboot to directboot.
8007 8036                   */
     8037 +                opts = strpbrk(kernel, " \t");
     8038 +                *opts++ = '\0';
8008 8039                  if (lp->cmd != NULL &&
8009 8040                      strcmp(lp->cmd, menu_cmds[KERNEL_CMD]) == 0) {
8010 8041                          (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
8011 8042                              menu_cmds[KERNEL_DOLLAR_CMD], menu_cmds[SEP_CMD],
8012 8043                              kernel);
8013 8044                          free(lp->cmd);
8014 8045                          free(lp->arg);
8015 8046                          free(lp->line);
8016 8047                          lp->cmd = s_strdup(menu_cmds[KERNEL_DOLLAR_CMD]);
8017 8048                          lp->arg = s_strdup(kernel);
8018 8049                          lp->line = s_strdup(linebuf);
8019 8050                          lp = lp->next;
8020 8051                          BAM_DPRINTF((D_ADDING_KERNEL_DOLLAR, fcn, kernel));
     8052 +                        (void) snprintf(linebuf, sizeof(linebuf), "%s%s%s",
     8053 +                                lp->cmd, menu_cmds[SEP_CMD],opts);
     8054 +                        free(lp->arg);
     8055 +                        free(lp->line);
     8056 +                        lp->line = s_strdup(linebuf);
     8057 +                        lp->arg = s_strdup(strchr(linebuf, '=') + 1);
8021 8058                  }
8022 8059                  if (lp->cmd != NULL &&
8023 8060                      strcmp(lp->cmd, menu_cmds[MODULE_CMD]) == 0) {
8024 8061                          (void) snprintf(linebuf, sizeof (linebuf), "%s%s%s",
8025 8062                              menu_cmds[MODULE_DOLLAR_CMD], menu_cmds[SEP_CMD],
8026 8063                              module);
8027 8064                          free(lp->cmd);
8028 8065                          free(lp->arg);
8029 8066                          free(lp->line);
8030 8067                          lp->cmd = s_strdup(menu_cmds[MODULE_DOLLAR_CMD]);
↓ open down ↓ 908 lines elided ↑ open up ↑
8939 8976  
8940 8977                  if (optnum == KERNEL_CMD) {
8941 8978                          /*
8942 8979                           * At this point, we've already checked that old_args
8943 8980                           * and entryp are valid pointers.  The "+ 2" is for
8944 8981                           * a space a the string termination character.
8945 8982                           */
8946 8983                          new_str_len = (sizeof (DIRECT_BOOT_KERNEL) - 1) +
8947 8984                              strlen(old_args) + 2;
8948 8985                          new_arg = s_calloc(1, new_str_len);
8949      -                        (void) snprintf(new_arg, new_str_len, "%s %s",
8950      -                            DIRECT_BOOT_KERNEL, old_args);
     8986 +                        (void) snprintf(new_arg, new_str_len, "%s",
     8987 +                            DIRECT_BOOT_KERNEL);
8951 8988                          free(kernelp->arg);
8952 8989                          kernelp->arg = new_arg;
8953 8990  
8954 8991                          /*
8955 8992                           * We have changed the kernel line, so we may need
8956 8993                           * to update the archive line as well.
8957 8994                           */
8958 8995                          set_archive_line(entryp, kernelp);
8959 8996                          BAM_DPRINTF((D_GET_SET_KERNEL_RESET_KERNEL_SET_ARG,
8960 8997                              fcn, kernelp->arg));
↓ open down ↓ 140 lines elided ↑ open up ↑
9101 9138                  kernelp->arg = new_arg;
9102 9139  
9103 9140                  /*
9104 9141                   * If we have changed the kernel line, we may need to update
9105 9142                   * the archive line as well.
9106 9143                   */
9107 9144                  set_archive_line(entryp, kernelp);
9108 9145                  BAM_DPRINTF((D_GET_SET_KERNEL_REPLACED_KERNEL_SAME_ARG, fcn,
9109 9146                      kernelp->arg));
9110 9147          } else {
9111      -                new_str_len = old_kernel_len + strlen(path) + 8;
     9148 +                kernelp = kernelp->next;
     9149 +                new_str_len = strlen(kernelp->arg) + strlen(path) + 8;
9112 9150                  new_arg = s_calloc(1, new_str_len);
9113      -                (void) strncpy(new_arg, kernelp->arg, old_kernel_len);
     9151 +                (void) strncpy(new_arg, kernelp->arg, strlen(kernelp->arg));
9114 9152                  (void) strlcat(new_arg, " ", new_str_len);
9115 9153                  (void) strlcat(new_arg, path, new_str_len);
9116 9154                  free(kernelp->arg);
9117 9155                  kernelp->arg = new_arg;
9118 9156                  BAM_DPRINTF((D_GET_SET_KERNEL_SAME_KERNEL_REPLACED_ARG, fcn,
9119 9157                      kernelp->arg));
9120 9158          }
9121 9159          rv = BAM_WRITE;
9122 9160  
9123 9161  done:
↓ open down ↓ 550 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX