From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6543937367387930624 X-Received: by 10.28.228.84 with SMTP id b81mr496588wmh.5.1523629150122; Fri, 13 Apr 2018 07:19:10 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 10.28.26.147 with SMTP id a141ls464440wma.0.canary-gmail; Fri, 13 Apr 2018 07:19:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx48qEnkxax+m7fS5SPo6RE/EibwtZjtMPHQLHXtm5ovvfJkS5NrAPKO44CqxXm48lmWiOQ8W X-Received: by 10.28.147.13 with SMTP id v13mr528905wmd.15.1523629149682; Fri, 13 Apr 2018 07:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523629149; cv=none; d=google.com; s=arc-20160816; b=0Jpck85yjBsDnI48xTv8dPRU8rKKV5R9xzCTnrylOEBjcdCMSRRUkMihZwYptU7HIE a8T7SQB7ilwZVwDfxjtA79fo5L2/ZgIOKUH9Fw+rX4+iIXfKZQyk0p1/bz6apaItjY+S QW2ts6HpASdqqFLMdRZv1UuYFJzvQ526iHpjBhRpMh8xUij2a8eukpz1PgIFt+Ji5usQ fRbT1ty40KhgnWpORTZGmDsX/cTRaAVjkERMjEgNw0n6Ueo3oknp79gY+Bt848DteKyn TB1zGae172KMMI+g0TyNCDMVHEqLbnEq5LcR/tRorTrgPhZ3cuyRHm9d0+VeaUWwp6Dt GXMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=D2leweuJzopixx4ER8GX4d+R/0PUNCTkLSZL1UTCU+g=; b=vKgzk1XdjcbtjlmEP0loe5bImIvgHKEnNm8y8wYRg70kkZP1Gjrai9VVJLI1zfIyK0 1dC1COXAkwuaymV3uUlTw9rlR+faaLNFlgauIWaDpgamT8rZkN+vYenyqhkrjOM9/a2I eieJ/fS7WRDewjKs4d0Cp9EtbZuyK5raWVIc+x7sxwsKEAyvguv8NdXxhRVXLsmUobbD iL2YK+1nn1bRdmbalNDJPr5Qkxq7dkHyeTKBBv3FtFVN2RK+x/taT2MsBkHQQLKaLKAA DlT1h5QjrBIJuONYPr+4gmPSJMk39RGZlbVkmG0MHsOO/08r/ya3DzaPZlndbA6fi61N UxYw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=henning.schild@siemens.com Return-Path: Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id h20si153679wmc.1.2018.04.13.07.19.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Apr 2018 07:19:09 -0700 (PDT) Received-SPF: pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=henning.schild@siemens.com Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id w3DEJ9aM022187 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Apr 2018 16:19:09 +0200 Received: from md1pvb1c.ad001.siemens.net (md1pvb1c.ad001.siemens.net [139.25.68.40] (may be forged)) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id w3DEJ8W3011006; Fri, 13 Apr 2018 16:19:09 +0200 From: Henning Schild To: isar-users@googlegroups.com Cc: Cedric Hombourger , Andreas Reichel , Henning Schild Subject: [PATCH v2 11/17] images: New class wic-img for wic intregration Date: Fri, 13 Apr 2018 16:19:00 +0200 Message-Id: X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: X-TUID: 9a5RMacsmdTo This patch integrates wic into the bitbake workflow, wic will be used for the imaging step, no need to call it manually. After all the previous reverts we now use an unmodified version of wic. Issues: - wic was never integrated - you always had to build an ext4-img to create a wic image later - there was never a way to control the size of wic disks/partition, only directly in the wks - wic used to leak the hosts bootloader into the final image Impact: The patch solves the Issues, but drops the ability to manually start wic after bitbake. And it drops support for building wic images for Distros before stretch. Signed-off-by: Henning Schild --- doc/user_manual.md | 6 - .../scripts/lib/wic/canned-wks/sdimage-efi.wks | 2 +- .../lib/wic/plugins/source/bootimg-efi-isar.py | 297 +++++++++++++++++++++ meta/classes/wic-img.bbclass | 78 ++++++ meta/recipes-devtools/buildchroot/buildchroot.bb | 19 ++ scripts/wic_fakeroot | 37 +++ 6 files changed, 432 insertions(+), 7 deletions(-) create mode 100644 meta-isar/scripts/lib/wic/plugins/source/bootimg-efi-isar.py create mode 100644 meta/classes/wic-img.bbclass create mode 100755 scripts/wic_fakeroot diff --git a/doc/user_manual.md b/doc/user_manual.md index 058f7bd..7bd52f4 100644 --- a/doc/user_manual.md +++ b/doc/user_manual.md @@ -52,16 +52,10 @@ The steps below describe how to build the images provided by default. Install the following packages: ``` dosfstools -e2fsprogs/jessie-backports # wic: e2fsprogs -d -gdisk # wic git -grub-efi-amd64-bin # wic UEFI: /usr/lib/grub/x86_64-efi/moddep.lst -grub-efi-ia32-bin # wic UEFI: /usr/lib/grub/i386-efi/moddep.lst -mtools # wic FAT: mcopy debootstrap parted python -python3 # wic qemu qemu-user-static rxvt-unicode # build_parallel diff --git a/meta-isar/scripts/lib/wic/canned-wks/sdimage-efi.wks b/meta-isar/scripts/lib/wic/canned-wks/sdimage-efi.wks index 1171a26..580ad21 100644 --- a/meta-isar/scripts/lib/wic/canned-wks/sdimage-efi.wks +++ b/meta-isar/scripts/lib/wic/canned-wks/sdimage-efi.wks @@ -2,7 +2,7 @@ # long-description: Creates a partitioned EFI disk image without any swap that # the user can directly dd to boot media. -part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 +part /boot --source bootimg-efi-isar --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid diff --git a/meta-isar/scripts/lib/wic/plugins/source/bootimg-efi-isar.py b/meta-isar/scripts/lib/wic/plugins/source/bootimg-efi-isar.py new file mode 100644 index 0000000..fccf96c --- /dev/null +++ b/meta-isar/scripts/lib/wic/plugins/source/bootimg-efi-isar.py @@ -0,0 +1,297 @@ +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +# +# Copyright (c) 2014, Intel Corporation. +# All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# DESCRIPTION +# This implements the 'bootimg-efi-isar' source plugin class for 'wic' +# +# AUTHORS +# Tom Zanussi +# + +import logging +import os +import shutil + +from wic import WicError +from wic.engine import get_custom_config +from wic.pluginbase import SourcePlugin +from wic.utils.misc import (exec_cmd, get_bitbake_var, BOOTDD_EXTRA_SPACE) + +logger = logging.getLogger('wic') + +class BootimgEFIPlugin(SourcePlugin): + """ + Create EFI boot partition. + This plugin supports GRUB 2 and systemd-boot bootloaders. + """ + + name = 'bootimg-efi-isar' + + @classmethod + def do_configure_grubefi(cls, creator, cr_workdir): + """ + Create loader-specific (grub-efi) config + """ + configfile = creator.ks.bootloader.configfile + custom_cfg = None + if configfile: + custom_cfg = get_custom_config(configfile) + if custom_cfg: + # Use a custom configuration for grub + grubefi_conf = custom_cfg + logger.debug("Using custom configuration file " + "%s for grub.cfg", configfile) + else: + raise WicError("configfile is specified but failed to " + "get it from %s." % configfile) + + if not custom_cfg: + # Create grub configuration using parameters from wks file + bootloader = creator.ks.bootloader + + grubefi_conf = "" + grubefi_conf += "serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1\n" + grubefi_conf += "default=boot\n" + grubefi_conf += "timeout=%s\n" % bootloader.timeout + grubefi_conf += "set root='hd0,gpt2'\n" + grubefi_conf += "menuentry 'boot'{\n" + + kernel = "/vmlinuz" + + grubefi_conf += "linux %s root=%s rootwait %s\n" \ + % (kernel, creator.rootdev, bootloader.append) + + initrd = "/initrd.img" + + grubefi_conf += "initrd %s\n" % initrd + + grubefi_conf += "}\n" + + logger.debug("Writing grubefi config %s/hdd/boot/EFI/BOOT/grub.cfg", + cr_workdir) + cfg = open("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, "w") + cfg.write(grubefi_conf) + cfg.close() + + cfg = open("%s/hdd/boot/EFI/BOOT/grub-mkimage.cfg" % cr_workdir, "w") + mkimage_conf = "set root='hd0,gpt1'\n" + mkimage_conf += "set prefix=($root)/EFI/BOOT\n" + cfg.write(mkimage_conf) + cfg.close() + + @classmethod + def do_configure_systemdboot(cls, hdddir, creator, cr_workdir, source_params): + """ + Create loader-specific systemd-boot/gummiboot config + """ + install_cmd = "install -d %s/loader" % hdddir + exec_cmd(install_cmd) + + install_cmd = "install -d %s/loader/entries" % hdddir + exec_cmd(install_cmd) + + bootloader = creator.ks.bootloader + + loader_conf = "" + loader_conf += "default boot\n" + loader_conf += "timeout %d\n" % bootloader.timeout + + initrd = source_params.get('initrd') + + if initrd: + # obviously we need to have a common common deploy var + bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") + if not bootimg_dir: + raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") + + cp_cmd = "cp %s/%s %s" % (bootimg_dir, initrd, hdddir) + exec_cmd(cp_cmd, True) + else: + logger.debug("Ignoring missing initrd") + + logger.debug("Writing systemd-boot config " + "%s/hdd/boot/loader/loader.conf", cr_workdir) + cfg = open("%s/hdd/boot/loader/loader.conf" % cr_workdir, "w") + cfg.write(loader_conf) + cfg.close() + + configfile = creator.ks.bootloader.configfile + custom_cfg = None + if configfile: + custom_cfg = get_custom_config(configfile) + if custom_cfg: + # Use a custom configuration for systemd-boot + boot_conf = custom_cfg + logger.debug("Using custom configuration file " + "%s for systemd-boots's boot.conf", configfile) + else: + raise WicError("configfile is specified but failed to " + "get it from %s.", configfile) + + if not custom_cfg: + # Create systemd-boot configuration using parameters from wks file + kernel = "/vmlinuz" + + boot_conf = "" + boot_conf += "title boot\n" + boot_conf += "linux %s\n" % kernel + boot_conf += "options LABEL=Boot root=%s %s\n" % \ + (creator.rootdev, bootloader.append) + + if initrd: + boot_conf += "initrd /%s\n" % initrd + + logger.debug("Writing systemd-boot config " + "%s/hdd/boot/loader/entries/boot.conf", cr_workdir) + cfg = open("%s/hdd/boot/loader/entries/boot.conf" % cr_workdir, "w") + cfg.write(boot_conf) + cfg.close() + + + @classmethod + def do_configure_partition(cls, part, source_params, creator, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + native_sysroot): + """ + Called before do_prepare_partition(), creates loader-specific config + """ + hdddir = "%s/hdd/boot" % cr_workdir + + install_cmd = "install -d %s/EFI/BOOT" % hdddir + exec_cmd(install_cmd) + + try: + if source_params['loader'] == 'grub-efi': + cls.do_configure_grubefi(creator, cr_workdir) + elif source_params['loader'] == 'systemd-boot': + cls.do_configure_systemdboot(hdddir, creator, cr_workdir, source_params) + else: + raise WicError("unrecognized bootimg-efi-isar loader: %s" % source_params['loader']) + except KeyError: + raise WicError("bootimg-efi-isar requires a loader, none specified") + + + @classmethod + def do_prepare_partition(cls, part, source_params, creator, cr_workdir, + oe_builddir, bootimg_dir, kernel_dir, + rootfs_dir, native_sysroot): + """ + Called to do the actual content population for a partition i.e. it + 'prepares' the partition to be incorporated into the image. + In this case, prepare content for an EFI (grub) boot partition. + """ + if not kernel_dir: + kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") + if not kernel_dir: + raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") + + staging_kernel_dir = kernel_dir + + hdddir = "%s/hdd/boot" % cr_workdir + + try: + if source_params['loader'] == 'grub-efi': + shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir, + "%s/grub.cfg" % cr_workdir) + shutil.copyfile("%s/hdd/boot/EFI/BOOT/grub-mkimage.cfg" % cr_workdir, + "%s/grub-mkimage.cfg" % cr_workdir) + for mod in [x for x in os.listdir(kernel_dir) if x.startswith("grub-efi-")]: + cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[9:]) + exec_cmd(cp_cmd, True) + shutil.move("%s/grub.cfg" % cr_workdir, + "%s/hdd/boot/EFI/BOOT/grub.cfg" % cr_workdir) + + distro_arch = get_bitbake_var("DISTRO_ARCH") + if not distro_arch: + raise WicError("Couldn't find target architecture") + + if distro_arch == "amd64": + grub_target = 'x86_64-efi' + grub_image = "bootx64.efi" + elif distro_arch == "i386": + grub_target = 'i386-efi' + grub_image = "bootia32.efi" + else: + raise WicError("grub-efi is incompatible with target %s" % + distro_arch) + + bootimg_dir = "%s/hdd/boot" % cr_workdir + if not os.path.isfile("%s/EFI/BOOT/%s" \ + % (bootimg_dir, grub_image)): + + # TODO: check that grub-mkimage is available + grub_cmd = "grub-mkimage -p /EFI/BOOT " + grub_cmd += "-c %s/grub-mkimage.cfg " % cr_workdir + grub_cmd += "-O %s -o %s/EFI/BOOT/%s " \ + % (grub_target, bootimg_dir, grub_image) + grub_cmd += "part_gpt part_msdos ntfs ntfscomp fat ext2 " + grub_cmd += "normal chain boot configfile linux multiboot " + grub_cmd += "search efi_gop efi_uga font gfxterm gfxmenu " + grub_cmd += "terminal minicmd test iorw loadenv echo help " + grub_cmd += "reboot serial terminfo iso9660 loopback tar " + grub_cmd += "memdisk ls search_fs_uuid udf btrfs xfs lvm " + grub_cmd += "reiserfs ata " + exec_cmd(grub_cmd) + elif source_params['loader'] == 'systemd-boot': + for mod in [x for x in os.listdir(kernel_dir) if x.startswith("systemd-")]: + cp_cmd = "cp %s/%s %s/EFI/BOOT/%s" % (kernel_dir, mod, hdddir, mod[8:]) + exec_cmd(cp_cmd, True) + else: + raise WicError("unrecognized bootimg-efi-isar loader: %s" % + source_params['loader']) + except KeyError: + raise WicError("bootimg-efi-isar requires a loader, none specified") + + startup = os.path.join(kernel_dir, "startup.nsh") + if os.path.exists(startup): + cp_cmd = "cp %s %s/" % (startup, hdddir) + exec_cmd(cp_cmd, True) + + du_cmd = "du -bks %s" % hdddir + out = exec_cmd(du_cmd) + blocks = int(out.split()[0]) + + extra_blocks = part.get_extra_block_count(blocks) + + if extra_blocks < BOOTDD_EXTRA_SPACE: + extra_blocks = BOOTDD_EXTRA_SPACE + + blocks += extra_blocks + + logger.debug("Added %d extra blocks to %s to get to %d total blocks", + extra_blocks, part.mountpoint, blocks) + + # dosfs image, created by mkdosfs + bootimg = "%s/boot.img" % cr_workdir + + dosfs_cmd = "mkdosfs -n efi -C %s %d" % (bootimg, blocks) + exec_cmd(dosfs_cmd) + + mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (bootimg, hdddir) + exec_cmd(mcopy_cmd, True) + + chmod_cmd = "chmod 644 %s" % bootimg + exec_cmd(chmod_cmd) + + du_cmd = "du -Lbks %s" % bootimg + out = exec_cmd(du_cmd) + bootimg_size = out.split()[0] + + part.size = int(bootimg_size) + part.source_file = bootimg diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass new file mode 100644 index 0000000..d1deff3 --- /dev/null +++ b/meta/classes/wic-img.bbclass @@ -0,0 +1,78 @@ +# This software is a part of ISAR. +# Copyright (C) 2018 Siemens AG +# +# this class is heavily inspired by OEs ./meta/classes/image_types_wic.bbclass +# + +WKS_FILE ?= "sdimage-efi" +ROOTFS_TYPE ?= "ext4" + +STAGING_DATADIR ?= "/usr/lib/" +STAGING_LIBDIR ?= "/usr/lib/" +STAGING_DIR ?= "${TMPDIR}" +IMAGE_BASENAME ?= "multiconfig:${MACHINE}-${DISTRO}:${PN}" +FAKEROOTCMD ?= "${ISARROOT}/scripts/wic_fakeroot" +RECIPE_SYSROOT_NATIVE ?= "/" + +do_wic_image[stamp-extra-info] = "${DISTRO}-${MACHINE}" + +WIC_CREATE_EXTRA_ARGS ?= "" + +WICVARS ?= "\ + BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD IMAGE_BASENAME IMAGE_BOOT_FILES \ + IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD INITRD_LIVE ISODIR RECIPE_SYSROOT_NATIVE \ + ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS TRANSLATED_TARGET_ARCH" + +# Isar specific vars used in our plugins +WICVARS += "KERNEL_IMAGE INITRD_IMAGE DISTRO_ARCH" + +python do_rootfs_wicenv () { + wicvars = d.getVar('WICVARS', True) + if not wicvars: + return + + stdir = d.getVar('STAGING_DIR', True) + outdir = os.path.join(stdir, d.getVar('MACHINE', True), 'imgdata') + bb.utils.mkdirhier(outdir) + basename = d.getVar('IMAGE_BASENAME', True) + with open(os.path.join(outdir, basename) + '.env', 'w') as envf: + for var in wicvars.split(): + value = d.getVar(var, True) + if value: + envf.write('%s="%s"\n' % (var, value.strip())) + + # this part is stolen from OE ./meta/recipes-core/meta/wic-tools.bb + with open(os.path.join(outdir, "wic-tools.env"), 'w') as envf: + for var in ('RECIPE_SYSROOT_NATIVE', 'STAGING_DATADIR', 'STAGING_LIBDIR'): + envf.write('%s="%s"\n' % (var, d.getVar(var, True).strip())) + +} + +addtask do_rootfs_wicenv after do_copy_boot_files before do_wic_image +do_rootfs_wicenv[vardeps] += "${WICVARS}" +do_rootfs_wicenv[prefuncs] = 'set_image_size' + +WIC_IMAGE_FILE ="${DEPLOY_DIR_IMAGE}/${PN}-${DISTRO}-${MACHINE}.wic.img" + +do_build[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}" + +do_wic_image() { + if ! grep -q ${BUILDCHROOT_DIR}/dev /proc/mounts; then + sudo mount -t devtmpfs -o mode=0755,nosuid devtmpfs ${BUILDCHROOT_DIR}/dev + sudo mount -t proc none ${BUILDCHROOT_DIR}/proc + fi + for dir in ${BBLAYERS} ${STAGING_DIR} ${ISARROOT}/scripts; do + sudo mkdir -p ${BUILDCHROOT_DIR}/$dir + sudo mount --bind $dir ${BUILDCHROOT_DIR}/$dir + done + export FAKEROOTCMD=${FAKEROOTCMD} + export BUILDDIR=${BUILDDIR} + export MTOOLS_SKIP_CHECK=1 + + sudo -E chroot ${BUILDCHROOT_DIR} ${ISARROOT}/scripts/wic create ${WKS_FILE} --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -o /tmp/ -e ${IMAGE_BASENAME} ${WIC_CREATE_EXTRA_ARGS} + cp -f `ls -t -1 ${BUILDCHROOT_DIR}/tmp/${WKS_FILE}*.direct | head -1` ${WIC_IMAGE_FILE} +} + +do_wic_image[depends] = "buildchroot:do_build" + +addtask wic_image before do_build after do_copy_boot_files diff --git a/meta/recipes-devtools/buildchroot/buildchroot.bb b/meta/recipes-devtools/buildchroot/buildchroot.bb index b16e63a..bd4d003 100644 --- a/meta/recipes-devtools/buildchroot/buildchroot.bb +++ b/meta/recipes-devtools/buildchroot/buildchroot.bb @@ -28,6 +28,25 @@ BUILDCHROOT_PREINSTALL ?= "gcc \ devscripts \ equivs" +BUILDCHROOT_PREINSTALL_WIC = " \ + parted \ + gdisk \ + util-linux \ + syslinux \ + syslinux-common \ + dosfstools \ + mtools \ + e2fsprogs \ + grub-efi-amd64-bin \ + grub-efi-ia32-bin \ + python3" + +python () { + if d.getVar('IMAGE_TYPE', True) == 'wic-img': + d.appendVar('BUILDCHROOT_PREINSTALL', + d.getVar('BUILDCHROOT_PREINSTALL_WIC', True)) +} + WORKDIR = "${TMPDIR}/work/${DISTRO}-${DISTRO_ARCH}/${PN}" do_build[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}" diff --git a/scripts/wic_fakeroot b/scripts/wic_fakeroot new file mode 100755 index 0000000..9e01c38 --- /dev/null +++ b/scripts/wic_fakeroot @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# +# wic needs a FAKEROOT cmd to run, the default is pseudo. In Isar we do/can not +# use pseudo. And we call wic as root to begin with, so this script could be a +# dummy doing nothing. It is almost a dummy ... +# +# If the fsck hack ever becomes obsolete, FAKEROOTCMD ?= "true;" can be used +# +# This software is a part of Isar. +# Copyright (C) 2018 Siemens AG +# +import os +import sys +import shutil +import subprocess + +args = sys.argv +args.pop(0) +cmd = args[0] + +# expect to be running as root +# we could loosen that and execv(sudo, args) but even some early +# "du"s fail, which do not use the fakeroot-wrapper +# i.e. in wics partition.py the "du -ks" fails on +# var/cache/apt/archives/partial +# rootfs/root ... +assert 'root' == os.environ["USER"] + +# e2fsck <= 1.43.5 returns 1 on non-errors (stretch and before affected) +# treat 1 as safe ... the filesystem was successfully repaired and is OK +if cmd.startswith('fsck.'): + ret = subprocess.call(args) + if ret == 0 or ret == 1: + sys.exit(0) + sys.exit(ret) + +os.execv(shutil.which(cmd), args) -- 2.16.1