Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/disk.py19
-rw-r--r--archinstall/lib/general.py4
-rw-r--r--archinstall/lib/hardware.py61
-rw-r--r--archinstall/lib/installer.py11
-rw-r--r--archinstall/lib/networking.py2
-rw-r--r--archinstall/lib/profiles.py12
-rw-r--r--archinstall/lib/user_interaction.py4
7 files changed, 93 insertions, 20 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index f4936d73..de39bafd 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -254,7 +254,8 @@ class Partition:
return None
def has_content(self):
- if not get_filesystem_type(self.path):
+ fs_type = get_filesystem_type(self.path)
+ if not fs_type or "swap" in fs_type:
return False
temporary_mountpoint = '/tmp/' + hashlib.md5(bytes(f"{time.time()}", 'UTF-8') + os.urandom(12)).hexdigest()
@@ -447,16 +448,16 @@ class Filesystem:
if self.blockdevice.keep_partitions is False:
log(f'Wiping {self.blockdevice} by using partition format {self.mode}', level=logging.DEBUG)
if self.mode == GPT:
- if self.raw_parted(f'{self.blockdevice.device} mklabel gpt').exit_code == 0:
+ if self.parted_mklabel(self.blockdevice.device, "gpt"):
self.blockdevice.flush_cache()
return self
else:
- raise DiskError('Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt')
+ raise DiskError('Problem setting the disk label type to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt')
elif self.mode == MBR:
- if SysCommand(f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos').exit_code == 0:
+ if self.parted_mklabel(self.blockdevice.device, "msdos"):
return self
else:
- raise DiskError('Problem setting the partition format to MBR:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos')
+ raise DiskError('Problem setting the disk label type to msdos:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos')
else:
raise DiskError(f'Unknown mode selected to format in: {self.mode}')
@@ -551,6 +552,14 @@ class Filesystem:
def set(self, partition: int, string: str):
return self.parted(f'{self.blockdevice.device} set {partition + 1} {string}') == 0
+ def parted_mklabel(self, device: str, disk_label: str):
+ # Try to unmount devices before attempting to run mklabel
+ try:
+ SysCommand(f'bash -c "umount {device}?"')
+ except:
+ pass
+ return self.raw_parted(f'{device} mklabel {disk_label}').exit_code == 0
+
def device_state(name, *args, **kwargs):
# Based out of: https://askubuntu.com/questions/528690/how-to-get-list-of-all-non-removable-disk-device-names-ssd-hdd-and-sata-ide-onl/528709#528709
diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py
index 9711382f..831b5451 100644
--- a/archinstall/lib/general.py
+++ b/archinstall/lib/general.py
@@ -13,7 +13,7 @@ from typing import Union
from .exceptions import *
from .output import log
-
+from .storage import storage
def gen_uid(entropy_length=256):
return hashlib.sha512(os.urandom(entropy_length)).hexdigest()
@@ -244,6 +244,8 @@ class SysCommandWorker:
if not self.pid:
try:
os.execve(self.cmd[0], self.cmd, {**os.environ, **self.environment_vars})
+ if storage['arguments'].get('debug'):
+ log(f"Executing: {self.cmd}", level=logging.DEBUG)
except FileNotFoundError:
log(f"{self.cmd[0]} does not exist.", level=logging.ERROR, fg="red")
self.exit_code = 1
diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py
index 6a3b166d..a63155f5 100644
--- a/archinstall/lib/hardware.py
+++ b/archinstall/lib/hardware.py
@@ -48,10 +48,12 @@ AVAILABLE_GFX_DRIVERS = {
"intel-media-driver",
"vulkan-intel",
],
- "Nvidia": {
- "open-source": ["mesa", "xf86-video-nouveau", "libva-mesa-driver"],
- "proprietary": ["nvidia"],
- },
+ "Nvidia (open-source)": [
+ "mesa",
+ "xf86-video-nouveau",
+ "libva-mesa-driver"
+ ],
+ "Nvidia (proprietary)": ["nvidia"],
"VMware / VirtualBox (open-source)": ["mesa", "xf86-video-vmware"],
}
@@ -79,22 +81,22 @@ def has_uefi() -> bool:
def graphics_devices() -> dict:
cards = {}
for line in SysCommand("lspci"):
- if b' VGA ' in line:
+ if b' VGA ' in line or b' 3D ' in line:
_, identifier = line.split(b': ', 1)
- cards[identifier.strip().lower().decode('UTF-8')] = line
+ cards[identifier.strip().decode('UTF-8')] = line
return cards
def has_nvidia_graphics() -> bool:
- return any('nvidia' in x for x in graphics_devices())
+ return any('nvidia' in x.lower() for x in graphics_devices())
def has_amd_graphics() -> bool:
- return any('amd' in x for x in graphics_devices())
+ return any('amd' in x.lower() for x in graphics_devices())
def has_intel_graphics() -> bool:
- return any('intel' in x for x in graphics_devices())
+ return any('intel' in x.lower() for x in graphics_devices())
def cpu_vendor() -> Optional[str]:
@@ -107,6 +109,47 @@ def cpu_vendor() -> Optional[str]:
return None
+def cpu_model() -> Optional[str]:
+ cpu_info_raw = SysCommand("lscpu -J")
+ cpu_info = json.loads(b"".join(cpu_info_raw).decode('UTF-8'))['lscpu']
+
+ for info in cpu_info:
+ if info.get('field', None) == "Model name:":
+ return info.get('data', None)
+ return None
+
+
+def sys_vendor() -> Optional[str]:
+ with open(f"/sys/devices/virtual/dmi/id/sys_vendor") as vendor:
+ return vendor.read().strip()
+
+
+def product_name() -> Optional[str]:
+ with open(f"/sys/devices/virtual/dmi/id/product_name") as product:
+ return product.read().strip()
+
+
+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())
+
+
+def mem_available() -> Optional[str]:
+ return mem_info()['MemAvailable']
+
+
+def mem_free() -> Optional[str]:
+ return mem_info()['MemFree']
+
+
+def mem_total() -> Optional[str]:
+ return mem_info()['MemTotal']
+
+
+def virtualization() -> Optional[str]:
+ return str(SysCommand("systemd-detect-virt")).strip('\r\n')
+
+
def is_vm() -> bool:
try:
# systemd-detect-virt issues a non-zero exit code if it is not on a virtual machine
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index c2db8337..da6f6a9b 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -2,8 +2,8 @@ from .disk import *
from .hardware import *
from .locale_helpers import verify_keyboard_layout, verify_x11_keyboard_layout
from .mirrors import *
-from .storage import storage
from .plugins import plugins
+from .storage import storage
from .user_interaction import *
# Any package that the Installer() is responsible for (optional and the default ones)
@@ -54,7 +54,6 @@ class Installer:
for kernel in kernels:
self.base_packages.append(kernel)
-
self.post_base_install = []
storage['session'] = self
@@ -442,6 +441,10 @@ class Installer:
# Fallback, try creating the boot loader without touching the EFI variables
SysCommand(f'/usr/bin/arch-chroot {self.target} bootctl --no-variables --path=/boot install')
+ # Ensure that the /boot/loader directory exists before we try to create files in it
+ if not os.path.exists(f'{self.target}/boot/loader'):
+ os.makedirs(f'{self.target}/boot/loader')
+
# Modify or create a loader.conf
if os.path.isfile(f'{self.target}/boot/loader/loader.conf'):
with open(f'{self.target}/boot/loader/loader.conf', 'r') as loader:
@@ -462,6 +465,10 @@ class Installer:
else:
loader.write(f"{line}\n")
+ # Ensure that the /boot/loader/entries directory exists before we try to create files in it
+ if not os.path.exists(f'{self.target}/boot/loader/entries'):
+ os.makedirs(f'{self.target}/boot/loader/entries')
+
for kernel in self.kernels:
# Setup the loader entry
with open(f'{self.target}/boot/loader/entries/{self.init_time}_{kernel}.conf', 'w') as entry:
diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py
index 0643c9cf..49970ec4 100644
--- a/archinstall/lib/networking.py
+++ b/archinstall/lib/networking.py
@@ -31,7 +31,7 @@ def list_interfaces(skip_loopback=True):
def check_mirror_reachable():
if (exit_code := SysCommand("pacman -Sy").exit_code) == 0:
return True
- elif exit_code == 256:
+ elif os.geteuid() != 0:
log("check_mirror_reachable() uses 'pacman -Sy' which requires root.", level=logging.ERROR, fg="red")
return False
diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py
index d4913e7e..8434a0ab 100644
--- a/archinstall/lib/profiles.py
+++ b/archinstall/lib/profiles.py
@@ -228,6 +228,18 @@ class Profile(Script):
# since developers like less code - omitting it should assume they want to present it.
return True
+ def get_profile_description(self):
+ with open(self.path, 'r') as source:
+ source_data = source.read()
+
+ if '__description__' in source_data:
+ with self.load_instructions(namespace=f"{self.namespace}.py") as imported:
+ if hasattr(imported, '__description__'):
+ return imported.__description__
+
+ # Default to this string if the profile does not have a description.
+ return "This profile does not have the __description__ attribute set."
+
@property
def packages(self) -> Optional[list]:
"""
diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py
index 79919658..b52267d9 100644
--- a/archinstall/lib/user_interaction.py
+++ b/archinstall/lib/user_interaction.py
@@ -575,11 +575,11 @@ def select_profile():
if len(shown_profiles) >= 1:
for index, profile in enumerate(shown_profiles):
- print(f"{index}: {profile}")
+ description = Profile(None, profile).get_profile_description()
+ print(f"{index}: {profile}: {description}")
print(' -- The above list is a set of pre-programmed profiles. --')
print(' -- They might make it easier to install things like desktop environments. --')
- print(' -- The desktop profile will let you select a DE/WM profile, e.g gnome, kde, sway --')
print(' -- (Leave blank and hit enter to skip this step and continue) --')
selected_profile = generic_select(actual_profiles_raw, 'Enter a pre-programmed profile name if you want to install one: ', options_output=False)