Esempio n. 1
0
def extend_fs(fs_type, fs_dev):
    if fs_type in ('ext2', 'ext3', 'ext4'):
        # ext3,4 file system can be mounted
        # must be checked with e2fsck -f
        utils.execute('e2fsck', '-yf', fs_dev, check_exit_code=[0])
        utils.execute('resize2fs', fs_dev, check_exit_code=[0])
    elif fs_type == 'xfs':
        # xfs file system must be mounted
        utils.execute('xfs_growfs', fs_dev, check_exit_code=[0])
    else:
        raise errors.FsUtilsError('Unsupported file system type')
Esempio n. 2
0
def make_fs(fs_type, fs_options, fs_label, dev):
    # NOTE(agordeev): notice the different flag to force the fs creating
    #                ext* uses -F flag, xfs/mkswap uses -f flag.
    cmd_line = []
    #通过mkswap创建swap分区
    cmd_name = 'mkswap'
    if fs_type != 'swap':
        #通过mkfs.ext4创建ext4
        cmd_name = 'mkfs.%s' % fs_type
    if fs_type == 'xfs':
        # NOTE(agordeev): force xfs creation.
        # Othwerwise, it will fail to proceed if filesystem exists.
        fs_options += ' -f '
    if fs_type == 'swap':
        fs_options += ' -f '
    cmd_line.append(cmd_name)
    for opt in (fs_options, format_fs_label(fs_label)):
        cmd_line.extend([s for s in opt.split(' ') if s])
    cmd_line.append(dev)

    # NOTE(dbilunov): make sure the newly-created fs can
    # be observed by blkid. Currently known problem is
    # that generated UUID could possibly collide with
    # minix filesystem magic (0x8f13)
    mkfs_ok = False
    for _ in six.moves.range(MAX_MKFS_TRIES):
        #格式化文件系统
        utils.execute(*cmd_line)
        try:
            utils.execute('blkid', '-c', '/dev/null', '-o', 'value', '-s',
                          'UUID', dev)
        except errors.ProcessExecutionError:
            LOG.warning('blkid has failed on %s, retrying...', dev)
        else:
            mkfs_ok = True
            break
    if not mkfs_ok:
        raise errors.FsUtilsError('Cannot get UUID of a newly-created ' +
                                  '{0} on {1}'.format(fs_type, dev))