mirror of https://git.48k.eu/ogclient
fs: add swap support and improve mkfs logging
parent
8ff6341b69
commit
26ca4c7950
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue