Skip to content

Commit

Permalink
buildextend-live: add readonly kargs file for 'coreos-installer iso k…
Browse files Browse the repository at this point in the history
…arg reset'

Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
  • Loading branch information
nikita-dubrovskii committed Dec 11, 2020
1 parent 5553a85 commit 7f624b5
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/cmd-buildextend-live
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def generate_iso():
print(f'Substituting ISO kernel arguments: {kargs}')

files_with_karg_embed_areas = {}
cmdline = ''
karg_embed_area_length = 0
# Grab all the contents from the live dir from the configs
for srcdir, _, filenames in os.walk(srcdir_prefix):
Expand All @@ -341,6 +342,12 @@ def generate_iso():
buf = newbuf
karg_area_end = re.search(r'(#+) COREOS_KARG_EMBED_AREA\n', buf)
if karg_area_end is not None:
file_kargs = buf[karg_area_start.start():karg_area_end.start()]
if len(cmdline) == 0:
cmdline = file_kargs
elif cmdline != file_kargs:
raise Exception(f'Default cmdline is different: "{cmdline}" != "{file_kargs}"')

length = karg_area_end.start() + len(karg_area_end[1]) - karg_area_start.start()
files_with_karg_embed_areas[filename] = karg_area_start.start()
if karg_embed_area_length == 0:
Expand All @@ -352,6 +359,9 @@ def generate_iso():
shutil.copystat(srcfile, dstfile)
print(f'{srcfile} -> {dstfile}')

with open(os.path.join(tmpisoroot, '.cmdline'), 'w') as fh:
fh.write(cmdline)

# These sections are based on lorax templates
# see https://github.com/weldr/lorax/tree/master/share/templates.d/99-generic

Expand Down Expand Up @@ -526,8 +536,8 @@ def generate_iso():
# coreos-installer side first
INITRDFMT = '<8s2Q'
assert struct.calcsize(INITRDFMT) == 24
KARGSFMT = f"<8s{MAX_KARG_FILES+1}Q" # +1 for area length
assert struct.calcsize(KARGSFMT) == 64
KARGSFMT = f"<8s{MAX_KARG_FILES+1+1}Q" # +1 for area length and +1 for offset to default read-only '.cmdline'
assert struct.calcsize(KARGSFMT) == 72

# Start of the Ignition padding within the ISO
offset = file_offset_in_iso(isoinfo, ignition_img)
Expand All @@ -540,11 +550,14 @@ def generate_iso():
# Write header at the end of the System Area
isofh.seek(ISO_SYSTEM_AREA_SIZE - (struct.calcsize(INITRDFMT) +
struct.calcsize(KARGSFMT)))
offsets = [0] * MAX_KARG_FILES

offsets = [0] * (MAX_KARG_FILES + 1) # +1 for offset to default
# This is ours default read-only '.cmdline' file, which is used for `coreos-installer iso kargs reset ISO`
offsets[0] = file_offset_in_iso(isoinfo, '.cmdline')

for i, fn in enumerate(files_with_karg_embed_areas):
offset_in_file = files_with_karg_embed_areas[fn]
offsets[i] = file_offset_in_iso(isoinfo, fn) + offset_in_file
offsets[i + 1] = file_offset_in_iso(isoinfo, fn) + offset_in_file
isofh.write(struct.pack(KARGSFMT, b'corekarg', karg_embed_area_length, *offsets))
# Magic number + offset + length
isofh.write(struct.pack(INITRDFMT, b'coreiso+', offset, initrd_ignition_padding))
Expand Down

0 comments on commit 7f624b5

Please sign in to comment.