Skip to content

Commit

Permalink
fixup! python: setup: arch: Switch to systemd-boot if necessary
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Chancellor <[email protected]>
  • Loading branch information
nathanchance committed Dec 3, 2024
1 parent 1b92018 commit 1786e74
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions python/setup/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from argparse import ArgumentParser
from collections import UserDict
import getpass
import json
import os
from pathlib import Path
import re
Expand Down Expand Up @@ -502,33 +503,33 @@ def switch_to_systemd_boot(dryrun=False):
if lib.setup.using_systemd_boot():
return

# Install systemd-boot to ESP
# Install systemd-boot to ESP, which will create /boot/loader and
# /boot/loader/entries.
if dryrun:
print('$ bootctl install')
print('$ bootctl install\n')
else:
subprocess.run(['bootctl', 'install'], check=True)

# Create initial loader.conf
loader_conf_txt = 'default linux.conf\ntimeout 3\n'
if dryrun:
print('$ mkdir /boot/loader')
print(f"$ echo '{loader_conf_txt}' > /boot/loader/loader.conf")
print(f"$ echo '{loader_conf_txt}' > /boot/loader/loader.conf\n")
else:
Path('/boot/loader').mkdir(exist_ok=True)
Path('/boot/loader/loader.conf').write_text(loader_conf_txt, encoding='utf-8')

# Get partition UUID and filesystem type of /
partuuid, fstype = subprocess.run(['findmnt', '-n', '-o', 'PARTUUID,FSTYPE', '/'],
capture_output=True,
check=True,
text=True).stdout.strip().split(' ')
findmnt_cmd = ['findmnt', '-J', '-n', '-o', 'FSROOT,FSTYPE,PARTUUID', '/']
findmnt_proc = subprocess.run(findmnt_cmd, capture_output=True, check=True, text=True)
findmnt = json.loads(findmnt_proc.stdout)['filesystems'][0]

# Default cmdline options
cmdline_options = CmdlineOptions({
'root': f"PARTUUID={partuuid}",
'rootfstype': fstype,
'root': f"PARTUUID={findmnt['partuuid']}",
'rootfstype': findmnt['fstype'],
'rw': None,
})
if findmnt['fstype'] == 'btrfs' and (subvol := findmnt['fsroot'].strip('/')):
cmdline_options['rootflags'] = f"subvol={subvol}"
cmdline_options.update(get_cmdline_additions())
# Copy over any cmdline options that we added in grub, as those might be
# necessary for the machine to work properly.
Expand All @@ -546,18 +547,20 @@ def switch_to_systemd_boot(dryrun=False):
cmdline_options.update(CmdlineOptions(match.groups()[0]))

# Create initial linux.conf
linux_conf_txt = (
'title Arch Linux (linux)\n'
'linux /vmlinuz-linux\n'
f"initrd /{UCODE_VENDOR}-ucode.img\n" if UCODE_VENDOR else '',
'initrd /initramfs-linux.img\n'
f"options {' '.join(sorted(cmdline_options))}\n",
)
initrds = ['initramfs-linux']
if not lib.setup.is_virtual_machine() and UCODE_VENDOR:
initrds.insert(0, f"{UCODE_VENDOR}-ucode")
linux_conf_parts = [
'title Arch Linux (linux)',
'linux /vmlinuz-linux',
*[f"initrd /{initrd}.img" for initrd in initrds],
f"options {cmdline_options}",
]
linux_conf_txt = f"{'\n'.join(linux_conf_parts)}\n"
if dryrun:
print('$ mkdir /boot/loader/entries')
print(f"$ echo '{linux_conf_txt}' > /boot/loader/entries/linux.conf")
print(f"$ echo '{linux_conf_txt}' > /boot/loader/entries/linux.conf\n")
print('$ rm -fr /boot/grub')
else:
Path('/boot/loader/entries').mkdir(exist_ok=True)
Path('/boot/loader/entries/linux.conf').write_text(linux_conf_txt, encoding='utf-8')

# Remove grub
Expand Down

0 comments on commit 1786e74

Please sign in to comment.