live-bootstrap/sysb.py
fosslinux 5c88f1c87f 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.
2021-08-27 14:54:08 +10:00

50 lines
1.5 KiB
Python
Executable file

#!/usr/bin/env python3
"""System B"""
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2021 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-FileCopyrightText: 2021 fosslinux <fosslinux@aussies.space>
import os
import shutil
import getpass
from lib.utils import mount, umount, copytree, create_disk, run
from lib.sysgeneral import SysGeneral
class SysB(SysGeneral):
"""
Class responsible for preparing sources for System B.
"""
def __init__(self, arch, preserve_tmp, tmpdir, chroot):
self.git_dir = os.path.dirname(os.path.join(__file__))
self.arch = arch
self.preserve_tmp = preserve_tmp
self.chroot = chroot
self.sys_dir = os.path.join(self.git_dir, 'sysb')
if tmpdir is None:
self.tmp_dir = os.path.join(self.sys_dir, 'tmp')
else:
self.tmp_dir = os.path.join(tmpdir, 'sysb')
os.mkdir(self.tmp_dir)
self.base_dir = os.path.join(self.tmp_dir, 'usr', 'src')
self.prepare()
def prepare(self):
"""
Prepare directory structure for System B.
"""
self.mount_tmpfs()
os.makedirs(self.base_dir)
# Misc files/scripts
self.deploy_sysglobal_files()
self.deploy_scripts()
def deploy_scripts(self):
"""Add the scripts to the chroot"""
# init script
shutil.copy2(os.path.join(self.sys_dir, 'init'), self.tmp_dir)
# run.sh
shutil.copy2(os.path.join(self.sys_dir, 'run.sh'), self.base_dir)