Reworked the mkinitcpio configuration to be more robust according to the logic behind #91 and in prep for #145. Also in prep for #124 the lookup of partitions have been prepared here. We now need a reverse-lookup function.
This commit is contained in:
parent
e717a72a10
commit
08cf788eaa
|
|
@ -34,28 +34,21 @@ class Installer():
|
||||||
:type hostname: str, optional
|
:type hostname: str, optional
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, target, *, base_packages='base base-devel linux linux-firmware efibootmgr', logdir=None, logfile=None):
|
def __init__(self, target, *, base_packages='base base-devel linux linux-firmware efibootmgr'):
|
||||||
self.target = target
|
self.target = target
|
||||||
self.init_time = time.strftime('%Y-%m-%d_%H-%M-%S')
|
self.init_time = time.strftime('%Y-%m-%d_%H-%M-%S')
|
||||||
self.milliseconds = int(str(time.time()).split('.')[1])
|
self.milliseconds = int(str(time.time()).split('.')[1])
|
||||||
|
|
||||||
if logdir:
|
|
||||||
storage['LOG_PATH'] = logdir
|
|
||||||
if logfile:
|
|
||||||
storage['LOG_FILE'] = logfile
|
|
||||||
|
|
||||||
self.helper_flags = {
|
self.helper_flags = {
|
||||||
'bootloader' : False,
|
|
||||||
'base' : False,
|
'base' : False,
|
||||||
'user' : False # Root counts as a user, if additional users are skipped.
|
'bootloader' : False
|
||||||
}
|
}
|
||||||
|
|
||||||
self.base_packages = base_packages.split(' ') if type(base_packages) is str else base_packages
|
self.base_packages = base_packages.split(' ') if type(base_packages) is str else base_packages
|
||||||
self.post_base_install = []
|
self.post_base_install = []
|
||||||
storage['session'] = self
|
|
||||||
|
|
||||||
self.partition = partition
|
storage['session'] = self
|
||||||
self.boot_partition = boot_partition
|
self.partitions = get_partitions_in_use(self.target)
|
||||||
|
|
||||||
def log(self, *args, level=LOG_LEVELS.Debug, **kwargs):
|
def log(self, *args, level=LOG_LEVELS.Debug, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
@ -65,9 +58,6 @@ class Installer():
|
||||||
log(*args, level=level, **kwargs)
|
log(*args, level=level, **kwargs)
|
||||||
|
|
||||||
def __enter__(self, *args, **kwargs):
|
def __enter__(self, *args, **kwargs):
|
||||||
self.partition.mount(self.mountpoint)
|
|
||||||
os.makedirs(f'{self.mountpoint}/boot', exist_ok=True)
|
|
||||||
self.boot_partition.mount(f'{self.mountpoint}/boot')
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, *args, **kwargs):
|
def __exit__(self, *args, **kwargs):
|
||||||
|
|
@ -272,18 +262,25 @@ class Installer():
|
||||||
## (encrypted partitions default to btrfs for now, so we need btrfs-progs)
|
## (encrypted partitions default to btrfs for now, so we need btrfs-progs)
|
||||||
## TODO: Perhaps this should be living in the function which dictates
|
## TODO: Perhaps this should be living in the function which dictates
|
||||||
## the partitioning. Leaving here for now.
|
## the partitioning. Leaving here for now.
|
||||||
if self.partition.filesystem == 'btrfs':
|
MODULES = []
|
||||||
#if self.partition.encrypted:
|
BINARIES = []
|
||||||
self.base_packages.append('btrfs-progs')
|
FILES = []
|
||||||
if self.partition.filesystem == 'xfs':
|
HOOKS = ["base", "udev", "autodetect", "keyboard", "keymap", "modconf", "block", "filesystems", "fsck"]
|
||||||
self.base_packages.append('xfsprogs')
|
|
||||||
if self.partition.filesystem == 'f2fs':
|
for partition in self.partitions:
|
||||||
self.base_packages.append('f2fs-tools')
|
if partition.filesystem == 'btrfs':
|
||||||
|
#if partition.encrypted:
|
||||||
|
self.base_packages.append('btrfs-progs')
|
||||||
|
if partition.filesystem == 'xfs':
|
||||||
|
self.base_packages.append('xfsprogs')
|
||||||
|
if partition.filesystem == 'f2fs':
|
||||||
|
self.base_packages.append('f2fs-tools')
|
||||||
|
|
||||||
self.pacstrap(self.base_packages)
|
self.pacstrap(self.base_packages)
|
||||||
self.helper_flags['base-strapped'] = True
|
self.helper_flags['base-strapped'] = True
|
||||||
#self.genfstab()
|
#self.genfstab()
|
||||||
|
|
||||||
with open(f"{self.mountpoint}/etc/fstab", "a") as fstab:
|
with open(f"{self.target}/etc/fstab", "a") as fstab:
|
||||||
fstab.write(
|
fstab.write(
|
||||||
"\ntmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0\n"
|
"\ntmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0\n"
|
||||||
) # Redundant \n at the start? who knows?
|
) # Redundant \n at the start? who knows?
|
||||||
|
|
@ -296,25 +293,21 @@ class Installer():
|
||||||
self.set_locale('en_US')
|
self.set_locale('en_US')
|
||||||
|
|
||||||
# TODO: Use python functions for this
|
# TODO: Use python functions for this
|
||||||
sys_command(f'/usr/bin/arch-chroot {self.mountpoint} chmod 700 /root')
|
sys_command(f'/usr/bin/arch-chroot {self.target} chmod 700 /root')
|
||||||
|
|
||||||
# Configure mkinitcpio to handle some specific use cases.
|
# Configure mkinitcpio to handle some specific use cases.
|
||||||
# TODO: Yes, we should not overwrite the entire thing, but for now this should be fine
|
|
||||||
# since we just installed the base system.
|
|
||||||
if self.partition.filesystem == 'btrfs':
|
if self.partition.filesystem == 'btrfs':
|
||||||
with open(f'{self.mountpoint}/etc/mkinitcpio.conf', 'w') as mkinit:
|
MODULES.append('btrfs')
|
||||||
mkinit.write('MODULES=(btrfs)\n')
|
BINARIES.append('/usr/bin/btrfs')
|
||||||
mkinit.write('BINARIES=(/usr/bin/btrfs)\n')
|
|
||||||
mkinit.write('FILES=()\n')
|
|
||||||
mkinit.write('HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems fsck)\n')
|
|
||||||
sys_command(f'/usr/bin/arch-chroot {self.mountpoint} mkinitcpio -p linux')
|
|
||||||
elif self.partition.encrypted:
|
elif self.partition.encrypted:
|
||||||
with open(f'{self.mountpoint}/etc/mkinitcpio.conf', 'w') as mkinit:
|
HOOKS.patch('encrypt', before='filesystems')
|
||||||
mkinit.write('MODULES=()\n')
|
|
||||||
mkinit.write('BINARIES=()\n')
|
with open(f'{self.target}/etc/mkinitcpio.conf', 'w') as mkinit:
|
||||||
mkinit.write('FILES=()\n')
|
mkinit.write(f"MODULES=({' '.join(MODULES)})\n")
|
||||||
mkinit.write('HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems fsck)\n')
|
mkinit.write(f"BINARIES=({' '.join(BINARIES)})\n")
|
||||||
sys_command(f'/usr/bin/arch-chroot {self.mountpoint} mkinitcpio -p linux')
|
mkinit.write(f"FILES=({' '.join(FILES)})\n")
|
||||||
|
mkinit.write(f"HOOKS=({' '.join(HOOKS)})\n")
|
||||||
|
sys_command(f'/usr/bin/arch-chroot {self.target} mkinitcpio -p linux')
|
||||||
|
|
||||||
self.helper_flags['base'] = True
|
self.helper_flags['base'] = True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue