Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds+github@gmail.com>2020-07-06 15:46:19 +0200
committerAnton Hvornum <anton.feeds+github@gmail.com>2020-07-06 15:46:19 +0200
commit94f8d90121a8bd51111ee6067a78f81282574414 (patch)
tree606d188d052b092c72e0055fd99297b9348372c7 /archinstall.py
parentf0bc987e1bea4d1243340be0e6dd1522ea2750ff (diff)
Added a PArtition() class that supports mounting and formatting. Also reworked the installation flow a bit to be a bit more clear while sacrificing some automation. Maybe I'll revert some changes and 'automatically' do certain things, but for now this shouldn't impact anyone to much
Diffstat (limited to 'archinstall.py')
-rw-r--r--archinstall.py52
1 files changed, 44 insertions, 8 deletions
diff --git a/archinstall.py b/archinstall.py
index c8df36c2..ce108d8b 100644
--- a/archinstall.py
+++ b/archinstall.py
@@ -5,17 +5,53 @@ from helpers.disk import *
from helpers.general import *
from helpers.user_interaction import *
-class HardDrive():
- def __init__(self, full_path:str, *args, **kwargs):
- if not stat.S_ISBLK(os.stat(full_path).st_mode):
- raise DiskError(f'Selected disk "{full_path}" is not a block device.')
-
-class installer():
- def __init__(self, partition, *, profile=None, hostname='ArchInstalled'):
+class Installer():
+ def __init__(self, partition, *, profile=None, mountpoint='/mnt', hostname='ArchInstalled'):
self.profile = profile
self.hostname = hostname
+ self.mountpoint = mountpoint
self.partition = partition
+ def __enter__(self, *args, **kwargs):
+ self.partition.mount(self.mountpoint)
+ return self
+
+ def __exit__(self, *args, **kwargs):
+ # b''.join(sys_command(f'sync')) # No need to, since the underlaying fs() object will call sync.
+ # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
+ if len(args) >= 2 and args[1]:
+ raise args[1]
+ return True
+
def minimal_installation(self):
- pass \ No newline at end of file
+ if (sync_mirrors := sys_command('/usr/bin/pacman -Syy')).exit_code == 0:
+ if (pacstrap := sys_command(f'/usr/bin/pacstrap {self.mountpoint} base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog')).exit_code == 0:
+ return True
+ else:
+ log(f'Could not strap in base: {pacstrap.exit_code}')
+ else:
+ log(f'Could not sync mirrors: {sync_mirrors.exit_code}')
+
+ def add_bootloader(self, partition):
+ os.makedirs(f'{self.mountpoint}/boot', exist_ok=True)
+ partition.mount(f'{self.mountpoint}/boot')
+ o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} bootctl --no-variables --path=/boot install'))
+
+ with open('/mnt/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('/mnt/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.
+ # UUID = simple_command(f"blkid -s PARTUUID -o value /dev/{os.path.basename(args['drive'])}{args['partitions']['2']}").decode('UTF-8').strip()
+ # entry.write('options root=PARTUUID={UUID} rw intel_pstate=no_hwp\n'.format(UUID=UUID))
+ UUID = b''.join(sys_command(f"ls -l /dev/disk/by-uuid/ | grep {os.path.basename(partition['path'])} | awk '{{print $9}}'")).decode('UTF-8').strip()
+ entry.write(f'options cryptdevice=UUID={UUID}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') \ No newline at end of file