Skip to content

Commit

Permalink
Fix preinstallimages in containers (#1031)
Browse files Browse the repository at this point in the history
* preinstall_image(): Refactor tar and bsdtar excludes into a shared variable

* preinstall_image(): Avoid extracting special files under /dev, /proc, /run and /sys in podman containers

Rootless containers do not have sufficient capabilities to create such special files.
Also, these directories are usually tmpfs mounts so we're not using the original content anyway.
  • Loading branch information
dmach authored Feb 7, 2025
1 parent 50abd76 commit 3a949fd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions init_buildsystem
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,19 @@ preinstall_image() {
check_exit
echo "unpacking preinstall image${2:+ $2}"
preinstall_setup

TAR_EXCLUDES="--exclude .build --exclude .init_b_cache"

if [ -f "/run/.containerenv" ]; then
# we're running in a podman container and we probably don't have sufficient capabilities to create special files
TAR_EXCLUDES="$TAR_EXCLUDES --exclude dev/* --exclude proc/* --exclude run/* --exclude sys/*"
fi

if test -x /usr/bin/bsdtar ; then
TAR="/usr/bin/bsdtar --exclude .build --exclude .init_b_cache -P --chroot --numeric-owner -x"
TAR="/usr/bin/bsdtar $TAR_EXCLUDES -P --chroot --numeric-owner -x"
else
unsafe_preinstall_check
TAR="tar --exclude .build --exclude .init_b_cache -x"
TAR="tar $TAR_EXCLUDES -x"
fi
if ! $TAR -f "$BUILD_INIT_CACHE/rpms/$1" ; then
echo "ERROR: unpack failed."
Expand Down

0 comments on commit 3a949fd

Please sign in to comment.