Beispiel #1
0
def _create_root_dir(container_dir, localdisk):
    """Prepares chrooted environment."""
    # Create root directory structure (chroot base).
    # container_dir/<subdir>
    root_dir = os.path.join(container_dir, 'root')

    already_initialized = fs_linux.blk_fs_test(localdisk['block_dev'])
    if not already_initialized:
        # Format the block device
        fs_linux.blk_fs_create(localdisk['block_dev'])

    _LOGGER.info('Creating container root directory: %s', root_dir)
    # Creates directory that will serve as new root.
    fs.mkdir_safe(fs.norm_safe(root_dir))
    # Unshare the mount namespace
    unshare.unshare(unshare.CLONE_NEWNS)
    # Mount the container root volume
    fs_linux.mount_filesystem(localdisk['block_dev'], root_dir)

    return root_dir
Beispiel #2
0
def chroot_init(newroot):
    """Prepares the file system for subsequent chroot.

    - Unshares mount subsystem.
    - Creates directory that will serve as new root.

    :param newroot:
        Path to the intended root dir of the chroot environment
    :type newroot:
        ``str``
    :returns:
        Normalized path to the new root dir
    :rtype:
        ``str``
    """
    # Make sure new root is valid argument.
    newroot_norm = norm_safe(newroot)
    # Creates directory that will serve as new root.
    mkdir_safe(newroot_norm)
    # Unshare the mount namespace
    unshare.unshare(unshare.CLONE_NEWNS)
    return newroot_norm
Beispiel #3
0
def _create_root_dir(tm_env, container_dir, root_dir, app):
    """Prepares chrooted environment."""
    # Generate a unique name for the app
    unique_name = appcfg.app_unique_name(app)

    # First wait for the block device to be ready
    localdisk_client = tm_env.svc_localdisk.make_client(
        os.path.join(container_dir, 'localdisk'))
    localdisk = localdisk_client.wait(unique_name)

    already_initialized = fs.test_filesystem(localdisk['block_dev'])
    if not already_initialized:
        # Format the block device
        fs.create_filesystem(localdisk['block_dev'])

    _LOGGER.info('Creating container root directory: %s', root_dir)
    # Creates directory that will serve as new root.
    fs.mkdir_safe(fs.norm_safe(root_dir))
    # Unshare the mount namespace
    unshare.unshare(unshare.CLONE_NEWNS)
    # Mount the container root volume
    fs.mount_filesystem(localdisk['block_dev'], root_dir)