diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-02-22 10:21:59 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-02-22 10:52:03 +0100 |
commit | 26ca4c7950ca745a922442118dbb7d40397209ee (patch) | |
tree | 9e54a713ccbaa0d5e02d0f100a4cdddd19bd0281 /src/utils/fs.py | |
parent | 8ff6341b69262ad7a5b2c7ac681947fdef80801d (diff) |
fs: add swap support and improve mkfs logging
Diffstat (limited to 'src/utils/fs.py')
-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. |