-
Notifications
You must be signed in to change notification settings - Fork 109
/
org.osbuild.fix-bls
executable file
·45 lines (32 loc) · 1.22 KB
/
org.osbuild.fix-bls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python3
import glob
import json
import re
import sys
STAGE_DESC = "Fix paths in /boot/loader/entries"
STAGE_INFO = """
Fixes paths in /boot/loader/entries that have incorrect paths for /boot.
This happens because some boot loader config tools (e.g. grub2-mkrelpath)
examine /proc/self/mountinfo to find the "real" path to /boot, and find the
path to the osbuild tree - which won't be valid at boot time for this image.
This stage reads and (re)writes all .conf files in /boot/loader/entries.
"""
STAGE_OPTS = ""
def main(tree, _options):
"""Fix broken paths in /boot/loader/entries.
grub2-mkrelpath uses /proc/self/mountinfo to find the source of the file
system it is installed to. This breaks in a container, because we
bind-mount the tree from the host.
"""
path_re = re.compile(r"(/.*)+/boot")
for name in glob.glob(f"{tree}/boot/loader/entries/*.conf"):
with open(name) as f:
entry = f.read().splitlines(keepends=True)
with open(name, "w") as f:
for line in entry:
f.write(path_re.sub("/boot", line))
return 0
if __name__ == '__main__':
args = json.load(sys.stdin)
r = main(args["tree"], args["options"])
sys.exit(r)