Skip to content

Commit

Permalink
ensure that rootfs tarballs usability for standard chroots
Browse files Browse the repository at this point in the history
Make sure all xattrs are preserved in the archive.
  • Loading branch information
sylirre committed Dec 19, 2023
1 parent 7bb3d7d commit 7e95435
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 32 deletions.
20 changes: 20 additions & 0 deletions bootstrap-rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ translate_arch() {
esac
}

# Common way to archive the rootfs.
# Usage: archive_rootfs /path/to/rootfs.tar.xz rootfs-dir
# rootfs-dir is relative to $WORKDIR
archive_rootfs() {
sudo tar \
--directory="$WORKDIR" \
--create \
--sort=name \
--hard-dereference \
--numeric-owner \
--preserve-permissions \
--acls \
--xattrs \
--xattrs-include='*' \
--xz \
--file="$1" \
"$2"
sudo chown $(id -un):$(id -gn) "$1"
}

##############################################################################

# Reset workspace. This also deletes any previously made rootfs tarballs.
Expand Down
7 changes: 2 additions & 5 deletions distro-build/alpine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bootstrap_distribution() {
sha256sum -c "${WORKDIR}/alpine-minirootfs-${dist_version}-${arch}.tar.gz.sha256"

sudo mkdir -m 755 "${WORKDIR}/alpine-$(translate_arch "$arch")"
sudo tar -zxp \
sudo tar -zxp --acls --xattrs --xattrs-include='*' \
-f "${WORKDIR}/alpine-minirootfs-${dist_version}-${arch}.tar.gz" \
-C "${WORKDIR}/alpine-$(translate_arch "$arch")"

Expand All @@ -33,11 +33,8 @@ bootstrap_distribution() {

sudo rm -f "${WORKDIR:?}/alpine-$(translate_arch "$arch")"/var/cache/apk/* || true

sudo tar -J -c \
-f "${ROOTFS_DIR}/alpine-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz" \
-C "$WORKDIR" \
archive_rootfs "${ROOTFS_DIR}/alpine-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz" \
"alpine-$(translate_arch "$arch")"
sudo chown $(id -un):$(id -gn) "${ROOTFS_DIR}/alpine-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz"
done
}

Expand Down
14 changes: 5 additions & 9 deletions distro-build/archlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ bootstrap_distribution() {
"http://os.archlinuxarm.org/os/ArchLinuxARM-${arch}-latest.tar.gz"

sudo mkdir -m 755 "${WORKDIR}/archlinux-$(translate_arch "$arch")"
sudo tar -zxpf "${WORKDIR}/archlinux-${arch}.tar.gz" \
sudo tar -zxp --acls --xattrs --xattrs-include='*' \
-f "${WORKDIR}/archlinux-${arch}.tar.gz" \
-C "${WORKDIR}/archlinux-$(translate_arch "$arch")"

cat <<- EOF | sudo unshare -mpf bash -e -
Expand All @@ -32,11 +33,8 @@ bootstrap_distribution() {

sudo rm -f "${WORKDIR:?}/archlinux-$(translate_arch "$arch")"/var/cache/pacman/pkg/* || true

sudo tar -J -c \
-f "${ROOTFS_DIR}/archlinux-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz" \
-C "$WORKDIR" \
archive_rootfs "${ROOTFS_DIR}/archlinux-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz" \
"archlinux-$(translate_arch "$arch")"
sudo chown $(id -un):$(id -gn) "${ROOTFS_DIR}/archlinux-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz"
done
unset arch

Expand All @@ -48,7 +46,7 @@ bootstrap_distribution() {
"https://mirror.rackspace.com/archlinux/iso/${dist_version}/archlinux-bootstrap-${dist_version}-x86_64.tar.gz"

sudo mkdir -m 755 "${WORKDIR}/archlinux-bootstrap"
sudo tar -zxp --strip-components=1 \
sudo tar -zxp --strip-components=1 --acls --xattrs --xattrs-include='*' \
-f "${WORKDIR}/archlinux-x86_64.tar.gz" \
-C "${WORKDIR}/archlinux-bootstrap"

Expand Down Expand Up @@ -76,10 +74,8 @@ bootstrap_distribution() {

for arch in i686 x86_64; do
sudo rm -f "${WORKDIR:?}/archlinux-bootstrap/archlinux-${arch}"/var/cache/pacman/pkg/* || true
sudo tar -Jcf "${ROOTFS_DIR}/archlinux-${arch}-pd-${CURRENT_VERSION}.tar.xz" \
-C "${WORKDIR}/archlinux-bootstrap" \
archive_rootfs "${ROOTFS_DIR}/archlinux-${arch}-pd-${CURRENT_VERSION}.tar.xz" \
"archlinux-${arch}"
sudo chown $(id -un):$(id -gn) "${ROOTFS_DIR}/archlinux-${arch}-pd-${CURRENT_VERSION}.tar.xz"
done
unset arch
}
Expand Down
8 changes: 3 additions & 5 deletions distro-build/artix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ bootstrap_distribution() {
"https://armtixlinux.org/images/armtix-runit-20230401.tar.xz"

sudo mkdir -m 755 "${WORKDIR}/artix-aarch64"
sudo tar -Jxpf "${WORKDIR}/artix-aarch64.tar.xz" \
sudo tar -Jxp --acls --xattrs --xattrs-include='*' \
-f "${WORKDIR}/artix-aarch64.tar.xz" \
-C "${WORKDIR}/artix-aarch64"

cat <<- EOF | sudo unshare -mpf bash -e -
Expand All @@ -25,11 +26,8 @@ bootstrap_distribution() {

sudo rm -f "${WORKDIR:?}/artix-aarch64"/var/cache/pacman/pkg/* || true

sudo tar -J -c \
-f "${ROOTFS_DIR}/artix-aarch64-pd-${CURRENT_VERSION}.tar.xz" \
-C "$WORKDIR" \
archive_rootfs "${ROOTFS_DIR}/artix-aarch64-pd-${CURRENT_VERSION}.tar.xz" \
"artix-aarch64"
sudo chown $(id -un):$(id -gn) "${ROOTFS_DIR}/artix-aarch64-pd-${CURRENT_VERSION}.tar.xz"
}

write_plugin() {
Expand Down
5 changes: 1 addition & 4 deletions distro-build/deepin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ bootstrap_distribution() {
env DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot "${WORKDIR}/deepin-$(translate_arch "$arch")" dpkg --configure -a
EOF

sudo tar -J -c \
-f "${ROOTFS_DIR}/deepin-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz" \
-C "$WORKDIR" \
archive_rootfs "${ROOTFS_DIR}/deepin-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz" \
"deepin-$(translate_arch "$arch")"
sudo chown $(id -un):$(id -gn) "${ROOTFS_DIR}/deepin-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz"
done
unset arch
}
Expand Down
7 changes: 3 additions & 4 deletions distro-build/manjaro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bootstrap_distribution() {
"https://github.com/manjaro-arm/rootfs/releases/download/${dist_version}/Manjaro-ARM-aarch64-latest.tar.gz"

mkdir "${WORKDIR}/manjaro-aarch64"
sudo tar -xp \
sudo tar -xp --acls --xattrs --xattrs-include='*' \
-f "${WORKDIR}/manjaro-aarch64.tar.xz" \
-C "${WORKDIR}/manjaro-aarch64"

Expand All @@ -30,9 +30,8 @@ bootstrap_distribution() {

sudo rm -f "${WORKDIR:?}"/manjaro-aarch64/var/cache/pacman/pkg/* || true

sudo tar -Jcf "${ROOTFS_DIR}/manjaro-aarch64-pd-${CURRENT_VERSION}.tar.xz" \
-C "${WORKDIR}/manjaro-aarch64" ./
sudo chown $(id -un):$(id -gn) "${ROOTFS_DIR}/manjaro-aarch64-pd-${CURRENT_VERSION}.tar.xz"
archive_rootfs "${ROOTFS_DIR}/manjaro-aarch64-pd-${CURRENT_VERSION}.tar.xz" \
"manjaro-aarch64"
}

write_plugin() {
Expand Down
7 changes: 2 additions & 5 deletions distro-build/void.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bootstrap_distribution() {
"https://repo-default.voidlinux.org/live/${dist_version}/void-${arch}-ROOTFS-${dist_version}.tar.xz"

sudo mkdir -m 755 "${WORKDIR}/void-$(translate_arch "$arch")"
sudo tar -Jxp \
sudo tar -Jxp --acls --xattrs --xattrs-include='*' \
-f "${WORKDIR}/void-${arch}.tar.xz" \
-C "${WORKDIR}/void-$(translate_arch "$arch")"

Expand All @@ -29,11 +29,8 @@ bootstrap_distribution() {

sudo rm -f "${WORKDIR}/void-$(translate_arch "$arch")"/var/cache/xbps/* || true

sudo tar -J -c \
-f "${ROOTFS_DIR}/void-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz" \
-C "$WORKDIR" \
archive_rootfs "${ROOTFS_DIR}/void-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz" \
"void-$(translate_arch "$arch")"
sudo chown $(id -un):$(id -gn) "${ROOTFS_DIR}/void-$(translate_arch "$arch")-pd-${CURRENT_VERSION}.tar.xz"
done
}

Expand Down

0 comments on commit 7e95435

Please sign in to comment.