Print this page
5377 bootadm update-archive misidentifies BEs as ramdisks


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  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 2011 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  */
  36 
  37 /* Headers */
  38 #include <stdio.h>
  39 #include <errno.h>
  40 #include <stdlib.h>
  41 #include <string.h>
  42 #include <unistd.h>
  43 #include <sys/types.h>
  44 #include <sys/stat.h>
  45 #include <alloca.h>
  46 #include <stdarg.h>
  47 #include <limits.h>


 104     OPT_REQ,            /* option required */
 105     OPT_OPTIONAL        /* option may or may not be present */
 106 } option_t;
 107 
 108 typedef struct {
 109         char    *subcmd;
 110         option_t option;
 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 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         "/ramdisk"
 125 #define STUBBOOT                "/stubboot"
 126 #define MULTIBOOT               "/platform/i86pc/multiboot"
 127 #define GRUBSIGN_DIR            "/boot/grub/bootsign"
 128 #define GRUBSIGN_BACKUP         "/etc/bootsign"
 129 #define GRUBSIGN_UFS_PREFIX     "rootfs"
 130 #define GRUBSIGN_ZFS_PREFIX     "pool_"
 131 #define GRUBSIGN_LU_PREFIX      "BE_"
 132 #define UFS_SIGNATURE_LIST      "/var/run/grub_ufs_signatures"
 133 #define ZFS_LEGACY_MNTPT        "/tmp/bootadm_mnt_zfs_legacy"
 134 
 135 #define BOOTADM_RDONLY_TEST     "BOOTADM_RDONLY_TEST"
 136 
 137 /* lock related */
 138 #define BAM_LOCK_FILE           "/var/run/bootadm.lock"
 139 #define LOCK_FILE_PERMS         (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
 140 
 141 #define CREATE_RAMDISK          "boot/solaris/bin/create_ramdisk"
 142 #define CREATE_DISKMAP          "boot/solaris/bin/create_diskmap"
 143 #define EXTRACT_BOOT_FILELIST   "boot/solaris/bin/extract_boot_filelist"
 144 #define GRUBDISK_MAP            "/var/run/solaris_grubdisk.map"


3449         if (strcmp(root, "/") != 0) {
3450                 cp = mntpt + strlen(mntpt) - 1;
3451                 if (*cp == '/')
3452                         *cp = '\0';
3453         }
3454         found = 0;
3455         while (getextmntent(fp, &mnt, sizeof (mnt)) == 0) {
3456                 if (strcmp(mnt.mnt_mountp, mntpt) == 0) {
3457                         found = 1;
3458                         break;
3459                 }
3460         }
3461 
3462         if (!found) {
3463                 if (bam_verbose)
3464                         bam_error(NOT_IN_MNTTAB, mntpt);
3465                 (void) fclose(fp);
3466                 return (0);
3467         }
3468 
3469         if (strstr(mnt.mnt_special, RAMDISK_SPECIAL) != NULL) {

3470                 if (bam_verbose)
3471                         bam_error(IS_RAMDISK, bam_root);
3472                 (void) fclose(fp);
3473                 return (1);
3474         }
3475 
3476         (void) fclose(fp);
3477 
3478         return (0);
3479 }
3480 
3481 static int
3482 is_boot_archive(char *root)
3483 {
3484         char            path[PATH_MAX];
3485         struct stat     sb;
3486         int             error;
3487         const char      *fcn = "is_boot_archive()";
3488 
3489         /*




   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  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.
  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  */
  36 
  37 /* Headers */
  38 #include <stdio.h>
  39 #include <errno.h>
  40 #include <stdlib.h>
  41 #include <string.h>
  42 #include <unistd.h>
  43 #include <sys/types.h>
  44 #include <sys/stat.h>
  45 #include <alloca.h>
  46 #include <stdarg.h>
  47 #include <limits.h>


 104     OPT_REQ,            /* option required */
 105     OPT_OPTIONAL        /* option may or may not be present */
 106 } option_t;
 107 
 108 typedef struct {
 109         char    *subcmd;
 110         option_t option;
 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 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"
 127 #define GRUBSIGN_DIR            "/boot/grub/bootsign"
 128 #define GRUBSIGN_BACKUP         "/etc/bootsign"
 129 #define GRUBSIGN_UFS_PREFIX     "rootfs"
 130 #define GRUBSIGN_ZFS_PREFIX     "pool_"
 131 #define GRUBSIGN_LU_PREFIX      "BE_"
 132 #define UFS_SIGNATURE_LIST      "/var/run/grub_ufs_signatures"
 133 #define ZFS_LEGACY_MNTPT        "/tmp/bootadm_mnt_zfs_legacy"
 134 
 135 #define BOOTADM_RDONLY_TEST     "BOOTADM_RDONLY_TEST"
 136 
 137 /* lock related */
 138 #define BAM_LOCK_FILE           "/var/run/bootadm.lock"
 139 #define LOCK_FILE_PERMS         (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
 140 
 141 #define CREATE_RAMDISK          "boot/solaris/bin/create_ramdisk"
 142 #define CREATE_DISKMAP          "boot/solaris/bin/create_diskmap"
 143 #define EXTRACT_BOOT_FILELIST   "boot/solaris/bin/extract_boot_filelist"
 144 #define GRUBDISK_MAP            "/var/run/solaris_grubdisk.map"


3449         if (strcmp(root, "/") != 0) {
3450                 cp = mntpt + strlen(mntpt) - 1;
3451                 if (*cp == '/')
3452                         *cp = '\0';
3453         }
3454         found = 0;
3455         while (getextmntent(fp, &mnt, sizeof (mnt)) == 0) {
3456                 if (strcmp(mnt.mnt_mountp, mntpt) == 0) {
3457                         found = 1;
3458                         break;
3459                 }
3460         }
3461 
3462         if (!found) {
3463                 if (bam_verbose)
3464                         bam_error(NOT_IN_MNTTAB, mntpt);
3465                 (void) fclose(fp);
3466                 return (0);
3467         }
3468 
3469         if (strncmp(mnt.mnt_special, RAMDISK_SPECIAL,
3470             strlen(RAMDISK_SPECIAL)) == 0) {
3471                 if (bam_verbose)
3472                         bam_error(IS_RAMDISK, bam_root);
3473                 (void) fclose(fp);
3474                 return (1);
3475         }
3476 
3477         (void) fclose(fp);
3478 
3479         return (0);
3480 }
3481 
3482 static int
3483 is_boot_archive(char *root)
3484 {
3485         char            path[PATH_MAX];
3486         struct stat     sb;
3487         int             error;
3488         const char      *fcn = "is_boot_archive()";
3489 
3490         /*