Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall')
-rw-r--r--archinstall/__init__.py2
-rw-r--r--archinstall/lib/disk.py7
-rw-r--r--archinstall/lib/general.py5
-rw-r--r--archinstall/lib/hardware.py49
-rw-r--r--archinstall/lib/installer.py18
-rw-r--r--archinstall/lib/mirrors.py4
-rw-r--r--archinstall/lib/packages.py15
-rw-r--r--archinstall/lib/user_interaction.py13
8 files changed, 62 insertions, 51 deletions
diff --git a/archinstall/__init__.py b/archinstall/__init__.py
index 84595528..2eec1ce6 100644
--- a/archinstall/__init__.py
+++ b/archinstall/__init__.py
@@ -64,7 +64,7 @@ def initialize_arguments():
config[key] = val
config["script"] = args.script
if args.dry_run is not None:
- config["dry_run"] = args.dry_run
+ config["dry-run"] = args.dry_run
return config
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index e8deb619..c86bf7bc 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -667,6 +667,11 @@ class Partition:
raise DiskError(f"Could not format {path} with {filesystem} because: {handle.decode('UTF-8')}")
self.filesystem = filesystem
+ elif filesystem == 'ext2':
+ if (handle := SysCommand(f'/usr/bin/mkfs.ext2 -F {path}')).exit_code != 0:
+ raise DiskError(f'Could not format {path} with {filesystem} because: {b"".join(handle)}')
+ self.filesystem = 'ext2'
+
elif filesystem == 'xfs':
if (handle := SysCommand(f'/usr/bin/mkfs.xfs -f {path}')).exit_code != 0:
raise DiskError(f"Could not format {path} with {filesystem} because: {handle.decode('UTF-8')}")
@@ -909,6 +914,7 @@ class Filesystem:
if self.parted(parted_string):
start_wait = time.time()
+
while previous_partition_uuids == {partition.uuid for partition in self.blockdevice.partitions.values()}:
if time.time() - start_wait > 10:
raise DiskError(f"New partition never showed up after adding new partition on {self} (timeout 10 seconds).")
@@ -918,7 +924,6 @@ class Filesystem:
time.sleep(0.5) # Let the kernel catch up with quick block devices (nvme for instance)
return self.blockdevice.get_partition(uuid=(previous_partition_uuids ^ {partition.uuid for partition in self.blockdevice.partitions.values()}).pop())
-
def set_name(self, partition: int, name: str):
return self.parted(f'{self.blockdevice.device} name {partition + 1} "{name}"') == 0
diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py
index f0be7972..1e8fc837 100644
--- a/archinstall/lib/general.py
+++ b/archinstall/lib/general.py
@@ -100,10 +100,7 @@ class JsonEncoder:
elif isinstance(obj, (datetime, date)):
return obj.isoformat()
elif isinstance(obj, (list, set, tuple)):
- r = []
- for item in obj:
- r.append(json.loads(json.dumps(item, cls=JSON)))
- return r
+ return [json.loads(json.dumps(item, cls=JSON)) for item in obj]
else:
return obj
diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py
index a63155f5..56444eeb 100644
--- a/archinstall/lib/hardware.py
+++ b/archinstall/lib/hardware.py
@@ -1,7 +1,7 @@
import json
import os
-import subprocess
-from typing import Optional
+from pathlib import Path
+from typing import Iterator, Optional
from .general import SysCommand
from .networking import list_interfaces, enrich_iface_types
@@ -57,22 +57,33 @@ AVAILABLE_GFX_DRIVERS = {
"VMware / VirtualBox (open-source)": ["mesa", "xf86-video-vmware"],
}
+CPUINFO = Path("/proc/cpuinfo")
+
+
+def cpuinfo() -> Iterator[dict[str, str]]:
+ """Yields information about the CPUs of the system."""
+ cpu = {}
+
+ with CPUINFO.open() as file:
+ for line in file:
+ if not (line := line.strip()):
+ yield cpu
+ cpu = {}
+ continue
+
+ key, value = line.split(":", maxsplit=1)
+ cpu[key.strip()] = value.strip()
+
def has_wifi() -> bool:
return 'WIRELESS' in enrich_iface_types(list_interfaces().values()).values()
def has_amd_cpu() -> bool:
- if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode():
- return True
- return False
-
+ return any(cpu.get("vendor_id") == "AuthenticAMD" for cpu in cpuinfo())
def has_intel_cpu() -> bool:
- if subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode():
- return True
- return False
-
+ return any(cpu.get("vendor_id") == "GenuineIntel" for cpu in cpuinfo())
def has_uefi() -> bool:
return os.path.isdir('/sys/firmware/efi')
@@ -106,7 +117,7 @@ def cpu_vendor() -> Optional[str]:
for info in cpu_info:
if info.get('field', None) == "Vendor ID:":
return info.get('data', None)
- return None
+ return
def cpu_model() -> Optional[str]:
@@ -116,7 +127,7 @@ def cpu_model() -> Optional[str]:
for info in cpu_info:
if info.get('field', None) == "Model name:":
return info.get('data', None)
- return None
+ return
def sys_vendor() -> Optional[str]:
@@ -131,7 +142,10 @@ def product_name() -> Optional[str]:
def mem_info():
# This implementation is from https://stackoverflow.com/a/28161352
- return dict((i.split()[0].rstrip(':'), int(i.split()[1])) for i in open('/proc/meminfo').readlines())
+ return {
+ i.split()[0].rstrip(':'): int(i.split()[1])
+ for i in open('/proc/meminfo').readlines()
+ }
def mem_available() -> Optional[str]:
@@ -151,13 +165,6 @@ def virtualization() -> Optional[str]:
def is_vm() -> bool:
- try:
- # systemd-detect-virt issues a non-zero exit code if it is not on a virtual machine
- if b"none" not in b"".join(SysCommand("systemd-detect-virt")).lower():
- return True
- except:
- pass
-
- return False
+ return b"none" not in b"".join(SysCommand("systemd-detect-virt")).lower()
# TODO: Add more identifiers
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index 00d3a001..3efb0499 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -429,7 +429,7 @@ class Installer:
return True
- def add_bootloader(self, bootloader='systemd-bootctl'):
+ def add_bootloader(self, _device, bootloader='systemd-bootctl'):
for plugin in plugins.values():
if hasattr(plugin, 'on_add_bootloader'):
# Allow plugins to override the boot-loader handling.
@@ -523,7 +523,16 @@ class Installer:
self.helper_flags['bootloader'] = bootloader
elif bootloader == "grub-install":
- self.pacstrap('grub')
+ self.pacstrap('grub') # no need?
+
+ if real_device := self.detect_encryption(root_partition):
+ _file = "/etc/default/grub"
+ root_uuid = SysCommand(f"blkid -s UUID -o value {real_device.path}").decode().rstrip()
+ add_to_CMDLINE_LINUX = f"sed -i 's/GRUB_CMDLINE_LINUX=\"\"/GRUB_CMDLINE_LINUX=\"cryptdevice=UUID={root_uuid}:cryptlvm\"/'"
+ enable_CRYPTODISK = "sed -i 's/#GRUB_ENABLE_CRYPTODISK=y/GRUB_ENABLE_CRYPTODISK=y/'"
+
+ SysCommand(f"/usr/bin/arch-chroot {self.target} {add_to_CMDLINE_LINUX} {_file}")
+ SysCommand(f"/usr/bin/arch-chroot {self.target} {enable_CRYPTODISK} {_file}")
if has_uefi():
self.pacstrap('efibootmgr')
@@ -532,10 +541,7 @@ class Installer:
self.helper_flags['bootloader'] = True
return True
else:
- root_device = subprocess.check_output(f'basename "$(readlink -f /sys/class/block/{root_partition.path.replace("/dev/", "")}/..)"', shell=True).decode().strip()
- if root_device == "block":
- root_device = f"{root_partition.path}"
- o = b''.join(SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --target=i386-pc /dev/{root_device}'))
+ o = b''.join(SysCommand(f'/usr/bin/arch-chroot {self.target} grub-install --target=i386-pc --recheck {_device.path}'))
SysCommand('/usr/bin/arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg')
self.helper_flags['bootloader'] = True
else:
diff --git a/archinstall/lib/mirrors.py b/archinstall/lib/mirrors.py
index 95fb5ac6..1b62a61b 100644
--- a/archinstall/lib/mirrors.py
+++ b/archinstall/lib/mirrors.py
@@ -59,9 +59,7 @@ def filter_mirrors_by_region(regions, destination='/etc/pacman.d/mirrorlist', so
:param regions: A series of country codes separated by `,`. For instance `SE,US` for sweden and United States.
:type regions: str
"""
- region_list = []
- for region in regions.split(','):
- region_list.append(f'country={region}')
+ region_list = [f'country={region}' for region in regions.split(',')]
response = urllib.request.urlopen(urllib.request.Request(f"https://archlinux.org/mirrorlist/?{'&'.join(region_list)}&protocol=https&protocol=http&ip_version=4&ip_version=6&use_mirror_status=on'", headers={'User-Agent': 'ArchInstall'}))
new_list = response.read().replace(b"#Server", b"Server")
diff --git a/archinstall/lib/packages.py b/archinstall/lib/packages.py
index 0ea195d2..0178d257 100644
--- a/archinstall/lib/packages.py
+++ b/archinstall/lib/packages.py
@@ -46,10 +46,7 @@ def find_packages(*names):
The function itself is rather slow, so consider not sending to
many packages to the search query.
"""
- result = {}
- for package in names:
- result[package] = find_package(package)
- return result
+ return {package: find_package(package) for package in names}
def validate_package_list(packages: list):
@@ -57,11 +54,11 @@ def validate_package_list(packages: list):
Validates a list of given packages.
Raises `RequirementError` if one or more packages are not found.
"""
- invalid_packages = []
- for package in packages:
- if not find_package(package)['results'] and not find_group(package):
- invalid_packages.append(package)
-
+ invalid_packages = [
+ package
+ for package in packages
+ if not find_package(package)['results'] and not find_group(package)
+ ]
if invalid_packages:
raise RequirementError(f"Invalid package names: {invalid_packages}")
diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py
index dadc111f..b017e41a 100644
--- a/archinstall/lib/user_interaction.py
+++ b/archinstall/lib/user_interaction.py
@@ -406,13 +406,13 @@ def ask_to_configure_network():
# {MAC: Ifname}
interfaces = {
'ISO-CONFIG': 'Copy ISO network configuration to installation',
- 'NetworkManager': 'Use NetworkManager to control and manage your internet connection',
+ 'NetworkManager': 'Use NetworkManager (necessary to configure internet graphically in GNOME and KDE)',
**list_interfaces()
}
nic = generic_select(interfaces, "Select one network interface to configure (leave blank to skip): ")
if nic and nic != 'Copy ISO network configuration to installation':
- if nic == 'Use NetworkManager to control and manage your internet connection':
+ if nic == 'Use NetworkManager (necessary to configure internet graphically in GNOME and KDE)':
return {'nic': nic, 'NetworkManager': True}
# Current workaround:
@@ -933,7 +933,7 @@ def select_driver(options=AVAILABLE_GFX_DRIVERS):
"""
drivers = sorted(list(options))
-
+
if drivers:
arguments = storage.get('arguments', {})
if has_amd_graphics():
@@ -943,11 +943,12 @@ def select_driver(options=AVAILABLE_GFX_DRIVERS):
if has_nvidia_graphics():
print('For the best compatibility with your Nvidia hardware, you may want to use the Nvidia proprietary driver.')
- arguments['gfx_driver'] = generic_select(drivers, input_text="Select a graphics driver or leave blank to install all open-source drivers: ")
-
+ if not arguments.get('gfx_driver', None):
+ arguments['gfx_driver'] = generic_select(drivers, input_text="Select a graphics driver or leave blank to install all open-source drivers: ")
+
if arguments.get('gfx_driver', None) is None:
arguments['gfx_driver'] = "All open-source (default)"
-
+
return options.get(arguments.get('gfx_driver'))
raise RequirementError("Selecting drivers require a least one profile to be given as an option.")