From 26ca4c7950ca745a922442118dbb7d40397209ee Mon Sep 17 00:00:00 2001 From: OpenGnSys Support Team Date: Thu, 22 Feb 2024 10:21:59 +0100 Subject: fs: add swap support and improve mkfs logging --- src/utils/fs.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src') 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. -- cgit v1.2.3-18-g5258