Exemplo n.º 1
0
def cleanup_existing_install_target(install_profile):
    ''' If installer was restarted after the failure, it is necessary
        to destroy the pool previously created by the installer.

        If there is a root pool manually imported by the user with
        the same name which will be used by the installer
        for target root pool, we don't want to destroy user's data.
        So, we will log warning message and abort the installation.

    '''

    # Umount /var/run/boot_archive, which might be mounted by
    # previous x86 installations.
    # Error from this command is intentionally ignored, because the
    # previous invocation of the transfer module might or might not have
    # mounted on the mount point.
    if platform.processor() == "i386":
        with open("/dev/null", "w") as null_handle:
            sp.Popen(["/usr/sbin/umount", "-f", "/var/run/boot_archive"],
                     stdout=null_handle, stderr=null_handle)

    # Don't try to clean up existing pool in any way
    if install_profile.install_to_pool:
        return

    rootpool_name = install_profile.disks[0].get_install_root_pool()

    cmd = "/usr/sbin/zpool list " + rootpool_name
    logging.debug("Executing: %s", cmd)
    status = commands.getstatusoutput(cmd)[0]
    if status != 0:
        logging.debug("Root pool %s does not exist", rootpool_name)
        return   # rpool doesn't exist, no need to clean up

    # Check value of rpool's org.openindiana.caiman:install property
    # If it is busy, that means the pool is left over from an aborted install.
    # If the property doesn't exist or has another value, we assume
    # that the root pool contains valid OpenIndiana instance.
    cmd = "/usr/sbin/zfs get -H -o value org.openindiana.caiman:install " + \
          rootpool_name
    logging.debug("Executing: %s", cmd)
    (status, pool_status) = commands.getstatusoutput(cmd)
    logging.debug("Return code: %s", status)
    logging.debug("Pool status: %s", pool_status)
    if (status != 0) or (pool_status != "busy"):
        logging.error("Root pool %s exists.", rootpool_name)
        logging.error("Installation can not proceed")
        raise ti_utils.InstallationError

    try:
        # We use rpool here only to do tgt.release_zfs_root_pool
        # and it doesn't need device name, so we just insert some placeholder.
        # Perhaps, we could just run dumpadm -d, swap -d, zpool destroy manually.
        rpool = tgt.Zpool(rootpool_name, "/dev/_placeholder_device_name")
        tgt.release_zfs_root_pool(rpool)
        logging.debug("Completed release_zfs_root_pool")
    except TypeError, te:
        logging.error("Failed to release existing rpool.")
        logging.exception(te)
        raise ti_utils.InstallationError
Exemplo n.º 2
0
def do_ti(install_profile, swap_dump):
    '''Call the ti module to create the disk layout, create a zfs root
    pool, create zfs volumes for swap and dump, and to create a be.

    '''
    diskname = install_profile.disk.name
    logging.debug("Diskname: %s", diskname)
    mesg = "Preparing disk for %(release)s installation" % RELEASE
    try:
        (inst_device, inst_device_size) = \
             install_profile.disk.get_install_dev_name_and_size()

        # The installation size we provide already included the required
        # swap size
        (swap_type, swap_size, dump_type, dump_size) = \
            swap_dump.calc_swap_dump_size(ti_utils.get_minimum_size(swap_dump),
                                          inst_device_size, swap_included=True)

        tgt_disk = install_profile.disk.to_tgt()
        tgt.create_disk_target(tgt_disk, False)
        logging.debug("Completed create_disk_target")
        INSTALL_STATUS.update(InstallStatus.TI, 20, mesg)

        rootpool_name = install_profile.disk.get_install_root_pool()
        rpool = tgt.Zpool(rootpool_name, inst_device)
        tgt.create_zfs_root_pool(rpool)
        logging.debug("Completed create_zfs_root_pool")
        INSTALL_STATUS.update(InstallStatus.TI, 40, mesg)

        create_swap = False
        if (swap_type == ti_utils.SwapDump.ZVOL):
            create_swap = True

        create_dump = False
        if (dump_type == ti_utils.SwapDump.ZVOL):
            create_dump = True

        logging.debug("Create swap %s Swap size: %s", create_swap, swap_size)
        logging.debug("Create dump %s Dump size: %s", create_dump, dump_size)

        tgt.create_zfs_volume(rootpool_name, create_swap, swap_size,
                              create_dump, dump_size)
        logging.debug("Completed create swap and dump")
        INSTALL_STATUS.update(InstallStatus.TI, 70, mesg)

        zfs_datasets = ()
        for ds in reversed(
                ZFS_SHARED_FS):  # must traverse it in reversed order
            zd = tgt.ZFSDataset(mountpoint=ds)
            zfs_datasets += (zd, )
        tgt.create_be_target(rootpool_name, INIT_BE_NAME, INSTALLED_ROOT_DIR,
                             zfs_datasets)

        logging.debug("Completed create_be_target")
        INSTALL_STATUS.update(InstallStatus.TI, 100, mesg)
    except TypeError, te:
        logging.error("Failed to initialize disk")
        logging.exception(te)
        raise ti_utils.InstallationError