48 lines
1.6 KiB
Plaintext
48 lines
1.6 KiB
Plaintext
Incorporate prep.txt with config file?
|
|
should look something like this:
|
|
|
|
#!/usr/bin/env python
|
|
|
|
import os
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
|
|
esp = {'/dev/vdb': ('Arch (Fallback)', '/mnt/boot2'),
|
|
'/dev/vda': ('Arch', '/mnt/boot1')}
|
|
part = 1
|
|
|
|
for dev, (label, mnt) in esp.items():
|
|
grubdir = os.path.join(mnt, 'grub')
|
|
if os.path.isdir(grubdir):
|
|
shutil.rmtree(grubdir)
|
|
efi = subprocess.run(['efibootmgr'], stdout = subprocess.PIPE)
|
|
efi_lines = efi.stdout.decode('utf-8').strip().splitlines()
|
|
efi_entries = {}
|
|
for l in efi_lines:
|
|
i = l.split(None, 1)
|
|
k = i[1].strip()
|
|
v = re.sub(r'^Boot(?P<boot_id>[A-Fa-f0-9]+).*$', r'\g<boot_id>', i[0])
|
|
efi_entries[k] = v
|
|
boot_id = efi_entries.get(label)
|
|
if not boot_id:
|
|
print('Could not find {0}'.format(label))
|
|
else:
|
|
cmd = subprocess.run(['efibootmgr',
|
|
'-b', boot_id,
|
|
'-B'],
|
|
stdout = subprocess.PIPE)
|
|
cmd = subprocess.run(['grub-install',
|
|
'--boot-directory={0}'.format(mnt),
|
|
'--bootloader-id=Arch',
|
|
'--efi-directory={0}'.format(mnt),
|
|
'--target=x86_64-efi',
|
|
'--no-nvram',
|
|
'--recheck'])
|
|
cmd = subprocess.run(['efibootmgr',
|
|
'--create',
|
|
'--disk', dev,
|
|
'--part', str(part),
|
|
'--loader', '/EFI/Arch/grubx64.efi',
|
|
'--label', label])
|