Started work on BIOS support

This commit is contained in:
advaithm 2021-03-12 11:30:32 +05:30
parent e2aeb3a32f
commit 850fd2efa8
No known key found for this signature in database
GPG Key ID: E557E45E6DAFFC0C
3 changed files with 33 additions and 8 deletions

View File

@ -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:

View File

@ -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}")

View File

@ -11,7 +11,7 @@ archinstall.sys_command(f'cryptsetup close /dev/mapper/luksloop', suppress_error
harddrive = archinstall.all_disks()['/dev/sda']
disk_password = '1234'
with archinstall.Filesystem(harddrive, archinstall.GPT) as fs:
with archinstall.Filesystem(harddrive) as fs:
# Use the entire disk instead of setting up partitions on your own
fs.use_entire_disk('luks2')