129
129
cmd += options.format(workdir=work_dir, serial_port=serial_port)
130
130
# Add install options if specified
131
131
if iso_path and kernel and kernel_opts:
132
initrd_path = os.path.join(work_dir, CASPER_INITRD)
132
initrd_path = os.path.join(work_dir, 'initrd.d', 'initrd')
133
133
kernel_path = os.path.join(work_dir, kernel)
134
134
cmd += QEMU_INSTALL_OPTS.format(
135
135
iso=iso_path, initrd=initrd_path, kernel=kernel_path,
232
232
def extract_kernel(iso_path, kernel_path, dst_path):
233
233
"""Extract kernel from iso to specified path."""
234
234
subprocess.check_call(
235
['bsdtar', 'xf', iso_path, '-C', dst_path, CASPER_INITRDLZ,
235
['bsdtar', 'xf', iso_path, '-C', dst_path, CASPER_INITRD,
313
313
:return: Path of initrd file with installer scripts added.
315
315
initrd_path = os.path.join(working_dir, CASPER_INITRD)
316
initrdlz_path = os.path.join(working_dir, CASPER_INITRDLZ)
317
initrd_work_dir = os.path.join(working_dir, 'initrd')
316
initrd_work_dir = os.path.join(working_dir, 'initrd.d')
317
my_initrd_path = os.path.join(initrd_work_dir, 'initrd')
318
318
# create dir to extract initrd, change to it and then extract files
319
319
os.mkdir(initrd_work_dir)
320
320
os.chdir(initrd_work_dir)
321
ps = subprocess.Popen(['xzcat', initrdlz_path], stdout=subprocess.PIPE)
322
subprocess.check_call(['cpio', '--quiet', '-id'], stdin=ps.stdout)
321
subprocess.check_call(['unmkinitramfs', initrd_path, os.getcwd()])
324
322
# copy the qemu scripts into initrd
325
copy_qemu_scripts_to_path(initrd_work_dir)
326
casper_prov = os.path.join(initrd_work_dir, 'qemu-casper-provision')
323
copy_qemu_scripts_to_path(os.path.join(initrd_work_dir, 'main'))
324
casper_prov = os.path.join(initrd_work_dir, 'main', 'qemu-casper-provision')
327
325
add_script_to_casper_setup(initrd_work_dir, casper_prov)
328
326
# create the preseed file
329
preseed_path = os.path.join(initrd_work_dir, PRESEED)
327
preseed_path = os.path.join(initrd_work_dir, 'main', PRESEED)
330
328
create_preseed(preseed_path, username, password, display_name)
331
329
# Copy all files back to the archive
332
with open(initrd_path, 'w') as initrd:
333
ps = subprocess.Popen(['find', '.'], stdout=subprocess.PIPE)
334
subprocess.check_call(
335
['cpio', '--quiet', '-o', '-H', 'newc'],
336
stdin=ps.stdout, stdout=initrd)
330
os.chdir(os.path.join(initrd_work_dir, 'main'))
331
pipe = pipes.Template()
332
pipe.prepend('find .', '.-')
333
pipe.append('cpio --quiet -o -H newc', '--')
334
initrd = os.path.join(initrd_work_dir, 'initrd')
335
if pipe.copy('/dev/null', initrd) != 0:
336
raise Exception('Failed to repack initrd')
337
return my_initrd_path
341
340
def add_script_to_casper_setup(initrd_path, script_path):
343
342
:param initrd_path: Path of initial ram disk to add the scripts.
344
343
:param script_path: Path of script file to add.
346
casper_dir = os.path.join(initrd_path, 'scripts', 'casper-bottom')
345
casper_dir = os.path.join(initrd_path, 'main', 'scripts', 'casper-bottom')
347
346
script_name = os.path.basename(script_path)
348
347
script_dst = os.path.join(casper_dir, script_name)
349
348
shutil.copy2(script_path, script_dst)