Merge pull request #138 from stikonas/chroot

Chroot
This commit is contained in:
fosslinux 2021-10-11 08:39:55 +11:00 committed by GitHub
commit d5d234225e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 29 deletions

View File

@ -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'):

12
sysa.py
View File

@ -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')

View File

@ -1,6 +1,7 @@
fafa676fe85f662f753bb5257ba6575086c6d4d7b8b27a952624db08e136b1ac /usr/bin/basename
8b4e2b1ea346298b6534894e85cfa3ac4ee9bd1900da1d044a45c366d143dbf0 /usr/bin/cat
24b11f735c4dcbd28e0defcef6208f419ebb3a7f33a5f7addb41d7df9e021bc1 /usr/bin/chmod
e19bd087a5e70f9319a81eae9d38513df68fb69769ca49e3f135f45d8b29c0e9 /usr/bin/chroot
8dd096b3a2973c4e3652e6bfffc30d2d85e8cb9b7f6cbbb2079cdb00a465589f /usr/bin/cksum
6e9c29ae39dc9cc13925fe4066ab1867d0623bc704b2b1be6e242dc27b6c8ea1 /usr/bin/cp
220ee0e1e19ad52403794872fd879619c25e2bf6b22d9616799250f76f8b9960 /usr/bin/csplit

View File

@ -83,7 +83,7 @@ CFLAGS = -I . -I lib \
SRC_DIR=src
COREUTILS = basename cat chmod cksum comm csplit cut dd dirname echo env expand expr factor false fmt fold head id join kill link ln logname mkfifo mkdir mknod nl od paste pathchk printf ptx pwd readlink rmdir seq sleep sort split sum sync tail tee tr tsort uname unexpand uniq unlink wc whoami test true yes
COREUTILS = basename cat chmod chroot cksum comm csplit cut dd dirname echo env expand expr factor false fmt fold head id join kill link ln logname mkfifo mkdir mknod nl od paste pathchk printf ptx pwd readlink rmdir seq sleep sort split sum sync tail tee tr tsort uname unexpand uniq unlink wc whoami test true yes
BINARIES = $(addprefix $(SRC_DIR)/, $(COREUTILS))

View File

@ -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

15
sysc.py
View File

@ -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']

View File

@ -8,4 +8,4 @@ set -e
# Begin sysc bootstrapping process
cd /usr/src
./run.sh
exec ./run.sh