From 95d1930874ecb63c853132bd305b89a59c2c52da Mon Sep 17 00:00:00 2001 From: Tobias Powalowski Date: Sun, 9 Jan 2022 14:05:36 +0100 Subject: [PATCH] speedup aarch64-create-container by using pacman on runnin aarch64 --- usr/bin/archboot-aarch64-create-container.sh | 62 ++++++++++++++------ 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/usr/bin/archboot-aarch64-create-container.sh b/usr/bin/archboot-aarch64-create-container.sh index c223a471c..8a6df9112 100755 --- a/usr/bin/archboot-aarch64-create-container.sh +++ b/usr/bin/archboot-aarch64-create-container.sh @@ -44,13 +44,41 @@ if ! [[ ${UID} -eq 0 ]]; then exit 1 fi -# prepare pacman dirs echo "Starting container creation ..." -echo "Downloading archlinuxarm aarch64..." -! [[ -f ArchLinuxARM-aarch64-latest.tar.gz ]] && wget ${LATEST_ARM64} >/dev/null 2>&1 echo "Create directories in ${_DIR} ..." mkdir "${_DIR}" -bsdtar -xf ArchLinuxARM-aarch64-latest.tar.gz -C "${_DIR}" +if [[ "$(uname -m)" == "aarch64" ]]; then + # prepare pacman dirs + echo "Create directories in ${_DIR} ..." + mkdir -p "${_DIR}"/var/lib/pacman + mkdir -p "${_CACHEDIR}" + [[ -e "${_DIR}/proc" ]] || mkdir -m 555 "${_DIR}/proc" + [[ -e "${_DIR}/sys" ]] || mkdir -m 555 "${_DIR}/sys" + [[ -e "${_DIR}/dev" ]] || mkdir -m 755 "${_DIR}/dev" + # mount special filesystems to ${_DIR} + echo "Mount special filesystems in ${_DIR} ..." + mount proc ""${_DIR}"/proc" -t proc -o nosuid,noexec,nodev + mount sys ""${_DIR}"/sys" -t sysfs -o nosuid,noexec,nodev,ro + mount udev ""${_DIR}"/dev" -t devtmpfs -o mode=0755,nosuid + mount devpts ""${_DIR}"/dev/pts" -t devpts -o mode=0620,gid=5,nosuid,noexec + mount shm ""${_DIR}"/dev/shm" -t tmpfs -o mode=1777,nosuid,nodev + # install archboot + echo "Installing packages base firmware and archboot to ${_DIR} ..." + pacman --root "${_DIR}" -Sy base archboot "${_LINUX_FIRMWARE}" --ignore systemd-resolvconf --noconfirm --cachedir "${_PWD}"/"${_CACHEDIR}" >/dev/null 2>&1 + # umount special filesystems + echo "Umount special filesystems in to ${_DIR} ..." + umount -R ""${_DIR}"/proc" + umount -R ""${_DIR}"/sys" + umount -R ""${_DIR}"/dev" +fi +if [[ "$(uname -m)" == "x86_64" ]]; then + echo "Downloading archlinuxarm aarch64..." + ! [[ -f ArchLinuxARM-aarch64-latest.tar.gz ]] && wget ${LATEST_ARM64} >/dev/null 2>&1 + bsdtar -xf ArchLinuxARM-aarch64-latest.tar.gz -C "${_DIR}" + echo "Removing installation tarball ..." + rm ArchLinuxARM-aarch64-latest.tar.gz +fi +# generate locales echo "Create locales in container ..." systemd-nspawn -D "${_DIR}" /bin/bash -c "echo 'en_US ISO-8859-1' >> /etc/locale.gen" >/dev/null 2>&1 systemd-nspawn -D "${_DIR}" /bin/bash -c "echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen" >/dev/null 2>&1 @@ -63,17 +91,19 @@ systemd-nspawn -D "${_DIR}" pacman-key --populate archlinuxarm >/dev/null 2>&1 sed -i -e 's:^CheckSpace:#CheckSpace:g' "${_DIR}"/etc/pacman.conf # enable parallel downloads sed -i -e 's:^#ParallelDownloads:ParallelDownloads:g' "${_DIR}"/etc/pacman.conf -# fix network in container -rm "${_DIR}/etc/resolv.conf" -echo "nameserver 8.8.8.8" > "${_DIR}/etc/resolv.conf" -# update container to latest packages -echo "Update container to latest packages..." -systemd-nspawn -D "${_DIR}" pacman -Syu --noconfirm >/dev/null 2>&1 -# remove linux hook to speedup -echo "Remove 60-linux-aarch64.hook from container..." -rm "${_DIR}/usr/share/libalpm/hooks/60-linux-aarch64.hook" -echo "Installing archboot-arm and firmware to container..." -systemd-nspawn -D "${_DIR}" /bin/bash -c "yes | pacman -S archboot-arm ${_LINUX_FIRMWARE}" >/dev/null 2>&1 +if [[ "$(uname -m)" == "x86_64" ]]; then + # fix network in container + rm "${_DIR}/etc/resolv.conf" + echo "nameserver 8.8.8.8" > "${_DIR}/etc/resolv.conf" + # update container to latest packages + echo "Update container to latest packages..." + systemd-nspawn -D "${_DIR}" pacman -Syu --noconfirm >/dev/null 2>&1 + # remove linux hook to speedup + echo "Remove 60-linux-aarch64.hook from container..." + rm "${_DIR}/usr/share/libalpm/hooks/60-linux-aarch64.hook" + echo "Installing archboot-arm and firmware to container..." + systemd-nspawn -D "${_DIR}" /bin/bash -c "yes | pacman -S archboot-arm ${_LINUX_FIRMWARE}" >/dev/null 2>&1 +fi echo "Setting hostname to archboot ..." systemd-nspawn -D "${_DIR}" /bin/bash -c "echo archboot > /etc/hostname" >/dev/null 2>&1 if [[ "${_SAVE_RAM}" == "1" ]]; then @@ -87,8 +117,6 @@ if [[ "${_CLEANUP_CACHE}" == "1" ]]; then echo "Clean pacman cache from ${_DIR} ..." rm -r "${_DIR}"/var/cache/pacman fi -echo "Removing installation tarball ..." -rm ArchLinuxARM-aarch64-latest.tar.gz echo "Finished container setup in ${_DIR} ."