From f1333eb77cc5b3a42a338776ce08014638f146f5 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 9 Feb 2022 12:54:34 +0100 Subject: [PATCH] Removed subvolume logic from MapperDev().mount() as a mapperdev isn't a BtrfsSubvolume(), instead we need to create a BtrfsSubvolume().mount() that handles this. --- archinstall/lib/disk/helpers.py | 7 +++++++ archinstall/lib/disk/mapperdev.py | 26 +++++++++++++++++++++++++- archinstall/lib/disk/partition.py | 18 ++++++++---------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/archinstall/lib/disk/helpers.py b/archinstall/lib/disk/helpers.py index afaf9e5e..879df19c 100644 --- a/archinstall/lib/disk/helpers.py +++ b/archinstall/lib/disk/helpers.py @@ -25,6 +25,13 @@ GIGA = 2 ** 30 def convert_size_to_gb(size :Union[int, float]) -> float: return round(size / GIGA,1) +def get_mount_fs_type(fs :str) -> str: + if fs == 'ntfs': + return 'ntfs3' # Needed to use the Paragon R/W NTFS driver + elif fs == 'fat32': + return 'vfat' # This is the actual type used for fat32 mounting + return fs + def sort_block_devices_based_on_performance(block_devices :List[BlockDevice]) -> Dict[BlockDevice, int]: result = {device: 0 for device in block_devices} diff --git a/archinstall/lib/disk/mapperdev.py b/archinstall/lib/disk/mapperdev.py index b8ee7894..340b3ea4 100644 --- a/archinstall/lib/disk/mapperdev.py +++ b/archinstall/lib/disk/mapperdev.py @@ -87,4 +87,28 @@ class MapperDev: def format(self, filesystem :str, options :List[str] = []) -> bool: # TODO: Create a format() helper function rather than relying on a dummy Partition().format() call: - self.partition.format(filesystem=filesystem, options=options, path=self.path) \ No newline at end of file + self.partition.format(filesystem=filesystem, options=options, path=self.path) + + def mount(self, target :str, fs :Optional[str] = None, options :str = '') -> bool: + from .helpers import get_mount_fs_type + + log(f'Mounting {self} to {target}', level=logging.INFO) + if not fs: + if not (fs := self.filesystem): + raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.') + + fs_type = get_mount_fs_type(fs) + + pathlib.Path(target).mkdir(parents=True, exist_ok=True) + + try: + if options: + mnt_handle = SysCommand(f"/usr/bin/mount -t {fs_type} -o {options} {self.path} {target}") + else: + mnt_handle = SysCommand(f"/usr/bin/mount -t {fs_type} {self.path} {target}") + + except SysCallError as err: + raise DiskError(f"Could not mount {self.path} to {target} using options {options}: {err}") + + return True + diff --git a/archinstall/lib/disk/partition.py b/archinstall/lib/disk/partition.py index a03e510f..156ee959 100644 --- a/archinstall/lib/disk/partition.py +++ b/archinstall/lib/disk/partition.py @@ -8,7 +8,13 @@ import hashlib from typing import Optional, Dict, Any, List, Union, Iterator from .blockdevice import BlockDevice -from .helpers import find_mountpoint, get_filesystem_type, convert_size_to_gb, split_bind_name +from .helpers import ( + find_mountpoint, + get_filesystem_type, + convert_size_to_gb, + split_bind_name, + get_mount_fs_type +) from ..storage import storage from ..exceptions import DiskError, SysCallError, UnknownFilesystemFormat from ..output import log @@ -470,12 +476,4 @@ class Partition: pass # We supported it, but /dev/null is not formattable as expected so the mkfs call exited with an error code except UnknownFilesystemFormat as err: raise err - return True - - -def get_mount_fs_type(fs :str) -> str: - if fs == 'ntfs': - return 'ntfs3' # Needed to use the Paragon R/W NTFS driver - elif fs == 'fat32': - return 'vfat' # This is the actual type used for fat32 mounting - return fs + return True \ No newline at end of file