Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions debos-recipes/examples/overlayfs-tools-overlay/sbin/overlay-do
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause

set -eux

OVERLAY_IMG="/overlay.img"
OVERLAY_DIR="/overlay"
UPPER_DIR="/overlay/upper"
MERGED_DIR="/overlay/merged"
WORK_DIR="/overlay/work"
LOWER_DIR="/"
BINDMOUNTS="/dev /dev/pts /proc /run /sys"

die() {
echo "$*" >&2
exit 1
}

cleanup() {
for fs in $(echo ${BINDMOUNTS} | rev); do
umount "${MERGED_DIR}/${fs}" || true
done
umount "${MERGED_DIR}" || true
umount "${OVERLAY_DIR}" || true
rmdir -v "${OVERLAY_DIR}" || true
}

trap cleanup EXIT

if ! [ -e "${OVERLAY_IMG}" ]; then
die "Overlay ${OVERLAY_IMG} not found"
fi

if [ -d "${OVERLAY_DIR}" ]; then
die "Overlay tree already present; cleanup with umount ${MERGED_DIR} ${OVERLAY_DIR} && rmdir ${OVERLAY_DIR}"
fi

mkdir -v "${OVERLAY_DIR}"
mount -o loop "${OVERLAY_IMG}" "${OVERLAY_DIR}"
mount -t overlay \
overlay \
"-olowerdir=${LOWER_DIR},upperdir=${UPPER_DIR},workdir=${WORK_DIR}" \
"${MERGED_DIR}"

for fs in $BINDMOUNTS; do
mount --bind "${fs}" "${MERGED_DIR}/${fs}"
done

echo "Running $* in merged chroot" >&2
chroot "${MERGED_DIR}" "$@"

54 changes: 54 additions & 0 deletions debos-recipes/examples/overlayfs-tools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- $overlaysize := or .overlaysize "2GiB" }}

architecture: arm64

# this recipe uses overlayfs to install a few extra packages only relevant for
# testing; the resulting image file can be used during factory testing to
# provide extra commands, and then removed from the filesystem
#
# to run a command from the overlay:
# /sbin/overlay-do <command ...>
# to remove the overlay:
# shred -n 1 -v -u /overlay.img

actions:
- action: run
description: Create overlayfs
chroot: true
command: |
set -eux
# create a sparse file to hold the overlay filesystem
truncate -s "{{$overlaysize}}" overlay.img
mkfs.ext4 /overlay.img
# debug
cat /proc/filesystems || true
lsmod || true
losetup -a || true
ls /lib/modules || true
uname -a || true
mkdir -vp /overlay
mount -o loop /overlay.img /overlay
# create directories needed to mount overlay
mkdir -v /overlay/merged /overlay/upper /overlay/work
umount /overlay
rmdir -vp /overlay

- action: overlay
description: Apply overlayfs overlay
source: overlayfs-tools-overlay

- action: run
description: Modernize APT sources
chroot: true
command: |
set -eux
# install gst-launch and some difficult to redistribute gstreamer plugins
/sbin/overlay-do \
apt -y install \
gstreamer1.0-libav \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-tools

# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause
3 changes: 3 additions & 0 deletions debos-recipes/qualcomm-linux-debian-rootfs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ actions:
qcom/qcs6490-rb3gen2.dtb \
qcom/qrb2210-rb1.dtb

- action: recipe
recipe: examples/overlayfs-tools.yaml

- action: pack
description: Create root filesystem tarball
file: rootfs.tar.gz
Expand Down
Loading