From c6c8a1eb7f9e8bc8b1219c0ba3c2b08515ec913d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sun, 10 Oct 2021 16:01:50 +0100 Subject: [PATCH] Move chroot transition script inside bootstrap. --- rootfs.py | 15 ++++----------- sysa.py | 12 +++++++++++- sysa/run.sh | 5 +++++ sysc.py | 15 --------------- sysc/init | 2 +- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/rootfs.py b/rootfs.py index 4949e0c..09ade1c 100755 --- a/rootfs.py +++ b/rootfs.py @@ -70,12 +70,13 @@ def main(): create_configuration_file(args) + system_c = SysC(arch=args.arch, preserve_tmp=args.preserve, + tmpdir=args.tmpdir, chroot=args.chroot) 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) + tmpdir=args.tmpdir, chroot=args.chroot, + sysb_tmp=system_b.tmp_dir, sysc_tmp=system_c.tmp_dir) bootstrap(args, system_a, system_b, system_c) @@ -92,14 +93,6 @@ print(shutil.which('chroot')) # sysa init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', args.arch, 'kaem-optional-seed') 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(f"Bootstrapping {args.arch} -- SysC") - init = os.path.join(os.sep, 'init') - run('sudo', chroot_binary, system_c.tmp_dir, init) elif args.minikernel: if os.path.isdir('kritis-linux'): diff --git a/sysa.py b/sysa.py index 486422c..c62634a 100755 --- a/sysa.py +++ b/sysa.py @@ -17,7 +17,7 @@ class SysA(SysGeneral): Class responsible for preparing sources for System A. """ # pylint: disable=too-many-instance-attributes,too-many-arguments - def __init__(self, arch, preserve_tmp, tmpdir, chroot, sysb_tmp): + def __init__(self, arch, preserve_tmp, tmpdir, chroot, sysb_tmp, sysc_tmp): self.git_dir = os.path.dirname(os.path.join(__file__)) self.arch = arch self.preserve_tmp = preserve_tmp @@ -31,6 +31,8 @@ class SysA(SysGeneral): self.after_dir = os.path.join(self.tmp_dir, 'after') self.base_dir = self.after_dir self.sysb_tmp = sysb_tmp + self.sysc_tmp = sysc_tmp + self.chroot = chroot self.prepare() @@ -52,11 +54,19 @@ class SysA(SysGeneral): # sysb must be added to sysa as it is another initramfs stage self.sysb() + if self.chroot: + self.sysc() + def sysb(self): """Copy in sysb files for sysb.""" shutil.copytree(self.sysb_tmp, os.path.join(self.tmp_dir, 'sysb'), shutil.ignore_patterns('tmp')) + def sysc(self): + """Copy in sysc files for sysc.""" + shutil.copytree(self.sysc_tmp, os.path.join(self.tmp_dir, 'sysc'), + shutil.ignore_patterns('tmp')) + def stage0_posix(self): """Copy in all of the stage0-posix""" stage0_posix_base_dir = os.path.join(self.sys_dir, 'stage0-posix', 'src') diff --git a/sysa/run.sh b/sysa/run.sh index d204e12..1bd7ecf 100755 --- a/sysa/run.sh +++ b/sysa/run.sh @@ -180,3 +180,8 @@ if [ "${CHROOT}" = False ]; then go_sysb fi + +# In chroot mode transition directly into System C. +SYSC="/sysc" +cp -R "${PREFIX}" "${SYSC}" +exec chroot "${SYSC}" /init diff --git a/sysc.py b/sysc.py index 2a8c547..d302db8 100755 --- a/sysc.py +++ b/sysc.py @@ -73,21 +73,6 @@ class SysC(SysGeneral): if not self.chroot: umount(self.rootfs_dir) - def chroot_transition(self, original): - """ - For chroot, transition sysa -> sysc - See create_sysc in sysb/run.sh - We skip sysb when using chroot, as sysb is entirely irrelevant - to chrooting (only for kernel shenanigans) - Copy directories from /usr (sysa) -> /usr (sysc) - """ - run('sudo', 'chown', '-R', getpass.getuser(), original) - run('sudo', 'chown', '-R', getpass.getuser(), self.rootfs_dir) - shutil.copytree(os.path.join(original, 'usr'), - os.path.join(self.rootfs_dir, 'usr'), - ignore=shutil.ignore_patterns("src"), - dirs_exist_ok=True, symlinks=True) - def deploy_scripts(self): """Add the scripts to the chroot""" src_files = ['run.sh', 'run2.sh'] diff --git a/sysc/init b/sysc/init index 50a2220..deeb132 100755 --- a/sysc/init +++ b/sysc/init @@ -8,4 +8,4 @@ set -e # Begin sysc bootstrapping process cd /usr/src -./run.sh +exec ./run.sh