mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-02 01:18:08 +01:00
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.
66 lines
2.2 KiB
Python
Executable file
66 lines
2.2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
"""
|
|
This file contains a few self-contained helper functions
|
|
"""
|
|
|
|
# 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 subprocess
|
|
import sys
|
|
|
|
def run(*args, **kwargs):
|
|
"""A small wrapper around subprocess.run"""
|
|
arguments = [str(arg) for arg in args]
|
|
|
|
if kwargs.pop('verbose', False):
|
|
print(arguments)
|
|
|
|
try:
|
|
return subprocess.run(arguments, check=True, **kwargs)
|
|
except subprocess.CalledProcessError:
|
|
print("Bootstrapping failed")
|
|
sys.exit(1)
|
|
|
|
def create_disk(image, disk_type, fs_type, size):
|
|
"""Create a disk image, with a filesystem on it"""
|
|
run('truncate', '-s', size, image)
|
|
# First find the device we will use, then actually use it
|
|
loop_dev = run('losetup', '-f', capture_output=True).stdout.decode().strip()
|
|
run('sudo', 'losetup', loop_dev, image)
|
|
# Create the partition
|
|
run('sudo', 'parted', '--script', image, 'mklabel', disk_type, 'mkpart',
|
|
'primary', 'ext4', '0%', '100%')
|
|
run('sudo', 'partprobe', loop_dev)
|
|
run('sudo', 'mkfs.' + fs_type, loop_dev + "p1")
|
|
return loop_dev
|
|
|
|
def mount(source, target, fs_type, options='', **kwargs):
|
|
"""Mount filesystem"""
|
|
run('sudo', 'mount', source, target, '-t', fs_type, '-o', options, **kwargs)
|
|
|
|
def umount(target, **kwargs):
|
|
"""Unmount filesystem"""
|
|
run('sudo', 'umount', target, **kwargs)
|
|
|
|
def copytree(src, dst, ignore=shutil.ignore_patterns('*.git*')):
|
|
"""Copy directory tree into another directory"""
|
|
file_name = os.path.basename(src)
|
|
shutil.copytree(src, os.path.join(dst, file_name), ignore=ignore)
|
|
|
|
def get_target(file_name):
|
|
"""Determine package installation directory"""
|
|
bname = os.path.basename(file_name)
|
|
|
|
# Remove file extension. This is not completely trivial because
|
|
# tar archives often come with double extensions.
|
|
first_ext = os.path.splitext(os.path.basename(bname))
|
|
second_ext = os.path.splitext(first_ext[0])
|
|
if second_ext[1] == '.tar':
|
|
bname = second_ext[0]
|
|
else:
|
|
bname = first_ext[0]
|
|
return bname
|