mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-20 03:50:37 +02:00
huge optimizing of update installer with saving RAM
This commit is contained in:
parent
f59fa731c2
commit
bfc64c2a2f
1 changed files with 82 additions and 82 deletions
|
@ -8,16 +8,17 @@ _G_RELEASE=""
|
|||
_CONFIG="/etc/archboot/${_RUNNING_ARCH}-update_installer.conf"
|
||||
_W_DIR="/archboot"
|
||||
_INSTALLER_SOURCE="https://gitlab.archlinux.org/tpowa/archboot/-/raw/master"
|
||||
_LIB_PATH="/usr/lib/archboot"
|
||||
_INST_PATH="${_LIB_PATH}/installer"
|
||||
_BIN_PATH="${_INSTALLER_SOURCE}/usr/bin"
|
||||
_LIB_PATH="${_INSTALLER_SOURCE}/usr/lib/archboot"
|
||||
_INST_PATH="${_INSTALLER_SOURCE}/${_LIB_PATH}/installer"
|
||||
|
||||
kver() {
|
||||
# get kernel version from installed kernel
|
||||
[[ "${_RUNNING_ARCH}" == "x86_64" ]] && VMLINUZ="/vmlinuz-linux"
|
||||
[[ "${_RUNNING_ARCH}" == "aarch64" ]] && VMLINUZ="/Image"
|
||||
[[ "${_RUNNING_ARCH}" == "x86_64" ]] && VMLINUZ="vmlinuz-linux"
|
||||
[[ "${_RUNNING_ARCH}" == "aarch64" ]] && VMLINUZ="Image"
|
||||
if [[ -f "${VMLINUZ}" ]]; then
|
||||
offset=$(hexdump -s 526 -n 2 -e '"%0d"' "${VMLINUZ}")
|
||||
read -r _HWKVER _ < <(dd if="${VMLINUZ}" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null)
|
||||
read -r _HWKVER _ < <(dd if="/${VMLINUZ}" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null)
|
||||
fi
|
||||
# fallback if no detectable kernel is installed
|
||||
[[ "${_HWKVER}" == "" ]] && _HWKVER="$(uname -r)"
|
||||
|
@ -31,14 +32,14 @@ usage () {
|
|||
echo ""
|
||||
echo "On fast internet connection (100Mbit) (approx. 5 minutes):"
|
||||
echo " -latest Launch latest archboot environment (using kexec)."
|
||||
echo " This operation needs at least 2.4 GB RAM."
|
||||
echo " This operation needs at least 2.3 GB RAM."
|
||||
echo ""
|
||||
echo " -latest-install Launch latest archboot environment with downloaded"
|
||||
echo " package cache (using kexec)."
|
||||
echo " This operation needs at least 2.9 GB RAM."
|
||||
echo " This operation needs at least 2.7 GB RAM."
|
||||
echo ""
|
||||
echo " -latest-image Generate latest image files in /archboot-release directory"
|
||||
echo " This operation needs at least 3.3 GB RAM."
|
||||
echo " This operation needs at least 4.6 GB RAM."
|
||||
echo ""
|
||||
echo " -h This message."
|
||||
exit 0
|
||||
|
@ -66,31 +67,31 @@ fi
|
|||
# Download latest setup and quickinst script from git repository
|
||||
if [[ "${_D_SCRIPTS}" == "1" ]]; then
|
||||
echo "Downloading latest km, tz, quickinst, setup and helpers..."
|
||||
wget -q "$_INSTALLER_SOURCE/usr/bin/archboot-quickinst.sh?inline=false" -O /usr/bin/quickinst >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE/usr/bin/archboot-setup.sh?inline=false" -O /usr/bin/setup >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE/usr/bin/archboot-km.sh?inline=false" -O /usr/bin/km >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE/usr/bin/archboot-tz.sh?inline=false" -O /usr/bin/tz >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE/usr/bin/archboot-${_RUNNING_ARCH}-create-container.sh?inline=false" -O "/usr/bin/archboot-${_RUNNING_ARCH}-create-container.sh" >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE/usr/bin/archboot-${_RUNNING_ARCH}-release.sh?inline=false" -O "/usr/bin/archboot-${_RUNNING_ARCH}-release.sh" >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE/usr/bin/archboot-binary-check.sh?inline=false" -O /usr/bin/archboot-binary-check.sh >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE/usr/bin/archboot-update-installer.sh?inline=false" -O /usr/bin/update-installer.sh >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_LIB_PATH}/common.sh?inline=false" -O "${_LIB_PATH}/common.sh" >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_LIB_PATH}/container.sh?inline=false" -O "${_LIB_PATH}/container.sh" >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_LIB_PATH}/release.sh?inline=false" -O "${_LIB_PATH}/release.sh" >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_LIB_PATH}/iso.sh?inline=false" -O "${_LIB_PATH}/iso.sh" >/dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/autoconfiguration.sh?inline=false" -O "${_INST_PATH}/autoconfiguration.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/autoprepare.sh?inline=false" -O "${_INST_PATH}/autoprepare.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/base.sh?inline=false" -O "${_INST_PATH}/base.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/blockdevices.sh?inline=false" -O "${_INST_PATH}/blockdevices.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/bootloader.sh?inline=false" -O "${_INST_PATH}/bootloader.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/btrfs.sh?inline=false" -O "${_INST_PATH}/btrfs.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/common.sh?inline=false" -O "${_INST_PATH}/common.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/configuration.sh?inline=false" -O "${_INST_PATH}/configuration.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/mountpoints.sh?inline=false" -O "${_INST_PATH}/mountpoints.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/network.sh?inline=false" -O "${_INST_PATH}/network.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/pacman.sh?inline=false" -O "${_INST_PATH}/pacman.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/partition.sh?inline=false" -O "${_INST_PATH}/partition.sh" > /dev/null 2>&1
|
||||
wget -q "$_INSTALLER_SOURCE${_INST_PATH}/storage.sh?inline=false" -O "${_INST_PATH}/storage.sh" > /dev/null 2>&1
|
||||
wget -q "${_BIN_PATH}/archboot-quickinst.sh?inline=false" -O /usr/bin/quickinst >/dev/null 2>&1
|
||||
wget -q "${_BIN_PATH}/archboot-setup.sh?inline=false" -O /usr/bin/setup >/dev/null 2>&1
|
||||
wget -q "${_BIN_PATH}/archboot-km.sh?inline=false" -O /usr/bin/km >/dev/null 2>&1
|
||||
wget -q "${_BIN_PATH}/archboot-tz.sh?inline=false" -O /usr/bin/tz >/dev/null 2>&1
|
||||
wget -q "${_BIN_PATH}/archboot-${_RUNNING_ARCH}-create-container.sh?inline=false" -O "/usr/bin/archboot-${_RUNNING_ARCH}-create-container.sh" >/dev/null 2>&1
|
||||
wget -q "${_BIN_PATH}/archboot-${_RUNNING_ARCH}-release.sh?inline=false" -O "/usr/bin/archboot-${_RUNNING_ARCH}-release.sh" >/dev/null 2>&1
|
||||
wget -q "${_BIN_PATH}/archboot-binary-check.sh?inline=false" -O /usr/bin/archboot-binary-check.sh >/dev/null 2>&1
|
||||
wget -q "${_BIN_PATH}/archboot-update-installer.sh?inline=false" -O /usr/bin/update-installer.sh >/dev/null 2>&1
|
||||
wget -q "${_LIB_PATH}/common.sh?inline=false" -O "${_LIB_PATH}/common.sh" >/dev/null 2>&1
|
||||
wget -q "${_LIB_PATH}/container.sh?inline=false" -O "${_LIB_PATH}/container.sh" >/dev/null 2>&1
|
||||
wget -q "${_LIB_PATH}/release.sh?inline=false" -O "${_LIB_PATH}/release.sh" >/dev/null 2>&1
|
||||
wget -q "${_LIB_PATH}/iso.sh?inline=false" -O "${_LIB_PATH}/iso.sh" >/dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/autoconfiguration.sh?inline=false" -O "${_INST_PATH}/autoconfiguration.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/autoprepare.sh?inline=false" -O "${_INST_PATH}/autoprepare.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/base.sh?inline=false" -O "${_INST_PATH}/base.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/blockdevices.sh?inline=false" -O "${_INST_PATH}/blockdevices.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/bootloader.sh?inline=false" -O "${_INST_PATH}/bootloader.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/btrfs.sh?inline=false" -O "${_INST_PATH}/btrfs.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/common.sh?inline=false" -O "${_INST_PATH}/common.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/configuration.sh?inline=false" -O "${_INST_PATH}/configuration.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/mountpoints.sh?inline=false" -O "${_INST_PATH}/mountpoints.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/network.sh?inline=false" -O "${_INST_PATH}/network.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/pacman.sh?inline=false" -O "${_INST_PATH}/pacman.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/partition.sh?inline=false" -O "${_INST_PATH}/partition.sh" > /dev/null 2>&1
|
||||
wget -q "${_INST_PATH}/storage.sh?inline=false" -O "${_INST_PATH}/storage.sh" > /dev/null 2>&1
|
||||
echo "Finished: Downloading scripts done."
|
||||
exit 0
|
||||
fi
|
||||
|
@ -105,18 +106,12 @@ if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
touch /.update-installer
|
||||
# zram part
|
||||
modprobe zram
|
||||
echo zstd > /sys/block/zram0/comp_algorithm
|
||||
echo 1400M > /sys/block/zram0/disk_size
|
||||
mkfs.btrfs /dev/zram0
|
||||
mkdir -p ${_W_DIR}
|
||||
mount -o compress=zstd /dev/zram0 ${_W_DIR}
|
||||
# remove everything not necessary
|
||||
echo "Step 1/9: Removing not necessary files from / ..."
|
||||
[[ -d "/usr/lib/firmware" ]] && rm -r "/usr/lib/firmware"
|
||||
[[ -d "/usr/lib/modules" ]] && rm -r "/usr/lib/modules"
|
||||
_SHARE_DIRS="efitools file grub hwdata kbd licenses makepkg nmap openvpn pacman refind tc usb_modeswitch vim zoneinfo zsh"
|
||||
rm -f /usr/lib/{libicu*,libstdc++*}
|
||||
_SHARE_DIRS="archboot efitools file grub hwdata kbd licenses lshw makepkg nmap nano openvpn pacman refind systemd tc usb_modeswitch vim zoneinfo"
|
||||
for i in ${_SHARE_DIRS}; do
|
||||
#shellcheck disable=SC2115
|
||||
[[ -d "/usr/share/${i}" ]] && rm -r "/usr/share/${i}"
|
||||
|
@ -125,67 +120,72 @@ if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
|||
while pgrep -x gpg > /dev/null 2>&1; do
|
||||
sleep 1
|
||||
done
|
||||
systemctl stop pacman-init.service
|
||||
echo "Step 3/9: Generating archboot container in ${_W_DIR} ..."
|
||||
echo " This will need some time ..."
|
||||
# create container without package cache
|
||||
[[ "${_L_COMPLETE}" == "1" ]] && ("archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc -cp >/dev/tty7 2>&1 || exit 1)
|
||||
if [[ "${_L_COMPLETE}" == "1" ]]; then
|
||||
"archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc -cp >/dev/tty7 2>&1 || exit 1
|
||||
fi
|
||||
# create container with package cache
|
||||
if [[ -e /var/cache/pacman/pkg/archboot.db ]]; then
|
||||
# offline mode
|
||||
# offline mode, for testing purposes
|
||||
# add the db too on reboot
|
||||
install -D -m644 /var/cache/pacman/pkg/archboot.db /archboot/var/cache/pacman/pkg/archboot.db
|
||||
[[ "${_L_INSTALL_COMPLETE}" == "1" ]] && ("archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc --install-source=file:///var/cache/pacman/pkg >/dev/tty7 2>&1 || exit 1)
|
||||
if [[ "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
||||
"archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc --install-source=file:///var/cache/pacman/pkg >/dev/tty7 2>&1 || exit 1
|
||||
fi
|
||||
else
|
||||
#online mode
|
||||
[[ "${_L_INSTALL_COMPLETE}" == "1" ]] && ("archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc >/dev/tty7 2>&1 || exit 1)
|
||||
fi
|
||||
# generate initrd in container, remove archboot packages from cache, not needed in normal install, umount tmp before generating initrd
|
||||
echo "Step 4/9: Moving kernel from ${_W_DIR} to / ..."
|
||||
if [[ "${_RUNNING_ARCH}" == "x86_64" ]]; then
|
||||
mv "${_W_DIR}"/boot/vmlinuz-linux / || exit 1
|
||||
### not supported
|
||||
#mv "${_W_DIR}"/boot/intel-ucode.img / || exit 1
|
||||
fi
|
||||
if [[ "${_RUNNING_ARCH}" == "aarch64" ]]; then
|
||||
mv "${_W_DIR}"/boot/Image / || exit 1
|
||||
if [[ "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
||||
"archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc >/dev/tty7 2>&1 || exit 1
|
||||
mv "${_W_DIR}"/var/cache/pacman/pkg /var/cache/pacman/
|
||||
fi
|
||||
fi
|
||||
echo "Step 4/9: Moving kernel ${VMLINUZ} to ${_W_DIR} ..."
|
||||
kver
|
||||
mv "${_W_DIR}"/boot/${VMLINUZ} "${_W_DIR}"/ || exit 1
|
||||
echo "Step 5/9: Collect initramfs files in ${_W_DIR} ..."
|
||||
echo " This will need some time ..."
|
||||
# add fix for mkinitcpio 31, remove when 32 is released
|
||||
cp "${_W_DIR}"/usr/share/archboot/patches/31-mkinitcpio.fixed "${_W_DIR}"/usr/bin/mkinitcpio
|
||||
cp "${_W_DIR}"/usr/share/archboot/patches/31-initcpio.functions.fixed "${_W_DIR}"/usr/lib/initcpio/functions
|
||||
kver
|
||||
# write initramfs to /tmp
|
||||
systemd-nspawn -q -D "${_W_DIR}" /bin/bash -c "umount /tmp; mkinitcpio -k ${_HWKVER} -c ${_CONFIG} -d /tmp/" >/dev/tty7 2>&1 || exit 1
|
||||
# move initramfs to /
|
||||
mv "${_W_DIR}/tmp" /initrd || exit 1
|
||||
echo "Step 6/9: Remove ${_W_DIR} ..."
|
||||
rm -r "${_W_DIR}" || exit 1
|
||||
echo "Step 7/9: Create initramfs /initrd.img ..."
|
||||
# write initramfs to "${_W_DIR}"/tmp
|
||||
systemd-nspawn -D "${_W_DIR}" /bin/bash -c "umount tmp;mkinitcpio -k ${_HWKVER} -c ${_CONFIG} -d /tmp" >/dev/tty7 2>&1 || exit 1
|
||||
#mv "${_W_DIR}/tmp" /initrd || exit 1
|
||||
echo "Step 6/9: Cleanup ${_W_DIR} ..."
|
||||
find "${_W_DIR}"/. -mindepth 1 -maxdepth 1 ! -name 'tmp' ! -name "${VMLINUZ}" -exec rm -rf {} \;
|
||||
echo "Step 7/9: Create initramfs initrd.img ..."
|
||||
echo " This will need some time ..."
|
||||
cd initrd || exit 1
|
||||
# move cache back to initramfs directory in online mode
|
||||
if ! [[ -e /var/cache/pacman/pkg/archboot.db ]]; then
|
||||
[[ "${_L_INSTALL_COMPLETE}" == "1" ]] && mv /var/cache/pacman/pkg ${_W_DIR}/tmp/var/cache/pacman/
|
||||
fi
|
||||
#from /usr/bin/mkinitpcio.conf
|
||||
# compress image with zstd
|
||||
cd "${_W_DIR}"/tmp || exit 1
|
||||
find . -mindepth 1 -printf '%P\0' | sort -z |
|
||||
LANG=C bsdtar --uid 0 --gid 0 --null -cnf - -T - |
|
||||
LANG=C bsdtar --null -cf - --format=newc @- | zstd -T0 -10> /initrd.img || exit 1
|
||||
cd ..
|
||||
echo "Step 8/9: Remove /initrd ..."
|
||||
rm -r "/initrd" || exit 1
|
||||
### not supported
|
||||
#mv "${_W_DIR}"/boot/amd-ucode.img / || exit 1
|
||||
# remove "${_W_DIR}"
|
||||
echo "Step 9/9: Loading files to kexec now, reboot in a few seconds ..."
|
||||
# load kernel and initrds into running kernel
|
||||
if [[ "${_RUNNING_ARCH}" == "x86_64" ]]; then
|
||||
kexec -l /vmlinuz-linux --initrd=/initrd.img --reuse-cmdline
|
||||
fi
|
||||
if [[ "${_RUNNING_ARCH}" == "aarch64" ]]; then
|
||||
kexec -l /Image --initrd=/initrd.img --reuse-cmdline
|
||||
fi
|
||||
echo "Finished: Rebooting ..."
|
||||
# restart environment
|
||||
systemctl kexec
|
||||
LANG=C bsdtar --null -cf - --format=newc @- | zstd -T0 -10> "${_W_DIR}"/initrd.img
|
||||
for i in $(find . -mindepth 1 -type f | sort); do
|
||||
rm "${i}" >/dev/null 2>&1
|
||||
done
|
||||
while pgreg -x bsdtar >/dev/null 2>&1; do
|
||||
sleep 1
|
||||
done
|
||||
echo "Step 8/9: Cleanup ${_W_DIR}/tmp ..."
|
||||
rm -r "${_W_DIR}"/tmp
|
||||
echo "Step 9/9: Loading files through kexec into kernel now ..."
|
||||
# load kernel and initrds into running kernel in background mode!
|
||||
kexec -f "${_W_DIR}"/${VMLINUZ} --initrd="${_W_DIR}"/initrd.img --reuse-cmdline&
|
||||
sleep 1
|
||||
# remove kernel and initrd to save RAM for kexec in background
|
||||
rm "${_W_DIR}"/{initrd.img,${VMLINUZ}}
|
||||
while pgreg -x kexec >/dev/null 2>&1; do
|
||||
sleep 1
|
||||
done
|
||||
echo "Finished: Rebooting in a few seconds ..."
|
||||
sleep 30
|
||||
fi
|
||||
|
||||
# Generate new images
|
||||
|
|
Loading…
Reference in a new issue