Skip to content

Commit f5aa598

Browse files
buildextend-live: add readonly kargs file for 'coreos-installer iso karg reset'
Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
1 parent 5b7757d commit f5aa598

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/cmd-buildextend-live

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ def generate_iso():
318318
print(f'Substituting ISO kernel arguments: {kargs}')
319319

320320
files_with_karg_embed_areas = {}
321+
cmdline = ''
321322
karg_embed_area_length = 0
322323
# Grab all the contents from the live dir from the configs
323324
for srcdir, _, filenames in os.walk(srcdir_prefix):
@@ -341,6 +342,12 @@ def generate_iso():
341342
buf = newbuf
342343
karg_area_end = re.search(r'(#+) COREOS_KARG_EMBED_AREA\n', buf)
343344
if karg_area_end is not None:
345+
file_kargs = buf[karg_area_start.start():karg_area_end.start()]
346+
if len(cmdline) == 0:
347+
cmdline = file_kargs
348+
elif cmdline != file_kargs:
349+
raise Exception(f'Default cmdline is different: "{cmdline}" != "{file_kargs}"')
350+
344351
length = karg_area_end.start() + len(karg_area_end[1]) - karg_area_start.start()
345352
files_with_karg_embed_areas[filename] = karg_area_start.start()
346353
if karg_embed_area_length == 0:
@@ -352,6 +359,9 @@ def generate_iso():
352359
shutil.copystat(srcfile, dstfile)
353360
print(f'{srcfile} -> {dstfile}')
354361

362+
with open(os.path.join(tmpisoroot, '.cmdline'), 'w') as fh:
363+
fh.write(cmdline)
364+
355365
# These sections are based on lorax templates
356366
# see https://github.com/weldr/lorax/tree/master/share/templates.d/99-generic
357367

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

532542
# Start of the Ignition padding within the ISO
533543
offset = file_offset_in_iso(isoinfo, ignition_img)
@@ -540,11 +550,14 @@ def generate_iso():
540550
# Write header at the end of the System Area
541551
isofh.seek(ISO_SYSTEM_AREA_SIZE - (struct.calcsize(INITRDFMT) +
542552
struct.calcsize(KARGSFMT)))
543-
offsets = [0] * MAX_KARG_FILES
553+
554+
offsets = [0] * (MAX_KARG_FILES + 1) # +1 for offset to default
555+
# This is ours default read-only '.cmdline' file, which is used for `coreos-installer iso kargs reset ISO`
556+
offsets[0] = file_offset_in_iso(isoinfo, '.cmdline')
544557

545558
for i, fn in enumerate(files_with_karg_embed_areas):
546559
offset_in_file = files_with_karg_embed_areas[fn]
547-
offsets[i] = file_offset_in_iso(isoinfo, fn) + offset_in_file
560+
offsets[i + 1] = file_offset_in_iso(isoinfo, fn) + offset_in_file
548561
isofh.write(struct.pack(KARGSFMT, b'corekarg', karg_embed_area_length, *offsets))
549562
# Magic number + offset + length
550563
isofh.write(struct.pack(INITRDFMT, b'coreiso+', offset, initrd_ignition_padding))

0 commit comments

Comments
 (0)