Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-09-06 15:54:52 +0200
committerGitHub <noreply@github.com>2021-09-06 15:54:52 +0200
commit1030bd19c58d6587c8c49eb015c78e488a49425e (patch)
tree9c6915a162048a52a66fa661b2d9d4a44c6db323 /archinstall/lib
parenta5a56728f155f689bed5826bbd30532a56450cf3 (diff)
parent40cd8011847e21f5116c49aaff0336a89988eb92 (diff)
Merge branch 'master' into native_cpu_detection
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/disk.py37
-rw-r--r--archinstall/lib/general.py5
-rw-r--r--archinstall/lib/hardware.py20
-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
7 files changed, 60 insertions, 52 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index de39bafd..17ffe762 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -347,6 +347,11 @@ class Partition:
raise DiskError(f'Could not format {path} with {filesystem} because: {b"".join(handle)}')
self.filesystem = 'ext4'
+ 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: {b"".join(handle)}')
@@ -518,12 +523,24 @@ class Filesystem:
self.blockdevice.partition[0].allow_formatting = True
self.blockdevice.partition[1].allow_formatting = True
else:
- # we don't need a seprate boot partition it would be a waste of space
- self.add_partition('primary', start='1MB', end='100%')
- self.blockdevice.partition[0].filesystem = root_filesystem_type
- log(f"Set the root partition {self.blockdevice.partition[0]} to use filesystem {root_filesystem_type}.", level=logging.DEBUG)
- self.blockdevice.partition[0].target_mountpoint = '/'
+ if not self.parted_mklabel(self.blockdevice.device, "msdos"):
+ raise KeyError(f"Could not create a MSDOS label on {self}")
+
+ self.add_partition('primary', start='1MiB', end='513MiB', partition_format='ext4')
+ self.set(0, 'boot on')
+ self.add_partition('primary', start='513MiB', end='100%')
+
+ self.blockdevice.partition[0].filesystem = 'ext4' # TODO: Up for debate weither or not this should be user-supplied: https://github.com/archlinux/archinstall/pull/595/files
+ self.blockdevice.partition[1].filesystem = root_filesystem_type
+
+ log(f"Set the boot partition {self.blockdevice.partition[0]} to use filesystem {'ext4'}.", level=logging.DEBUG)
+ log(f"Set the root partition {self.blockdevice.partition[1]} to use filesystem {root_filesystem_type}.", level=logging.DEBUG)
+
+ self.blockdevice.partition[0].target_mountpoint = '/boot'
+ self.blockdevice.partition[1].target_mountpoint = '/'
+
self.blockdevice.partition[0].allow_formatting = True
+ self.blockdevice.partition[1].allow_formatting = True
def add_partition(self, partition_type, start, end, partition_format=None):
log(f'Adding partition to {self.blockdevice}', level=logging.INFO)
@@ -531,7 +548,7 @@ class Filesystem:
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")
+ DiskError("Too many partitions on disk, MBR disks can only have 3 primary partitions")
if partition_format:
partitioning = self.parted(f'{self.blockdevice.device} mkpart {partition_type} {partition_format} {start} {end}') == 0
else:
@@ -539,11 +556,9 @@ class Filesystem:
if partitioning:
start_wait = time.time()
- while previous_partitions == self.blockdevice.partitions:
- time.sleep(0.025) # Let the new partition come up in the kernel
- if time.time() - start_wait > 10:
- raise DiskError(f"New partition never showed up after adding new partition on {self} (timeout 10 seconds).")
-
+ time.sleep(0.025) # Let the new partition come up in the kernel
+ if time.time() - start_wait > 20:
+ raise DiskError(f"New partition never showed up after adding new partition on {self} (timeout 10 seconds).")
return True
def set_name(self, partition: int, name: str):
diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py
index b9dc66ab..5200033a 100644
--- a/archinstall/lib/general.py
+++ b/archinstall/lib/general.py
@@ -98,10 +98,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 1299a6b4..56444eeb 100644
--- a/archinstall/lib/hardware.py
+++ b/archinstall/lib/hardware.py
@@ -82,11 +82,9 @@ def has_wifi() -> bool:
def has_amd_cpu() -> bool:
return any(cpu.get("vendor_id") == "AuthenticAMD" for cpu in cpuinfo())
-
def has_intel_cpu() -> bool:
return any(cpu.get("vendor_id") == "GenuineIntel" for cpu in cpuinfo())
-
def has_uefi() -> bool:
return os.path.isdir('/sys/firmware/efi')
@@ -119,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]:
@@ -129,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]:
@@ -144,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]:
@@ -164,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 da6f6a9b..25b5331a 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -409,7 +409,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.
@@ -500,7 +500,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')
@@ -509,10 +518,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 3c1ba04f..cebb2775 100644
--- a/archinstall/lib/user_interaction.py
+++ b/archinstall/lib/user_interaction.py
@@ -388,13 +388,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:
@@ -700,7 +700,7 @@ def select_driver(options=AVAILABLE_GFX_DRIVERS):
"""
drivers = sorted(list(options))
-
+
if drivers:
arguments = storage.get('arguments', {})
if has_amd_graphics():
@@ -710,11 +710,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.")