diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/fs.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/utils/fs.py b/src/utils/fs.py index 9f9f98b..69b4789 100644 --- a/src/utils/fs.py +++ b/src/utils/fs.py @@ -146,16 +146,17 @@ def mkfs(fs, disk, partition, label=None): 'ext4': mkfs_ext4, 'ntfs': mkfs_ntfs, 'fat32': mkfs_fat32, + 'linux-swap': mkfs_swap, } if fs not in fsdict: - logging.warn(f'mkfs aborted, invalid target filesystem.') - raise ValueError('Invalid target filesystem') + logging.error(f'mkfs fails, unsupported target filesystem {fs}') + raise ValueError(f'Unsupported target filesystem {fs}') try: partdev = get_partition_device(disk, partition) except ValueError as e: - logging.warn(f'mkfs aborted, invalid partition.') + logging.error(f'mkfs aborted, invalid partition.') raise e fsdict[fs](partdev, label) @@ -194,6 +195,17 @@ def mkfs_fat32(partdev, label=None): stderr=STDOUT) +def mkfs_swap(partdev, label=None): + if label: + cmd = shlex.split(f'mkswap -f -L {label} {partdev}') + else: + cmd = shlex.split(f'mkswap -f {partdev}') + with open('/tmp/command.log', 'wb', 0) as logfile: + subprocess.run(cmd, + stdout=logfile, + stderr=STDOUT) + + def get_filesystem_type(partdev): """ Get filesystem type from a partition device path. |