From c729341283acee364f5250db159c393a27a64092 Mon Sep 17 00:00:00 2001 From: Steven Shiau Date: Thu, 14 Mar 2024 08:14:00 +0800 Subject: [PATCH 1/3] Added a script to bootstrap using mmdebstrap. bootstrap_mmdebstrap: script to bootstrap using mmdebstrap. --- scripts/build/bootstrap_mmdebstrap | 132 +++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100755 scripts/build/bootstrap_mmdebstrap diff --git a/scripts/build/bootstrap_mmdebstrap b/scripts/build/bootstrap_mmdebstrap new file mode 100755 index 000000000..4ea7fda84 --- /dev/null +++ b/scripts/build/bootstrap_mmdebstrap @@ -0,0 +1,132 @@ +#!/bin/sh + +## live-build(7) - System Build Scripts +## Copyright (C) 2016-2020 The Debian Live team +## Copyright (C) 2006-2015 Daniel Baumann +## +## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING. +## This is free software, and you are welcome to redistribute it +## under certain conditions; see COPYING for details. + + +set -e + +# Including common functions +[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh + +# Setting static variables +DESCRIPTION="Bootstrap a Debian system with mmdebstrap(8)" +USAGE="${PROGRAM} [--force]" + +# Processing arguments and configuration files +Init_config_data "${@}" + +if [ "${LB_BOOTSTRAP}" != "mmdebstrap" ] +then + exit 0 +fi + +if ! command -v mmdebstrap >/dev/null +then + Echo_error "mmdebstrap - command not found" + exit 1 +fi + +# Check architecture +Check_crossarchitectures + +Echo_message "Begin bootstrapping system..." + +Check_package host /usr/bin/mmdebstrap mmdebstrap + +# Checking stage file +Check_stagefile "bootstrap" +# Note, this must match that used in `bootstrap_cache` +Check_stagefile "bootstrap_cache.restore" + +# Acquire lock file +Acquire_lockfile + +Print_breakage () +{ + Echo_message "If the following stage fails, the most likely cause of the problem is with your mirror configuration or a caching proxy." +} + +# Creating chroot directory +mkdir -p chroot + +# Setting mmdebstrap options +if [ -n "${LB_ARCHITECTURE}" ] +then + DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --arch=${LB_ARCHITECTURE}" +fi + +if [ "${LB_ARCHIVE_AREAS}" != "main" ] +then + # Modify archive areas to remove leading/trailing whitespaces and replace other whitepspace with commas + DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --components=$(echo ${LB_ARCHIVE_AREAS} | sed -e 's| |,|g')" + FOREIGN_DEBOOTSTRAP_OPTIONS="--components=$(echo ${LB_ARCHIVE_AREAS} | sed -e 's| |,|g')" +fi + +if [ "${_VERBOSE}" = "true" ] +then + DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --verbose" +fi + +# If LB_APT_SECURE is false, do not check signatures of the Release file +if [ "${LB_APT_SECURE}" = "false" ] +then + DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --no-check-gpg" +else + DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --force-check-gpg" +fi + +if [ "${LB_CACHE_PACKAGES}" = "true" ] +then + if ls cache/packages.bootstrap/*.deb > /dev/null 2>&1 + then + mkdir -p chroot/var/cache/apt/archives + cp cache/packages.bootstrap/*.deb chroot/var/cache/apt/archives + fi + + Print_breakage + Echo_message "Running mmdebstrap (download-only)..." + mmdebstrap ${DEBOOTSTRAP_OPTIONS} --download-only "${LB_PARENT_DISTRIBUTION_CHROOT}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}" ${DEBOOTSTRAP_SCRIPT} + + # Removing old cache + rm -f cache/packages.bootstrap/*.deb + + # Saving new cache + mkdir -p cache/packages.bootstrap + cp chroot/var/cache/apt/archives/*.deb cache/packages.bootstrap +fi + +Print_breakage +Echo_message "Running mmdebstrap..." + +# Run appropriate bootstrap, i.e. foreign or regular bootstrap +if [ "${LB_BOOTSTRAP_QEMU_ARCHITECTURE}" = "${LB_ARCHITECTURE}" ]; then + + if [ -n "${LB_BOOTSTRAP_QEMU_EXCLUDE}" ] + then + DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --exclude=$(echo ${LB_BOOTSTRAP_QEMU_EXCLUDE} | sed 's| *|,|g')" + fi + + Echo_message "Bootstrap will be foreign" + mmdebstrap ${DEBOOTSTRAP_OPTIONS} --foreign "${LB_PARENT_DISTRIBUTION_CHROOT}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}" ${DEBOOTSTRAP_SCRIPT} + + Echo_message "Running mmdebstrap second stage under QEMU" + cp ${LB_BOOTSTRAP_QEMU_STATIC} chroot/usr/bin + Chroot chroot /bin/sh /mmdebstrap/mmdebstrap --second-stage ${FOREIGN_DEBOOTSTRAP_OPTIONS} +else + mmdebstrap ${DEBOOTSTRAP_OPTIONS} "${LB_PARENT_DISTRIBUTION_CHROOT}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}" ${DEBOOTSTRAP_SCRIPT} +fi + +# Deconfiguring mmdebstrap configurations +rm -f chroot/etc/hosts + +# Removing bootstrap cache +rm -f chroot/var/cache/apt/archives/*.deb + +# Creating stage file +Create_stagefile "bootstrap" From ec2ce84e8d060d5971905814f524345859a274db Mon Sep 17 00:00:00 2001 From: Steven Shiau Date: Thu, 14 Mar 2024 08:27:37 +0800 Subject: [PATCH 2/3] Support different bootstrap programs. Update related scripts to support different bootstrap programs: debootstrap and mmdebstrap. --- scripts/build/bootstrap | 1 + scripts/build/bootstrap_debootstrap | 5 +++++ scripts/build/config | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/build/bootstrap b/scripts/build/bootstrap index 56d62e481..e8cbe7a9c 100755 --- a/scripts/build/bootstrap +++ b/scripts/build/bootstrap @@ -29,6 +29,7 @@ Setup_clean_exit # Bootstrapping system lb bootstrap_cache restore "${@}" +lb bootstrap_mmdebstrap "${@}" lb bootstrap_debootstrap "${@}" lb bootstrap_cache save "${@}" diff --git a/scripts/build/bootstrap_debootstrap b/scripts/build/bootstrap_debootstrap index e0278844c..d5284f913 100755 --- a/scripts/build/bootstrap_debootstrap +++ b/scripts/build/bootstrap_debootstrap @@ -21,6 +21,11 @@ USAGE="${PROGRAM} [--force]" # Processing arguments and configuration files Init_config_data "${@}" +if [ "${LB_BOOTSTRAP}" != "debootstrap" ] +then + exit 0 +fi + if ! command -v debootstrap >/dev/null then Echo_error "debootstrap - command not found" diff --git a/scripts/build/config b/scripts/build/config index 8b8010acb..1b082a73d 100755 --- a/scripts/build/config +++ b/scripts/build/config @@ -34,6 +34,7 @@ USAGE="${PROGRAM} [--apt apt|apt-get|aptitude]\n\ \t [--bootappend-live PARAMETER|\"PARAMETERS\"]\n\ \t [--bootappend-live-failsafe PARAMETER|\"PARAMETERS\"]\n\ \t [--bootloaders grub-legacy|grub-pc|syslinux|grub-efi|\"BOOTLOADERS\"]\n\ +\t [--bootstrap debootstrap|mmdebstrap]\n\ \t [--bootstrap-qemu-arch ARCH]\n\ \t [--bootstrap-qemu-exclude PACKAGE|\"PACKAGES\"]\n\ \t [--bootstrap-qemu-static PATH]\n\ @@ -139,7 +140,7 @@ Local_arguments () apt-source-archives:,architecture:,architectures:,archive-areas:, backports:,binary-filesystem:,binary-image:,binary-images:, bootappend-install:,bootappend-live:,bootappend-live-failsafe:, - bootloader:,bootloaders:,bootstrap-qemu-arch:,bootstrap-qemu-exclude:, + bootloader:,bootloaders:,bootstrap:,bootstrap-qemu-arch:,bootstrap-qemu-exclude:, bootstrap-qemu-static:,breakpoints,build-with-chroot:, cache:,cache-indices:,cache-packages:,cache-stages:,checksums:, chroot-filesystem:,chroot-squashfs-compression-level:, @@ -370,6 +371,11 @@ Local_arguments () shift 2 ;; + --bootstrap) + LB_BOOTSTRAP="${2}" + shift 2 + ;; + --bootstrap-qemu-arch) LB_BOOTSTRAP_QEMU_ARCHITECTURE="${2}" shift 2 @@ -991,6 +997,9 @@ LB_APT_SECURE="${LB_APT_SECURE}" # Set apt/aptitude source entries in sources.list LB_APT_SOURCE_ARCHIVES="${LB_APT_SOURCE_ARCHIVES}" +# Set bootstrap program +LB_BOOTSTRAP="${LB_BOOTSTRAP}" + # Control cache LB_CACHE="${LB_CACHE}" From 45dfc6c5a7d7b8d9bdcb7838127fc6f232a03661 Mon Sep 17 00:00:00 2001 From: Steven Shiau Date: Thu, 14 Mar 2024 08:28:41 +0800 Subject: [PATCH 3/3] Updated help files, default mode & packaging file. Updated help files, default mode and packaging file. --- debian/control | 2 +- functions/configuration.sh | 2 ++ manpages/en/lb_config.1 | 2 ++ manpages/en/live-build.7 | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 96ccc6c41..930e29b16 100644 --- a/debian/control +++ b/debian/control @@ -18,7 +18,7 @@ Package: live-build Architecture: all Depends: cpio, - debootstrap, + debootstrap | mmdebstrap, ${misc:Depends}, Recommends: apt-utils, diff --git a/functions/configuration.sh b/functions/configuration.sh index 0c88c2a00..5c3a6c995 100755 --- a/functions/configuration.sh +++ b/functions/configuration.sh @@ -481,6 +481,8 @@ Prepare_config () LB_SOURCE_IMAGES="${LB_SOURCE_IMAGES:-tar}" LB_SOURCE_IMAGES="$(echo "${LB_SOURCE_IMAGES}" | tr "," " ")" + LB_BOOTSTRAP="${LB_BOOTSTRAP:-debootstrap}" + # Foreign/port bootstrapping if [ -n "${LB_BOOTSTRAP_QEMU_ARCHITECTURES}" ]; then LB_BOOTSTRAP_QEMU_ARCHITECTURE="${LB_BOOTSTRAP_QEMU_ARCHITECTURES}" diff --git a/manpages/en/lb_config.1 b/manpages/en/lb_config.1 index 32cf42dea..66b6e2137 100644 --- a/manpages/en/lb_config.1 +++ b/manpages/en/lb_config.1 @@ -43,6 +43,8 @@ [\fB\-\-bootappend\-live\-failsafe\fR \fIPARAMETER\fR|"\fIPARAMETERS\fR"] .br [\fB\-\-bootloaders\fR grub-legacy|grub-pc|syslinux|grub-efi|"\fIBOOTLOADERS\fR"] +.br + [\fB\-\-bootstrap\fR debootstrap|mmdebstrap\fR] .br [\fB\-\-bootstrap\-qemu\-arch\fR \fIARCH\fR] .br diff --git a/manpages/en/live-build.7 b/manpages/en/live-build.7 index 0c17afb3c..49e8b9cef 100644 --- a/manpages/en/live-build.7 +++ b/manpages/en/live-build.7 @@ -84,6 +84,8 @@ applies apt archive configuration in save mode, saves to cache a copy of the generated bootstrap directory, and in restore mode, restores from cache a previously generated copy .IP "\fBlb bootstrap_debootstrap\fR(1)" 4 creates (bootstraps) a basic Debian root filesystem using debootstrap(8) +.IP "\fBlb bootstrap_mmdebstrap\fR(1)" 4 +creates (bootstraps) a basic Debian root filesystem using mmdebstrap(8) .SS Chroot stage specific commands .PP Note: The following chroot_ prefixed commands are used in building the live OS filesystem. Another set of similarly prefixed files are listed separately (see further down).