mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-14 23:35:24 +01:00
Add sysb and sysc scaffolding.
Now that we have the Linux Kernel built, we move to a full-disk (rather than initramfs) setup in sysc. However, we cannot assume the seed kernel has support for mounting hard drives. So, first we need to kexec into sysb, which is used as a jumping off point to create the hard drive for sysc. Additionally, since 2.6.16 does not have support for on-demand initramfs (initramfs must be built into kernel), we will have to rebuild the linux kernel within sysb without the initramfs. All of this process is not performed for chroot mode. Instead, we skip sysb and jump straight to sysc, copying over appropriate data. The python scripts have been changed slightly. Each sys* inherits SysGeneral, which contains various functions which are not specific to any sys* and simplifies those files. rootfs now also handles sysb and sysc. bootstrap.cfg also gives an indication whether we are running in a chroot to avoid attempting to kexec/mount within a chroot.
This commit is contained in:
parent
925ce198c1
commit
5c88f1c87f
75 changed files with 624 additions and 176 deletions
85
rootfs.py
85
rootfs.py
|
|
@ -10,6 +10,7 @@ you can run bootstap inside chroot.
|
|||
# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
|
||||
# SPDX-FileCopyrightText: 2021 Bastian Bittorf <bb@npl.de>
|
||||
# SPDX-FileCopyrightText: 2021 Melg Eight <public.melg8@gmail.com>
|
||||
# SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
|
||||
|
||||
import argparse
|
||||
import glob
|
||||
|
|
@ -18,7 +19,20 @@ import subprocess
|
|||
import shutil
|
||||
|
||||
from sysa import SysA
|
||||
from lib.utils import run
|
||||
from sysb import SysB
|
||||
from sysc import SysC
|
||||
from lib.utils import run, umount
|
||||
|
||||
def create_configuration_file(args):
|
||||
"""
|
||||
Creates bootstrap.cfg file which would contain options used to
|
||||
customize bootstrap.
|
||||
"""
|
||||
config_path = os.path.join('sysglobal', 'bootstrap.cfg')
|
||||
with open(config_path, "w") as config:
|
||||
config.write("FORCE_TIMESTAMPS=" + str(args.force_timestamps) + "\n")
|
||||
config.write("CHROOT=" + str(args.chroot) + "\n")
|
||||
config.write("DISK=hda1\n")
|
||||
|
||||
def main():
|
||||
"""
|
||||
|
|
@ -56,35 +70,17 @@ def main():
|
|||
if args.arch != "x86":
|
||||
raise ValueError("Only x86 is supported at the moment.")
|
||||
|
||||
system_a = SysA(arch=args.arch, preserve_tmp=args.preserve, tmpdir=args.tmpdir,
|
||||
force_timestamps=args.force_timestamps)
|
||||
initramfs_path = os.path.join(system_a.tmp_dir, "initramfs")
|
||||
create_configuration_file(args)
|
||||
|
||||
if not args.chroot:
|
||||
make_initramfs(system_a.tmp_dir, initramfs_path)
|
||||
system_b = SysB(arch=args.arch, preserve_tmp=args.preserve, tmpdir=args.tmpdir, chroot=args.chroot)
|
||||
system_a = SysA(arch=args.arch, preserve_tmp=args.preserve, tmpdir=args.tmpdir, chroot=args.chroot, sysb_tmp=system_b.tmp_dir)
|
||||
system_c = SysC(arch=args.arch, preserve_tmp=args.preserve, tmpdir=args.tmpdir, chroot=args.chroot)
|
||||
|
||||
bootstrap(args, system_a.tmp_dir, initramfs_path)
|
||||
bootstrap(args, system_a, system_b, system_c)
|
||||
|
||||
def make_initramfs(tmp_dir, initramfs_path):
|
||||
"""Package binary bootstrap seeds and sources into initramfs."""
|
||||
file_list = glob.glob(os.path.join(tmp_dir, '**'), recursive=True)
|
||||
|
||||
# Use built-in removeprefix once we can use Python 3.9
|
||||
def remove_prefix(text, prefix):
|
||||
if text.startswith(prefix):
|
||||
return text[len(prefix):]
|
||||
return text # or whatever
|
||||
|
||||
file_list = [remove_prefix(f, tmp_dir + os.sep) for f in file_list]
|
||||
|
||||
with open(initramfs_path, "w") as initramfs:
|
||||
cpio = subprocess.Popen(["cpio", "--format", "newc", "--create", "--directory", tmp_dir],
|
||||
stdin=subprocess.PIPE, stdout=initramfs)
|
||||
cpio.communicate(input='\n'.join(file_list).encode())
|
||||
|
||||
def bootstrap(args, tmp_dir, initramfs_path):
|
||||
def bootstrap(args, system_a, system_b, system_c):
|
||||
"""Kick off bootstrap process."""
|
||||
print("Bootstrapping %s" % (args.arch))
|
||||
print("Bootstrapping %s -- SysA" % (args.arch))
|
||||
if args.chroot:
|
||||
find_chroot = """
|
||||
import shutil
|
||||
|
|
@ -92,11 +88,19 @@ print(shutil.which('chroot'))
|
|||
"""
|
||||
chroot_binary = run('sudo', 'python3', '-c', find_chroot,
|
||||
capture_output=True).stdout.decode().strip()
|
||||
# sysa
|
||||
init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', args.arch, 'kaem-optional-seed')
|
||||
run('sudo', 'env', '-i', 'PATH=/bin', chroot_binary, tmp_dir, init)
|
||||
return
|
||||
run('sudo', 'env', '-i', 'PATH=/bin', chroot_binary, system_a.tmp_dir, init)
|
||||
# Perform the steps for sysa -> sysc transition that would occur within
|
||||
# qemu if we were running not in chroot
|
||||
# We skip sysb as that is only pertinent to "hardware" (not chroot)
|
||||
# system_c.chroot_transition(system_a.tmp_dir)
|
||||
# sysc
|
||||
print("Bootstrapping %s -- SysC" % (args.arch))
|
||||
# init = os.path.join(os.sep, 'init')
|
||||
# run('sudo', chroot_binary, system_c.tmp_dir, init)
|
||||
|
||||
if args.minikernel:
|
||||
elif args.minikernel:
|
||||
if os.path.isdir('kritis-linux'):
|
||||
shutil.rmtree('kritis-linux')
|
||||
|
||||
|
|
@ -111,19 +115,20 @@ print(shutil.which('chroot'))
|
|||
'--qemucpu', '486',
|
||||
'--kernel', '3.18.140',
|
||||
'--features', 'kflock,highrestimers',
|
||||
'--ramsize', str(args.qemu_ram) + 'M',
|
||||
'--initrd', initramfs_path,
|
||||
# Hack to add -hda /dev/blah
|
||||
'--ramsize', str(args.qemu_ram) + 'M -hda ' + sysb.dev_name,
|
||||
'--initrd', system_a.initramfs_path,
|
||||
'--log', '/tmp/bootstrap.log')
|
||||
return
|
||||
|
||||
run(args.qemu_cmd,
|
||||
'-enable-kvm',
|
||||
'-m', str(args.qemu_ram) + 'M',
|
||||
'-nographic',
|
||||
'-no-reboot',
|
||||
'-kernel', args.kernel,
|
||||
'-initrd', initramfs_path,
|
||||
'-append', "console=ttyS0")
|
||||
else:
|
||||
run(args.qemu_cmd,
|
||||
'-enable-kvm',
|
||||
'-m', str(args.qemu_ram) + 'M',
|
||||
'-no-reboot',
|
||||
'-hda', system_c.dev_name,
|
||||
'-kernel', args.kernel,
|
||||
'-initrd', system_a.initramfs_path,
|
||||
'-display', 'curses')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue