index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | archinstall/lib/disk/partition.py | 67 |
diff --git a/archinstall/lib/disk/partition.py b/archinstall/lib/disk/partition.py index 7bfde64c..708edd29 100644 --- a/archinstall/lib/disk/partition.py +++ b/archinstall/lib/disk/partition.py @@ -5,15 +5,15 @@ import logging import json import os import hashlib -from typing import Optional, Dict, Any, List, Union +from typing import Optional, Dict, Any, List, Union, Iterator from .blockdevice import BlockDevice -from .helpers import get_mount_info, 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 from ..storage import storage from ..exceptions import DiskError, SysCallError, UnknownFilesystemFormat from ..output import log from ..general import SysCommand - +from .btrfs import get_subvolumes_from_findmnt, BtrfsSubvolume class Partition: def __init__(self, @@ -29,9 +29,11 @@ class Partition: part_id = os.path.basename(path) self.block_device = block_device + if type(self.block_device) is str: + raise ValueError(f"Partition()'s 'block_device' parameter has to be a archinstall.BlockDevice() instance!") + self.path = path self.part_id = part_id - self.mountpoint = mountpoint self.target_mountpoint = mountpoint self.filesystem = filesystem self._encrypted = None @@ -42,20 +44,12 @@ class Partition: self.mount(mountpoint) try: - mount_information = get_mount_info(self.path) + self.mount_information = list(find_mountpoint(self.path)) except DiskError: - mount_information = {} - - if mount_information.get('target', None): - if self.mountpoint != mount_information.get('target', None) and mountpoint: - raise DiskError(f"{self} was given a mountpoint but the actual mountpoint differs: {mount_information.get('target', None)}") - - if target := mount_information.get('target', None): - self.mountpoint = target + self.mount_information = [{}] if not self.filesystem and autodetect_filesystem: - if fstype := mount_information.get('fstype', get_filesystem_type(path)): - self.filesystem = fstype + self.filesystem = get_filesystem_type(path) if self.filesystem == 'crypto_LUKS': self.encrypted = True @@ -98,6 +92,20 @@ class Partition: } @property + def mountpoint(self) -> Optional[str]: + try: + data = json.loads(SysCommand(f"findmnt --json -R {self.path}").decode()) + for filesystem in data['filesystems']: + return filesystem.get('target') + + except SysCallError as error: + # Not mounted anywhere most likely + log(f"Could not locate mount information for {self.path}: {error}", level=logging.DEBUG) + pass + + return None + + @property def sector_size(self) -> Optional[int]: output = json.loads(SysCommand(f"lsblk --json -o+LOG-SEC {self.device_path}").decode('UTF-8')) @@ -135,14 +143,16 @@ class Partition: for i in range(storage['DISK_RETRY_ATTEMPTS']): self.partprobe() - if (handle := SysCommand(f"lsblk --json -b -o+SIZE {self.device_path}")).exit_code == 0: - lsblk = json.loads(handle.decode('UTF-8')) + try: + lsblk = json.loads(SysCommand(f"lsblk --json -b -o+SIZE {self.device_path}").decode()) for device in lsblk['blockdevices']: return convert_size_to_gb(device['size']) - elif handle.exit_code == 8192: - # Device is not a block device - return None + except SysCallError as error: + if error.exit_code == 8192: + return None + else: + raise error time.sleep(storage['DISK_TIMEOUTS']) @@ -200,7 +210,14 @@ class Partition: For instance when you want to get a __repr__ of the class. """ self.partprobe() - return SysCommand(f'blkid -s PARTUUID -o value {self.device_path}').decode('UTF-8').strip() + try: + return SysCommand(f'blkid -s PARTUUID -o value {self.device_path}').decode('UTF-8').strip() + except SysCallError as error: + if self.block_device.info.get('TYPE') == 'iso9660': + # Parent device is a Optical Disk (.iso dd'ed onto a device for instance) + return None + + raise DiskError(f"Could not get PARTUUID of partition {self}: {error}") @property def encrypted(self) -> Union[bool, None]: @@ -237,6 +254,12 @@ class Partition: device_path, bind_name = split_bind_name(self.path) return bind_name + @property + def subvolumes(self) -> Iterator[BtrfsSubvolume]: + for mountpoint in self.mount_information: + for result in get_subvolumes_from_findmnt(mountpoint): + yield result + def partprobe(self) -> bool: if self.block_device and SysCommand(f'partprobe {self.block_device.device}').exit_code == 0: time.sleep(1) @@ -411,7 +434,6 @@ class Partition: except SysCallError as err: raise err - self.mountpoint = target return True return False @@ -425,7 +447,6 @@ class Partition: if 0 < worker.exit_code < 8000: raise SysCallError(f"Could not unmount {self.path} properly: {worker}", exit_code=worker.exit_code) - self.mountpoint = None return True def umount(self) -> bool: |