commit: d5008f93a529bd04b7e97eadb46e7dc3aaf2a695
parent 9384a5d432a7b246810e6c62d3f226df1239daab
Author: Gábor Stefanik <netrolller.3d@gmail.com>
Date: Mon, 1 Jan 2024 22:51:33 +0100
Support swap files in qemu or bare-metal mode
This can help alleviate memory pressure when bootstrapping
with high core counts.
Diffstat:
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/rootfs.py b/rootfs.py
@@ -12,6 +12,7 @@ you can run bootstap inside chroot.
# SPDX-FileCopyrightText: 2021 Bastian Bittorf <bb@npl.de>
# SPDX-FileCopyrightText: 2021 Melg Eight <public.melg8@gmail.com>
# SPDX-FileCopyrightText: 2021-23 fosslinux <fosslinux@aussies.space>
+# SPDX-FileCopyrightText: 2023-24 Gábor Stefanik <netrolller.3d@gmail.com>
import argparse
import os
@@ -31,6 +32,7 @@ def create_configuration_file(args):
config.write(f"CHROOT={args.chroot or args.bwrap}\n")
config.write(f"UPDATE_CHECKSUMS={args.update_checksums}\n")
config.write(f"JOBS={args.cores}\n")
+ config.write(f"SWAP_SIZE={args.swap}\n")
config.write(f"INTERNAL_CI={args.internal_ci or False}\n")
config.write(f"BARE_METAL={args.bare_metal}\n")
if (args.bare_metal or args.qemu) and not args.kernel:
@@ -44,7 +46,7 @@ def create_configuration_file(args):
config.write("KERNEL_BOOTSTRAP=False\n")
config.write(f"BUILD_KERNELS={args.update_checksums or args.build_kernels}\n")
-# pylint: disable=too-many-statements
+# pylint: disable=too-many-statements,too-many-branches
def main():
"""
A few command line arguments to customize bootstrap.
@@ -86,6 +88,8 @@ def main():
parser.add_argument("--early-preseed",
help="Skip early stages of live-bootstrap.", nargs=None)
parser.add_argument("--internal-ci", help="INTERNAL for github CI")
+ parser.add_argument("-s", "--swap", help="Swap space to allocate in Linux",
+ default=0)
# QEMU arguments
parser.add_argument("-q", "--qemu", help="Use QEMU",
@@ -143,6 +147,13 @@ def main():
else:
args.target_size = 0
+ # Swap file size validation
+ if args.qemu or args.bare_metal:
+ args.swap = (int(str(args.swap).rstrip('gGmM')) *
+ (1024 if str(args.swap).lower().endswith('g') else 1))
+ else:
+ args.swap = 0
+
# bootstrap.cfg
try:
os.remove(os.path.join('steps', 'bootstrap.cfg'))
diff --git a/steps/improve/swap.sh b/steps/improve/swap.sh
@@ -0,0 +1,19 @@
+
+#!/bin/sh
+#
+# SPDX-FileCopyrightText: 2024 Gábor Stefanik <netrolller.3d@gmail.com>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# Set up swap
+
+. /steps/bootstrap.cfg
+. /steps/env
+
+if ! test -f /swapfile
+then
+ echo "Making swap..."
+ dd if=/dev/zero of=/swapfile bs=1M count=${SWAP_SIZE}
+ mkswap /swapfile
+fi
+swapon /swapfile
diff --git a/steps/manifest b/steps/manifest
@@ -119,6 +119,7 @@ build: linux-4.9.10 ( BUILD_LINUX == True )
jump: break ( INTERNAL_CI == pass1 )
jump: linux ( CHROOT == False )
improve: finalize_fhs
+improve: swap ( SWAP_SIZE != 0 )
build: musl-1.2.4
build: curl-8.5.0
improve: populate_device_nodes