From 850fd2efa812508e2df67aa2b50cff8820389a0d Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 11:30:32 +0530 Subject: Started work on BIOS support --- archinstall/lib/disk.py | 16 ++++++++++++++-- archinstall/lib/installer.py | 23 ++++++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index c05ba757..16ee72e7 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -5,6 +5,7 @@ from .exceptions import DiskError from .general import * from .output import log, LOG_LEVELS from .storage import storage +from .hardware import hasUEFI ROOT_DIR_PATTERN = re.compile('^.*?/devices') GPT = 0b00000001 @@ -331,9 +332,12 @@ class Filesystem(): # TODO: # When instance of a HDD is selected, check all usages and gracefully unmount them # as well as close any crypto handles. - def __init__(self, blockdevice, mode=GPT): + def __init__(self, blockdevice): self.blockdevice = blockdevice - self.mode = mode + if hasUEFI(): + self.mode = GPT + else: + self.mode = MBR def __enter__(self, *args, **kwargs): if self.blockdevice.keep_partitions is False: @@ -343,6 +347,11 @@ class Filesystem(): return self else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') + elif self.mode == MBR: + if sys_command(f'/usr/bin/parted -s {self.blockdevice.} mklabel msdos').exit_code == 0: + return self + else: + raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos') else: raise DiskError(f'Unknown mode selected to format in: {self.mode}') @@ -405,6 +414,9 @@ class Filesystem(): log(f'Adding partition to {self.blockdevice}', level=LOG_LEVELS.Info) previous_partitions = self.blockdevice.partitions + if self.mode == MBR: + if len(self.blockdevice.partitions())>3: + DiskError("Too many partitions on disk, MBR disks can only have 3 parimary partitions") if format: partitioning = self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0 else: diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 06bdd05a..ecc3c9c9 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1,4 +1,4 @@ -import os, stat, time, shutil +import os, stat, time, shutil, subprocess from .exceptions import * from .disk import * @@ -53,6 +53,8 @@ class Installer(): } self.base_packages = base_packages.split(' ') + if not hasUEFI(): + base_packages.append('grub') # if it isn't uefi is must be bios therefore we need grub as systemd-boot is uefi only self.post_base_install = [] storage['session'] = self @@ -332,8 +334,10 @@ class Installer(): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) if not os.path.basename(real_path) == os.path.basename(self.partition.real_device): continue - - entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') + if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): # intel_paste is intel only, it's redudant on AMD systens + entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw\n') + else: + entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') self.helper_flags['bootloader'] = bootloader return True @@ -343,13 +347,22 @@ class Installer(): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) if not os.path.basename(real_path) == os.path.basename(self.partition.path): continue - - entry.write(f'options root=PARTUUID={uid} rw intel_pstate=no_hwp\n') + if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): + entry.write(f'options root=PARTUUID={uid} rw\n') + else: + entry.write(f'options root=PARTUUID={uid} rw intel_pstate=no_hwp\n') self.helper_flags['bootloader'] = bootloader return True break raise RequirementError(f"Could not identify the UUID of {self.partition}, there for {self.mountpoint}/boot/loader/entries/arch.conf will be broken until fixed.") + elif bootloader == 'grub-install': + if hasUEFI(): + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) + sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') + else: + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc {self}')) + sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: raise RequirementError(f"Unknown (or not yet implemented) bootloader added to add_bootloader(): {bootloader}") -- cgit v1.2.3-54-g00ecf From ceadb59b26cd99f11480058c072a678dc8ae2476 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 11:38:48 +0530 Subject: raise error if systemd-boot is used on a BIOS system --- archinstall/lib/installer.py | 89 +++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index ecc3c9c9..5ab560f4 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -313,49 +313,52 @@ class Installer(): self.log(f'Adding bootloader {bootloader} to {self.boot_partition}', level=LOG_LEVELS.Info) if bootloader == 'systemd-bootctl': - o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} bootctl --no-variables --path=/boot install')) - with open(f'{self.mountpoint}/boot/loader/loader.conf', 'w') as loader: - loader.write('default arch\n') - loader.write('timeout 5\n') - - ## For some reason, blkid and /dev/disk/by-uuid are not getting along well. - ## And blkid is wrong in terms of LUKS. - #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip() - with open(f'{self.mountpoint}/boot/loader/entries/arch.conf', 'w') as entry: - entry.write('title Arch Linux\n') - entry.write('linux /vmlinuz-linux\n') - entry.write('initrd /initramfs-linux.img\n') - ## blkid doesn't trigger on loopback devices really well, - ## so we'll use the old manual method until we get that sorted out. - - - if self.partition.encrypted: - for root, folders, uids in os.walk('/dev/disk/by-uuid'): - for uid in uids: - real_path = os.path.realpath(os.path.join(root, uid)) - if not os.path.basename(real_path) == os.path.basename(self.partition.real_device): continue - if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): # intel_paste is intel only, it's redudant on AMD systens - entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw\n') - else: - entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') - - self.helper_flags['bootloader'] = bootloader - return True - break - else: - for root, folders, uids in os.walk('/dev/disk/by-partuuid'): - for uid in uids: - real_path = os.path.realpath(os.path.join(root, uid)) - if not os.path.basename(real_path) == os.path.basename(self.partition.path): continue - if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): - entry.write(f'options root=PARTUUID={uid} rw\n') - else: - entry.write(f'options root=PARTUUID={uid} rw intel_pstate=no_hwp\n') - - self.helper_flags['bootloader'] = bootloader - return True - break - raise RequirementError(f"Could not identify the UUID of {self.partition}, there for {self.mountpoint}/boot/loader/entries/arch.conf will be broken until fixed.") + if hasUEFI(): + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} bootctl --no-variables --path=/boot install')) + with open(f'{self.mountpoint}/boot/loader/loader.conf', 'w') as loader: + loader.write('default arch\n') + loader.write('timeout 5\n') + + ## For some reason, blkid and /dev/disk/by-uuid are not getting along well. + ## And blkid is wrong in terms of LUKS. + #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip() + with open(f'{self.mountpoint}/boot/loader/entries/arch.conf', 'w') as entry: + entry.write('title Arch Linux\n') + entry.write('linux /vmlinuz-linux\n') + entry.write('initrd /initramfs-linux.img\n') + ## blkid doesn't trigger on loopback devices really well, + ## so we'll use the old manual method until we get that sorted out. + + + if self.partition.encrypted: + for root, folders, uids in os.walk('/dev/disk/by-uuid'): + for uid in uids: + real_path = os.path.realpath(os.path.join(root, uid)) + if not os.path.basename(real_path) == os.path.basename(self.partition.real_device): continue + if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): # intel_paste is intel only, it's redudant on AMD systens + entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw\n') + else: + entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') + + self.helper_flags['bootloader'] = bootloader + return True + break + else: + for root, folders, uids in os.walk('/dev/disk/by-partuuid'): + for uid in uids: + real_path = os.path.realpath(os.path.join(root, uid)) + if not os.path.basename(real_path) == os.path.basename(self.partition.path): continue + if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): + entry.write(f'options root=PARTUUID={uid} rw\n') + else: + entry.write(f'options root=PARTUUID={uid} rw intel_pstate=no_hwp\n') + + self.helper_flags['bootloader'] = bootloader + return True + break + raise RequirementError(f"Could not identify the UUID of {self.partition}, there for {self.mountpoint}/boot/loader/entries/arch.conf will be broken until fixed.") + else: + raise RequirementError("Systemd boot is UEFI only it can not be installed or used on bios") elif bootloader == 'grub-install': if hasUEFI(): o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) -- cgit v1.2.3-54-g00ecf From 43a0134f2e59dd34252195ff4d5bae4ebaaa6117 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 11:40:30 +0530 Subject: fixed typo --- archinstall/lib/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 5ab560f4..e393d50e 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -358,7 +358,7 @@ class Installer(): break raise RequirementError(f"Could not identify the UUID of {self.partition}, there for {self.mountpoint}/boot/loader/entries/arch.conf will be broken until fixed.") else: - raise RequirementError("Systemd boot is UEFI only it can not be installed or used on bios") + raise RequirementError("Systemd-boot is UEFI only it can not be installed or used on bios") elif bootloader == 'grub-install': if hasUEFI(): o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) -- cgit v1.2.3-54-g00ecf From 94456bf8ba692fb33c819d416636b34d9b14f7af Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 11:57:02 +0530 Subject: add function to check cpu vendor to allow for cpu specific command line arguments --- archinstall/lib/hardware.py | 7 ++++++- archinstall/lib/installer.py | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index 93eb560f..3586ad09 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -1,4 +1,4 @@ -import os +import os, subprocess from .general import sys_command from .networking import list_interfaces, enrichIfaceTypes @@ -7,6 +7,11 @@ def hasWifi(): return True return False +def hasAMDCPU(): + if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): + return True + return False + def hasUEFI(): return os.path.isdir('/sys/firmware/efi') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index e393d50e..dbcfb973 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -9,6 +9,7 @@ from .mirrors import * from .systemd import Networkd from .output import log, LOG_LEVELS from .storage import storage +from .hardware import * class Installer(): """ @@ -335,7 +336,7 @@ class Installer(): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) if not os.path.basename(real_path) == os.path.basename(self.partition.real_device): continue - if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): # intel_paste is intel only, it's redudant on AMD systens + if hasAMDCPU(): # intel_paste is intel only, it's redudant on AMD systens entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw\n') else: entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') @@ -348,7 +349,7 @@ class Installer(): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) if not os.path.basename(real_path) == os.path.basename(self.partition.path): continue - if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): + if hasAMDCPU(): entry.write(f'options root=PARTUUID={uid} rw\n') else: entry.write(f'options root=PARTUUID={uid} rw intel_pstate=no_hwp\n') -- cgit v1.2.3-54-g00ecf From 563a50dbc0d126c9d2e1038b7e71cf7d30a2fb29 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 11:59:46 +0530 Subject: fixed mistake in disk.py --- archinstall/lib/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 16ee72e7..cd740571 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -348,7 +348,7 @@ class Filesystem(): else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') elif self.mode == MBR: - if sys_command(f'/usr/bin/parted -s {self.blockdevice.} mklabel msdos').exit_code == 0: + if sys_command(f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos').exit_code == 0: return self else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos') -- cgit v1.2.3-54-g00ecf From f249476ea7c296459d175262f45c1f8273c6e8ea Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 13:40:54 +0530 Subject: figured out a way to get root device for installing grub --- archinstall/lib/disk.py | 18 ++++++++++-------- archinstall/lib/installer.py | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index cd740571..d05588a6 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -394,18 +394,20 @@ class Filesystem(): def use_entire_disk(self, root_filesystem_type='ext4', encrypt_root_partition=True): self.add_partition('primary', start='1MiB', end='513MiB', format='vfat') - self.set_name(0, 'EFI') - self.set(0, 'boot on') + #TODO: figure out what do for bios, we don't need a seprate partion for the bootloader + if hasUEFI(): + self.set_name(0, 'EFI') + self.set(0, 'boot on') # TODO: Probably redundant because in GPT mode 'esp on' is an alias for "boot on"? # https://www.gnu.org/software/parted/manual/html_node/set.html - self.set(0, 'esp on') - self.add_partition('primary', start='513MiB', end='100%') + self.set(0, 'esp on') + self.add_partition('primary', start='513MiB', end='100%') - self.blockdevice.partition[0].filesystem = 'vfat' - self.blockdevice.partition[1].filesystem = root_filesystem_type + self.blockdevice.partition[0].filesystem = 'vfat' + self.blockdevice.partition[1].filesystem = root_filesystem_type - self.blockdevice.partition[0].target_mountpoint = '/boot' - self.blockdevice.partition[1].target_mountpoint = '/' + self.blockdevice.partition[0].target_mountpoint = '/boot' + self.blockdevice.partition[1].target_mountpoint = '/' if encrypt_root_partition: self.blockdevice.partition[1].encrypted = True diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index dbcfb973..176b26f4 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -365,7 +365,8 @@ class Installer(): o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: - o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc {self}')) + root_device = subprocess.check_output(f'basename "$(readlink -f "/sys/class/block/{self.partition.path}/..")',shell=True).decode().strip() + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc /dev/{root_device}')) sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: raise RequirementError(f"Unknown (or not yet implemented) bootloader added to add_bootloader(): {bootloader}") -- cgit v1.2.3-54-g00ecf From 0a47dfe5d5bbc795366828fb7e453a8ef9d307cf Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 13:42:52 +0530 Subject: add a if statment to prevent a possible error --- archinstall/lib/installer.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 176b26f4..463f104a 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -366,6 +366,8 @@ class Installer(): sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: root_device = subprocess.check_output(f'basename "$(readlink -f "/sys/class/block/{self.partition.path}/..")',shell=True).decode().strip() + if root_device == "block": + root_device = f"{self.partition.path}" o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc /dev/{root_device}')) sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: -- cgit v1.2.3-54-g00ecf From 72284e2b2a96f4c8c6603f3a900b956121253b92 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 14:10:08 +0530 Subject: stip /dev/ since path is /dev/sdxN --- archinstall/lib/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 463f104a..e8829296 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -365,7 +365,7 @@ class Installer(): o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: - root_device = subprocess.check_output(f'basename "$(readlink -f "/sys/class/block/{self.partition.path}/..")',shell=True).decode().strip() + root_device = subprocess.check_output(f'basename "$(readlink -f "/sys/class/block/{self.partition.path.strip("/dev/")}/..")',shell=True).decode().strip() if root_device == "block": root_device = f"{self.partition.path}" o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc /dev/{root_device}')) -- cgit v1.2.3-54-g00ecf From 37a6018aaeed53ca95d9c7f81981db98aab24eab Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 28 Mar 2021 22:36:47 +0200 Subject: Fixed a path-check issue with Time Zones. --- archinstall/lib/installer.py | 16 ++++++++++++---- archinstall/lib/user_interaction.py | 8 +++++++- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 2200db8e..ff47be01 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -169,11 +169,19 @@ class Installer(): return True if sys_command(f'/usr/bin/arch-chroot {self.mountpoint} locale-gen').exit_code == 0 else False def set_timezone(self, zone, *args, **kwargs): - if not len(zone): return True + if not zone: return True + if not len(zone): return True # Redundant - (pathlib.Path(self.mountpoint)/"etc"/"localtime").unlink(missing_ok=True) - sys_command(f'/usr/bin/arch-chroot {self.mountpoint} ln -s /usr/share/zoneinfo/{zone} /etc/localtime') - return True + if (pathlib.Path("/usr")/"share"/"zoneinfo"/zone).exists(): + (pathlib.Path(self.mountpoint)/"etc"/"localtime").unlink(missing_ok=True) + sys_command(f'/usr/bin/arch-chroot {self.mountpoint} ln -s /usr/share/zoneinfo/{zone} /etc/localtime') + return True + else: + self.log( + f"Time zone {zone} does not exist, continuing with system default.", + level=LOG_LEVELS.Warning, + fg='red' + ) def activate_ntp(self): self.log(f'Installing and activating NTP.', level=LOG_LEVELS.Info) diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index e462c370..a79b4847 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -77,8 +77,14 @@ def ask_for_additional_users(prompt='Any additional users to install (leave blan def ask_for_a_timezone(): timezone = input('Enter a valid timezone (Example: Europe/Stockholm): ').strip() - if pathlib.Path(timezone).exists(): + if (pathlib.Path("/usr")/"share"/"zoneinfo"/timezone).exists(): return timezone + else: + log( + f"Time zone {timezone} does not exist, continuing with system default.", + level=LOG_LEVELS.Warning, + fg='red' + ) def ask_to_configure_network(): # Optionally configure one network interface. -- cgit v1.2.3-54-g00ecf From 0637ab6eb0b4be84bb03ffae41113c6a424f71e6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 28 Mar 2021 23:03:41 +0200 Subject: Adding debug to correct for a potential issue where partitions get marked as encrypted even tho \!disk-password was neven set. --- archinstall/lib/disk.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 2eef0e82..c1db3dc9 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -142,7 +142,7 @@ class Partition(): self.target_mountpoint = mountpoint self.filesystem = filesystem self.size = size # TODO: Refresh? - self.encrypted = encrypted + self._encrypted = encrypted self.allow_formatting = False # A fail-safe for unconfigured partitions, such as windows NTFS partitions. if mountpoint: @@ -161,7 +161,7 @@ class Partition(): self.filesystem = fstype if self.filesystem == 'crypto_LUKS': - self.encrypted = True + self._encrypted = True def __lt__(self, left_comparitor): if type(left_comparitor) == Partition: @@ -177,14 +177,23 @@ class Partition(): elif self.target_mountpoint: mount_repr = f", rel_mountpoint={self.target_mountpoint}" - if self.encrypted: + if self._encrypted: return f'Partition(path={self.path}, real_device={self.real_device}, fs={self.filesystem}{mount_repr})' else: return f'Partition(path={self.path}, fs={self.filesystem}{mount_repr})' + @property + def encrypted(self): + return self._encrypted + + @encrypted.setter + def encrypted(self, value :bool): + log(f'Marking {self} as encrypted', level=LOG_LEVELS.Debug) + self._encrypted = value + @property def real_device(self): - if not self.encrypted: + if not self._encrypted: return self.path else: for blockdevice in json.loads(b''.join(sys_command('lsblk -J')).decode('UTF-8'))['blockdevices']: @@ -237,7 +246,7 @@ class Partition(): """ from .luks import luks2 - if not self.encrypted: + if not self._encrypted: raise DiskError(f"Attempting to encrypt a partition that was not marked for encryption: {self}") if not self.safe_to_format(): -- cgit v1.2.3-54-g00ecf From 37ad64147f4f20823e789a16a2e48016299d0607 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 28 Mar 2021 23:10:23 +0200 Subject: Added some more useful debug data to the log. --- archinstall/lib/installer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index ff47be01..d161c3b7 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -369,10 +369,12 @@ class Installer(): if self.partition.encrypted: - log(f"Identifying root partition {self.partition} to boot based on disk UUID, looking for '{os.path.basename(self.partition.real_device)}'.", level=LOG_LEVELS.Debug) + log(f"Identifying root partition by DISK-UUID on {self.partition}, looking for '{os.path.basename(self.partition.real_device)}'.", level=LOG_LEVELS.Debug) for root, folders, uids in os.walk('/dev/disk/by-uuid'): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) + + log(f"Checking root partition match {os.path.basename(real_path)} against {os.path.basename(self.partition.real_device)}: {os.path.basename(real_path) == os.path.basename(self.partition.real_device)}", level=LOG_LEVELS.Debug) if not os.path.basename(real_path) == os.path.basename(self.partition.real_device): continue entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') @@ -381,10 +383,12 @@ class Installer(): return True break else: - log(f"Identifying root partition {self.partition} to boot based on partition UUID, looking for '{os.path.basename(self.partition.path)}'.", level=LOG_LEVELS.Debug) + log(f"Identifying root partition by PART-UUID on {self.partition}, looking for '{os.path.basename(self.partition.path)}'.", level=LOG_LEVELS.Debug) for root, folders, uids in os.walk('/dev/disk/by-partuuid'): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) + + log(f"Checking root partition match {os.path.basename(real_path)} against {os.path.basename(self.partition.path)}: {os.path.basename(real_path) == os.path.basename(self.partition.path)}", level=LOG_LEVELS.Debug) if not os.path.basename(real_path) == os.path.basename(self.partition.path): continue entry.write(f'options root=PARTUUID={uid} rw intel_pstate=no_hwp\n') -- cgit v1.2.3-54-g00ecf From a156f224a87a02d6b0f9a54eef2ce18e418e5187 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 08:56:41 +0200 Subject: Fixing un-encrypted drives matching on block encrypted. --- archinstall/lib/disk.py | 5 +++-- examples/guided.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index c1db3dc9..85b08bc0 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -142,7 +142,8 @@ class Partition(): self.target_mountpoint = mountpoint self.filesystem = filesystem self.size = size # TODO: Refresh? - self._encrypted = encrypted + self._encrypted = None + self.encrypted = encrypted self.allow_formatting = False # A fail-safe for unconfigured partitions, such as windows NTFS partitions. if mountpoint: @@ -161,7 +162,7 @@ class Partition(): self.filesystem = fstype if self.filesystem == 'crypto_LUKS': - self._encrypted = True + self.encrypted = True def __lt__(self, left_comparitor): if type(left_comparitor) == Partition: diff --git a/examples/guided.py b/examples/guided.py index 4766301e..d9dfe0df 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -292,6 +292,7 @@ def perform_installation(device, boot_partition, language, mirrors): Only requirement is that the block devices are formatted and setup prior to entering this function. """ + print('Installing on:', device) with archinstall.Installer(device, boot_partition=boot_partition, hostname=archinstall.arguments.get('hostname', 'Archinstall')) as installation: ## if len(mirrors): # Certain services might be running that affects the system during installation. -- cgit v1.2.3-54-g00ecf From 3161cd8afff2def3d4d3057cb028c666c4db55a3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 09:09:25 +0200 Subject: Fixing rare occation where partitions dissapear just before .format(). --- archinstall/lib/disk.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 85b08bc0..9afece2e 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -270,6 +270,11 @@ class Partition(): if allow_formatting is None: allow_formatting = self.allow_formatting + # To avoid "unable to open /dev/x: No such file or directory" + start_wait = time.time() + while pathlib.Path(path).exists() is False and time.time() - start_wait < 10: + time.sleep(0.025) + if not allow_formatting: raise PermissionError(f"{self} is not formatable either because instance is locked ({self.allow_formatting}) or a blocking flag was given ({allow_formatting})") -- cgit v1.2.3-54-g00ecf From f452dc695a6a2929ecf796f1730af3b683b1a449 Mon Sep 17 00:00:00 2001 From: Didr Date: Mon, 29 Mar 2021 10:16:20 +0200 Subject: Fix spelling error in filesystem choice Fixes a simple spelling error when the user is asked to select a filesystem. "Select which filesystem your main partition should use (by number **of** name)" should be **or**. --- archinstall/lib/user_interaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index a79b4847..a782197e 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -141,7 +141,7 @@ def ask_for_main_filesystem_format(): 'f2fs' : 'f2fs' } - value = generic_select(options.values(), "Select which filesystem your main partition should use (by number of name): ") + value = generic_select(options.values(), "Select which filesystem your main partition should use (by number or name): ") return next((key for key, val in options.items() if val == value), None) def generic_select(options, input_text="Select one of the above by index or absolute value: ", sort=True): -- cgit v1.2.3-54-g00ecf From 36dfa2e1c42add691243850b62b705b26a0a796c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 10:20:35 +0200 Subject: Reverting .strip() logic and moving the check into the get_password() function. --- archinstall/lib/user_interaction.py | 4 ++++ examples/guided.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index a79b4847..bee7b569 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -24,6 +24,10 @@ def get_password(prompt="Enter a password: "): if passwd != passwd_verification: log(' * Passwords did not match * ', bg='black', fg='red') continue + + if len(passwd.strip()) <= 0: + break + return passwd return None diff --git a/examples/guided.py b/examples/guided.py index 009f9fa6..92331450 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -139,7 +139,7 @@ def ask_user_questions(): # Get disk encryption password (or skip if blank) if not archinstall.arguments.get('!encryption-password', None): - if (passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): ')).strip(): + if (passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): ')): archinstall.arguments['!encryption-password'] = passwd archinstall.arguments['harddrive'].encryption_password = archinstall.arguments['!encryption-password'] -- cgit v1.2.3-54-g00ecf From e94a8d8b25060e0ab2a47215d773825e649a43aa Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 13:16:42 +0200 Subject: Debugging --- archinstall/lib/disk.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 9afece2e..5e16558e 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -452,6 +452,8 @@ class Filesystem(): self.blockdevice.partition[1].allow_formatting = True if encrypt_root_partition: + raise ValueError("moo") + exit(1) log(f"Marking partition {self.blockdevice.partition[1]} as encrypted.", level=LOG_LEVELS.Debug) self.blockdevice.partition[1].encrypted = True -- cgit v1.2.3-54-g00ecf From 0e269752479ff68fba73d4c04ea0f28718f945cd Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 15:55:36 +0200 Subject: Adding callstack to debug output for easier debugging. Removed hardcoded debug crash --- archinstall/lib/disk.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 5e16558e..3efee8b4 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -1,5 +1,5 @@ import glob, re, os, json, time, hashlib -import pathlib +import pathlib, traceback from collections import OrderedDict from .exceptions import DiskError from .general import * @@ -452,9 +452,9 @@ class Filesystem(): self.blockdevice.partition[1].allow_formatting = True if encrypt_root_partition: - raise ValueError("moo") - exit(1) log(f"Marking partition {self.blockdevice.partition[1]} as encrypted.", level=LOG_LEVELS.Debug) + log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) + self.blockdevice.partition[1].encrypted = True def add_partition(self, type, start, end, format=None): -- cgit v1.2.3-54-g00ecf From 39cb0b94d94c3f4fa0dec4002e8d9221fb28c753 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 15:57:31 +0200 Subject: Moved some debugging to catch more variable settings. --- archinstall/lib/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 3efee8b4..7bc09a0b 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -190,6 +190,7 @@ class Partition(): @encrypted.setter def encrypted(self, value :bool): log(f'Marking {self} as encrypted', level=LOG_LEVELS.Debug) + log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) self._encrypted = value @property @@ -453,7 +454,6 @@ class Filesystem(): if encrypt_root_partition: log(f"Marking partition {self.blockdevice.partition[1]} as encrypted.", level=LOG_LEVELS.Debug) - log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) self.blockdevice.partition[1].encrypted = True -- cgit v1.2.3-54-g00ecf From d26c1f820ddef17bfd9d1a536fbc8a068e815ff6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 16:11:30 +0200 Subject: Toned down the debugging a bit. --- archinstall/lib/disk.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 7bc09a0b..0e42feca 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -189,8 +189,9 @@ class Partition(): @encrypted.setter def encrypted(self, value :bool): - log(f'Marking {self} as encrypted', level=LOG_LEVELS.Debug) - log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) + if value: + log(f'Marking {self} as encrypted: {value}', level=LOG_LEVELS.Debug) + log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) self._encrypted = value @property -- cgit v1.2.3-54-g00ecf From 5e9c973d42125bb809443670c1e30439e4b11b17 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 16:51:30 +0200 Subject: Added support for flushing a BlockDevice() cache after a partition has been formatted. This is to avoid internal confusion of which partitions are encrypted or not when going from Encrypted -> Un-encrypted setups. --- archinstall/lib/disk.py | 11 +++++++++-- archinstall/lib/luks.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 0e42feca..518c1503 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -107,7 +107,7 @@ class BlockDevice(): if part_id not in self.part_cache: ## TODO: Force over-write even if in cache? if part_id not in self.part_cache or self.part_cache[part_id].size != part['size']: - self.part_cache[part_id] = Partition(root_path + part_id, part_id=part_id, size=part['size']) + self.part_cache[part_id] = Partition(root_path + part_id, self, part_id=part_id, size=part['size']) return {k: self.part_cache[k] for k in sorted(self.part_cache)} @@ -133,9 +133,11 @@ class BlockDevice(): self.part_cache = OrderedDict() class Partition(): - def __init__(self, path, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): + def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): if not part_id: part_id = os.path.basename(path) + + self.block_device = block_device self.path = path self.part_id = part_id self.mountpoint = mountpoint @@ -192,6 +194,7 @@ class Partition(): if value: log(f'Marking {self} as encrypted: {value}', level=LOG_LEVELS.Debug) log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) + self._encrypted = value @property @@ -318,6 +321,10 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") + + if self.block_device: + self.block_device.flush_cache() + return True def find_parent_of(self, data, name, parent=None): diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py index 30c38ec8..19c21795 100644 --- a/archinstall/lib/luks.py +++ b/archinstall/lib/luks.py @@ -113,7 +113,7 @@ class luks2(): sys_command(f'/usr/bin/cryptsetup open {partition.path} {mountpoint} --key-file {os.path.abspath(key_file)} --type luks2') if os.path.islink(f'/dev/mapper/{mountpoint}'): self.mapdev = f'/dev/mapper/{mountpoint}' - unlocked_partition = Partition(self.mapdev, encrypted=True, filesystem=get_filesystem_type(self.mapdev), autodetect_filesystem=False) + unlocked_partition = Partition(self.mapdev, None, encrypted=True, filesystem=get_filesystem_type(self.mapdev), autodetect_filesystem=False) unlocked_partition.allow_formatting = self.partition.allow_formatting return unlocked_partition -- cgit v1.2.3-54-g00ecf From f3907310e3fbbc07ad31f3558279cd73ba774472 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 16:59:09 +0200 Subject: Allowing individual partitions safety checks to rely on the parent blockdevice keep_partitions status. --- archinstall/lib/disk.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 518c1503..d6d28935 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -237,6 +237,9 @@ class Partition(): return True if files > 0 else False def safe_to_format(self): + if self.block_device and self.block_device.keep_partitions is True: + return True + if self.allow_formatting is False: log(f"Partition {self} is not marked for formatting.", level=LOG_LEVELS.Debug) return False -- cgit v1.2.3-54-g00ecf From a0980afff1d2458d348e144cb0d8351f862564c1 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:32:48 +0200 Subject: Experimenting with carrying over flags across cache flush. This to solve issues when flush is cleared and target mountpoints gets lost, making it impossible to do .find_mountpoint('/') later on for instance. --- archinstall/lib/disk.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index d6d28935..84a4ff37 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -130,7 +130,20 @@ class BlockDevice(): return False def flush_cache(self): + old_partitions = {**self.partitions} + self.part_cache = OrderedDict() + # Trigger a refresh of the cache + if len(self.partitions): + pass + + # Carry over any flags from the previous partitions + for partition in old_partitions: + if partition in self.part_cache: + if self.part_cache[partition].size == old_partitions[partition].size and \ + self.part_cache[partition].filesystem == old_partitions[partition].filesystem: + print('Carrying over', self.part_cache[partition].target_mountpoint) + self.part_cache[partition].target_mountpoint = old_partitions[partition].target_mountpoint class Partition(): def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): @@ -237,7 +250,9 @@ class Partition(): return True if files > 0 else False def safe_to_format(self): - if self.block_device and self.block_device.keep_partitions is True: + if self.block_device and self.block_device.keep_partitions is False: + # If we don't intend to keep any partitions on the parent block device + # We're good to format. return True if self.allow_formatting is False: @@ -325,6 +340,7 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") + # self.encrypted = False if self.filesystem != 'crypto_LUKS' else True if self.block_device: self.block_device.flush_cache() -- cgit v1.2.3-54-g00ecf From 512f0327f0d5eb9e507050ff9a4325e9728df705 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:34:13 +0200 Subject: Experimenting with cache, carrying over .allow_formatting --- archinstall/lib/disk.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 84a4ff37..3e512034 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -142,8 +142,9 @@ class BlockDevice(): if partition in self.part_cache: if self.part_cache[partition].size == old_partitions[partition].size and \ self.part_cache[partition].filesystem == old_partitions[partition].filesystem: - print('Carrying over', self.part_cache[partition].target_mountpoint) + print('Carrying over', self.part_cache[partition].target_mountpoint, self.part_cache[partition].allow_formatting) self.part_cache[partition].target_mountpoint = old_partitions[partition].target_mountpoint + self.part_cache[partition].allow_formatting = old_partitions[partition].allow_formatting class Partition(): def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): -- cgit v1.2.3-54-g00ecf From a29bd759548c02c609aa43d9536475b1259a70f9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:46:07 +0200 Subject: Removing a flush of the cache that was excessive. --- archinstall/lib/disk.py | 25 ++----------------------- examples/guided.py | 8 ++++---- 2 files changed, 6 insertions(+), 27 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 3e512034..4e70a4a5 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -130,21 +130,7 @@ class BlockDevice(): return False def flush_cache(self): - old_partitions = {**self.partitions} - self.part_cache = OrderedDict() - # Trigger a refresh of the cache - if len(self.partitions): - pass - - # Carry over any flags from the previous partitions - for partition in old_partitions: - if partition in self.part_cache: - if self.part_cache[partition].size == old_partitions[partition].size and \ - self.part_cache[partition].filesystem == old_partitions[partition].filesystem: - print('Carrying over', self.part_cache[partition].target_mountpoint, self.part_cache[partition].allow_formatting) - self.part_cache[partition].target_mountpoint = old_partitions[partition].target_mountpoint - self.part_cache[partition].allow_formatting = old_partitions[partition].allow_formatting class Partition(): def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): @@ -341,9 +327,7 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - # self.encrypted = False if self.filesystem != 'crypto_LUKS' else True - if self.block_device: - self.block_device.flush_cache() + self.encrypted = False if self.filesystem != 'crypto_LUKS' else True return True @@ -460,7 +444,7 @@ class Filesystem(): """ return self.raw_parted(string).exit_code - def use_entire_disk(self, root_filesystem_type='ext4', encrypt_root_partition=True): + def use_entire_disk(self, root_filesystem_type='ext4'): log(f"Using and formatting the entire {self.blockdevice}.", level=LOG_LEVELS.Debug) self.add_partition('primary', start='1MiB', end='513MiB', format='fat32') self.set_name(0, 'EFI') @@ -480,11 +464,6 @@ class Filesystem(): self.blockdevice.partition[0].allow_formatting = True self.blockdevice.partition[1].allow_formatting = True - if encrypt_root_partition: - log(f"Marking partition {self.blockdevice.partition[1]} as encrypted.", level=LOG_LEVELS.Debug) - - self.blockdevice.partition[1].encrypted = True - def add_partition(self, type, start, end, format=None): log(f'Adding partition to {self.blockdevice}', level=LOG_LEVELS.Info) diff --git a/examples/guided.py b/examples/guided.py index 92331450..71e1e01d 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -247,10 +247,10 @@ def perform_installation_steps(): with archinstall.Filesystem(archinstall.arguments['harddrive'], archinstall.GPT) as fs: # Wipe the entire drive if the disk flag `keep_partitions`is False. if archinstall.arguments['harddrive'].keep_partitions is False: - fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs'), - encrypt_root_partition=archinstall.arguments.get('!encryption-password', False)) - # Otherwise, check if encryption is desired and mark the root partition as encrypted. - elif archinstall.arguments.get('!encryption-password', None): + fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs')) + + # Check if encryption is desired and mark the root partition as encrypted. + if archinstall.arguments.get('!encryption-password', None): root_partition = fs.find_partition('/') root_partition.encrypted = True -- cgit v1.2.3-54-g00ecf From 0c86440e2e63c5e66e64679e79ff675b9cc3f1dd Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:47:34 +0200 Subject: Rolling back change to check parent blockdevice for safe formatting, it would wipe the boot partition if the boot partition for multiple drives was shared on the specific drive. --- archinstall/lib/disk.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 4e70a4a5..f0651685 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -237,11 +237,6 @@ class Partition(): return True if files > 0 else False def safe_to_format(self): - if self.block_device and self.block_device.keep_partitions is False: - # If we don't intend to keep any partitions on the parent block device - # We're good to format. - return True - if self.allow_formatting is False: log(f"Partition {self} is not marked for formatting.", level=LOG_LEVELS.Debug) return False -- cgit v1.2.3-54-g00ecf From 1b903550b588d1ade90eae034b757e2950398550 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:53:30 +0200 Subject: Reworking cache logic to not loose .encrypted flag on partitions after flushing cache. --- archinstall/lib/disk.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index f0651685..18006311 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,7 +322,8 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - self.encrypted = False if self.filesystem != 'crypto_LUKS' else True + if get_filesystem_type(path) == 'crypto_LUKS': + self.encrypted = True return True -- cgit v1.2.3-54-g00ecf From 8c8a441c2627a180671eb7fcd95b3a0f8d0a102e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 18:10:02 +0200 Subject: Added some debugging. --- archinstall/lib/disk.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 18006311..23fbf621 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,7 +322,9 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - if get_filesystem_type(path) == 'crypto_LUKS': + print('Checking if encrypted:', path) + print('Also checking:', self.real_device) + if get_filesystem_type(path) == 'crypto_LUKS' or get_filesystem_type(self.real_device) == 'crypto_LUKS': self.encrypted = True return True -- cgit v1.2.3-54-g00ecf From a50aa59060591a121a7b58e58487b6a2840825f3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 18:11:46 +0200 Subject: Adding .encrypted logic after .format calls to correctly identify partitions as encrypted/not-encrypted. This after a .flush_cache has been called. --- archinstall/lib/disk.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 23fbf621..9ad49ac2 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,10 +322,10 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - print('Checking if encrypted:', path) - print('Also checking:', self.real_device) if get_filesystem_type(path) == 'crypto_LUKS' or get_filesystem_type(self.real_device) == 'crypto_LUKS': self.encrypted = True + else: + self.encrypted = False return True -- cgit v1.2.3-54-g00ecf From 151c90a56d2dbf4daa7edb5545d25e2484df08f7 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 18:12:05 +0200 Subject: Added some debugging. --- archinstall/lib/disk.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 9ad49ac2..0425321d 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,6 +322,8 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") + print('Checking if encrypted:', path) + print('Also checking:', self.real_device) if get_filesystem_type(path) == 'crypto_LUKS' or get_filesystem_type(self.real_device) == 'crypto_LUKS': self.encrypted = True else: -- cgit v1.2.3-54-g00ecf From b03de49f0f6d29ec8cb7588c2216eb70d523e74d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 18:17:09 +0200 Subject: Removed debugging and finalized fix. --- archinstall/lib/disk.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 0425321d..9ad49ac2 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,8 +322,6 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - print('Checking if encrypted:', path) - print('Also checking:', self.real_device) if get_filesystem_type(path) == 'crypto_LUKS' or get_filesystem_type(self.real_device) == 'crypto_LUKS': self.encrypted = True else: -- cgit v1.2.3-54-g00ecf From 82342a0e94ed6d591b9855db590719764e9cb460 Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Tue, 30 Mar 2021 16:12:52 +0200 Subject: Add range check to generic_select --- archinstall/lib/user_interaction.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index defc2cfc..b3e0b665 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -170,7 +170,10 @@ def generic_select(options, input_text="Select one of the above by index or abso if len(selected_option.strip()) <= 0: return None elif selected_option.isdigit(): - selected_option = options[int(selected_option)] + selected_option = int(selected_option) + if selected_option >= len(options): + raise RequirementError(f'Selected option "{selected_option}" is out of range') + selected_option = options[selected_option] elif selected_option in options: pass # We gave a correct absolute value else: -- cgit v1.2.3-54-g00ecf From 40dbb5791c4be60d671d0a4abd2e9ba70e11b896 Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Tue, 30 Mar 2021 16:24:48 +0200 Subject: Add range check to disk selection --- archinstall/lib/user_interaction.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index b3e0b665..80db7be1 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -198,7 +198,10 @@ def select_disk(dict_o_disks): print(f"{index}: {drive} ({dict_o_disks[drive]['size'], dict_o_disks[drive].device, dict_o_disks[drive]['label']})") drive = input('Select one of the above disks (by number or full path): ') if drive.isdigit(): - drive = dict_o_disks[drives[int(drive)]] + drive = int(drive) + if drive >= len(drives): + raise DiskError(f'Selected option "{drive}" is out of range') + drive = dict_o_disks[drives[drive]] elif drive in dict_o_disks: drive = dict_o_disks[drive] else: -- cgit v1.2.3-54-g00ecf From b974b93004efa9912e404f5d3fca7c44a58dc0e3 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 2 Apr 2021 10:08:16 +0530 Subject: fixed some issues with the changes --- archinstall/lib/disk.py | 7 ++----- archinstall/lib/installer.py | 12 +++++++++++- examples/guided.py | 8 +++++++- 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index fbc11ca3..8e9e0234 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -390,12 +390,9 @@ class Filesystem(): # TODO: # When instance of a HDD is selected, check all usages and gracefully unmount them # as well as close any crypto handles. - def __init__(self, blockdevice): + def __init__(self, blockdevice,mode): self.blockdevice = blockdevice - if hasUEFI(): - self.mode = GPT - else: - self.mode = MBR + self.mode = mode def __enter__(self, *args, **kwargs): if self.blockdevice.keep_partitions is False: diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index d161c3b7..492d7715 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1,4 +1,4 @@ -import os, stat, time, shutil, pathlib +import os, stat, time, shutil, pathlib, subprocess from .exceptions import * from .disk import * @@ -398,6 +398,16 @@ class Installer(): break raise RequirementError(f"Could not identify the UUID of {self.partition}, there for {self.mountpoint}/boot/loader/entries/arch.conf will be broken until fixed.") + elif bootloader == "grub-install": + if hasUEFI(): + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) + sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') + else: + root_device = subprocess.check_output(f'basename "$(readlink -f "/sys/class/block/{self.partition.path.strip("/dev/")}/..")',shell=True).decode().strip() + if root_device == "block": + root_device = f"{self.partition.path}" + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc /dev/{root_device}')) + sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: raise RequirementError(f"Unknown (or not yet implemented) bootloader added to add_bootloader(): {bootloader}") diff --git a/examples/guided.py b/examples/guided.py index 71e1e01d..f374a41c 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -1,5 +1,6 @@ import getpass, time, json, sys, signal, os import archinstall +from archinstall.lib.hardware import hasUEFI """ This signal-handler chain (and global variable) @@ -244,7 +245,12 @@ def perform_installation_steps(): Setup the blockdevice, filesystem (and optionally encryption). Once that's done, we'll hand over to perform_installation() """ - with archinstall.Filesystem(archinstall.arguments['harddrive'], archinstall.GPT) as fs: + # maybe we can ask the user what they would prefer on uefi systems? + if hasUEFI(): + mode = archinstall.GPT + else: + mode = archinstall.MBR + with archinstall.Filesystem(archinstall.arguments['harddrive'],mode) as fs: # Wipe the entire drive if the disk flag `keep_partitions`is False. if archinstall.arguments['harddrive'].keep_partitions is False: fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs')) -- cgit v1.2.3-54-g00ecf From 655ec06119ee67cbf58733f2f1902c606006bef9 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 2 Apr 2021 10:12:45 +0530 Subject: accidentlly called dict as function --- archinstall/lib/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 8e9e0234..fdc2fbc5 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -481,7 +481,7 @@ class Filesystem(): previous_partitions = self.blockdevice.partitions if self.mode == MBR: - if len(self.blockdevice.partitions())>3: + if len(self.blockdevice.partitions)>3: DiskError("Too many partitions on disk, MBR disks can only have 3 parimary partitions") if format: partitioning = self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0 -- cgit v1.2.3-54-g00ecf From 6b218e555be5860a00297be30da22a1c09944ed2 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 2 Apr 2021 10:16:48 +0530 Subject: changed __enter__ --- archinstall/lib/installer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 492d7715..1411688c 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -67,9 +67,11 @@ class Installer(): log(*args, level=level, **kwargs) def __enter__(self, *args, **kwargs): - self.partition.mount(self.mountpoint) - os.makedirs(f'{self.mountpoint}/boot', exist_ok=True) - self.boot_partition.mount(f'{self.mountpoint}/boot') + if hasUEFI(): + # on bios we don't have a boot partition + self.partition.mount(self.mountpoint) + os.makedirs(f'{self.mountpoint}/boot', exist_ok=True) + self.boot_partition.mount(f'{self.mountpoint}/boot') return self def __exit__(self, *args, **kwargs): -- cgit v1.2.3-54-g00ecf From b5e32f980a27f272c1e3c42969323dff82617a84 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 2 Apr 2021 10:28:04 +0530 Subject: added hardwareincompatibilty erros and updated readme --- README.md | 4 ++-- archinstall/lib/installer.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'archinstall') diff --git a/README.md b/README.md index a65e92fa..9e611dd6 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,10 @@ with archinstall.Filesystem(harddrive, archinstall.GPT) as fs: This installer will perform the following: * Prompt the user to select a disk and disk-password - * Proceed to wipe the selected disk with a `GPT` partition table. + * Proceed to wipe the selected disk with a `GPT` partition table on a UEFI system and MBR on a bios system. * Sets up a default 100% used disk with encryption. * Installs a basic instance of Arch Linux *(base base-devel linux linux-firmware btrfs-progs efibootmgr)* - * Installs and configures a bootloader to partition 0. + * Installs and configures a bootloader to partition 0 on uefi. on bios it sets the root to partition 0. * Install additional packages *(nano, wget, git)* * Installs a network-profile called [workstation](https://github.com/Torxed/archinstall/blob/master/profiles/workstation.json) *(more on network profiles in the docs)* diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 1411688c..e38860d3 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -331,6 +331,8 @@ class Installer(): self.log(f'Adding bootloader {bootloader} to {self.boot_partition}', level=LOG_LEVELS.Info) if bootloader == 'systemd-bootctl': + if not hasUEFI(): + raise HardwareIncompatibilityError # TODO: Ideally we would want to check if another config # points towards the same disk and/or partition. # And in which case we should do some clean up. -- cgit v1.2.3-54-g00ecf