switch root to archboot container

This commit is contained in:
Tobias Powalowski 2022-06-02 13:41:30 +02:00
parent 6bebb3f60e
commit d90a7dab6d
2 changed files with 27 additions and 36 deletions

View file

@ -40,40 +40,39 @@ _zram_initialize
if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
_update_installer_check _update_installer_check
touch /.update-installer touch /.update-installer
echo -e "\033[1mStep 1/8:\033[0m Removing not necessary files from / ..." if ! [[ -e /etc/profile.d/zz-00-archboot ]]; then
_clean_archboot echo -e "\033[1mStep 1/2:\033[0m Removing not necessary files from / ..."
echo -e "\033[1mStep 2/8:\033[0m Generating archboot container in ${_W_DIR} ..." _clean_archboot
echo " This will need some time ..." echo -e "\033[1mStep 2/3:\033[0m Generating archboot container in ${_W_DIR} ..."
_create_container || exit 1 echo " This will need some time ..."
# 10 seconds for getting free RAM _create_container || exit 1
sleep 10 echo "update-installer.sh ${_RUN_OPTION}" > /archboot/etc/profile.d/zz-00-archboot
echo -e "\033[1mStep 3/8:\033[0m Moving kernel ${VMLINUZ} to /${VMLINUZ} ..." systemctl stop dbus
mv "${_W_DIR}"/boot/${VMLINUZ} / || exit 1 echo -e "\033[1mStep 3/3:\033[0m Switching to new root ${_W_DIR} ..."
systemctl switch-root ${_W_DIR}
fi
[[ ${_RUNNING_ARCH} == "x86_64" ]] && _kver_x86 [[ ${_RUNNING_ARCH} == "x86_64" ]] && _kver_x86
[[ ${_RUNNING_ARCH} == "aarch64" ]] && _kver_generic [[ ${_RUNNING_ARCH} == "aarch64" ]] && _kver_generic
echo -e "\033[1mStep 4/8:\033[0m Collect initramfs files in ${_W_DIR} ..." echo -e "\033[1mStep 1/4:\033[0m Collect initramfs files ..."
echo " This will need some time ..." echo " This will need some time ..."
# add fix for mkinitcpio 31, remove when 32 is released # 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 /usr/share/archboot/patches/31-mkinitcpio.fixed /usr/bin/mkinitcpio
cp "${_W_DIR}"/usr/share/archboot/patches/31-initcpio.functions.fixed "${_W_DIR}"/usr/lib/initcpio/functions cp /usr/share/archboot/patches/31-initcpio.functions.fixed /usr/lib/initcpio/functions
# write initramfs to "${_W_DIR}"/tmp # 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 mkinitcpio -k ${_HWKVER} -c ${_CONFIG} -d /tmp >/dev/tty7 2>&1 || exit 1
rm -f "${_W_DIR}"/tmp/etc/initrd-release rm -f /tmp/etc/initrd-release
echo -e "\033[1mStep 5/8:\033[0m Cleanup ${_W_DIR} ..." #echo -e "\033[1mStep 5/8:\033[0m Cleanup ${_W_DIR} ..."
find "${_W_DIR}"/. -mindepth 1 -maxdepth 1 ! -name 'tmp' ! -name "${VMLINUZ}" -exec rm -rf {} \; #find "${_W_DIR}"/. -mindepth 1 -maxdepth 1 ! -name 'tmp' ! -name "${VMLINUZ}" -exec rm -rf {} \;
# 10 seconds for getting free RAM # 10 seconds for getting free RAM
sleep 10 #sleep 10
echo -e "\033[1mStep 6/8:\033[0m Create initramfs /initrd.img ..." echo -e "\033[1mStep 2/4:\033[0m Create initramfs /initrd.img ..."
echo " This will need some time ..." echo " This will need some time ..."
_create_initramfs _create_initramfs
echo -e "\033[1mStep 7/8:\033[0m Cleanup ${_W_DIR} ..." echo -e "\033[1mStep 3/4:\033[0m Cleanup ${_W_DIR} ..."
rm -r "${_W_DIR}"
# wait 5 seconds to get RAM cleared and set free
sleep 5
cd / cd /
# unload virtio-net to avoid none functional network device on aarch64 # unload virtio-net to avoid none functional network device on aarch64
grep -qw virtio_net /proc/modules && rmmod virtio_net grep -qw virtio_net /proc/modules && rmmod virtio_net
echo -e "\033[1mStep 8/8:\033[0m Loading files through kexec into kernel now ..." echo -e "\033[1mStep 4/4:\033[0m Loading files through kexec into kernel now ..."
echo " This will need some time ..." echo " This will need some time ..."
_kexec _kexec
fi fi

View file

@ -198,7 +198,6 @@ _create_container() {
#online mode #online mode
if [[ "${_L_INSTALL_COMPLETE}" == "1" ]]; then if [[ "${_L_INSTALL_COMPLETE}" == "1" ]]; then
"archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc >/dev/tty7 2>&1 || exit 1 "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
fi fi
} }
@ -227,17 +226,9 @@ _kver_generic() {
} }
_create_initramfs() { _create_initramfs() {
# move cache back to initramfs directory in online mode
if ! [[ -e /var/cache/pacman/pkg/archboot.db ]]; then
if [[ "${_L_INSTALL_COMPLETE}" == "1" ]]; then
if [[ -d /var/cache/pacman/pkg ]]; then
mv /var/cache/pacman/pkg ${_W_DIR}/tmp/var/cache/pacman/
fi
fi
fi
#from /usr/bin/mkinitcpio.conf #from /usr/bin/mkinitcpio.conf
# compress image with zstd # compress image with zstd
cd "${_W_DIR}"/tmp || exit 1 cd /tmp || exit 1
find . -mindepth 1 -printf '%P\0' | sort -z | find . -mindepth 1 -printf '%P\0' | sort -z |
bsdtar --uid 0 --gid 0 --null -cnf - -T - | bsdtar --uid 0 --gid 0 --null -cnf - -T - |
bsdtar --null -cf - --format=newc @- | zstd --rm -T0> /initrd.img bsdtar --null -cf - --format=newc @- | zstd --rm -T0> /initrd.img
@ -256,13 +247,14 @@ _kexec () {
echo -e "\033[1m\033[93m- Possibility of not working kexec boot.\033[0m" echo -e "\033[1m\033[93m- Possibility of not working kexec boot.\033[0m"
echo -e "\033[1m\033[93m- Please use more or less RAM.\033[0m" echo -e "\033[1m\033[93m- Please use more or less RAM.\033[0m"
fi fi
kexec -s -f /"${VMLINUZ}" --initrd="/initrd.img" --reuse-cmdline & kexec -s -f /boot/"${VMLINUZ}" --initrd="/initrd.img" --reuse-cmdline &
else else
echo -e "Running \033[1m\033[92mkexec\033[0m with \033[1mold\033[0m KEXEC_LOAD ..." echo -e "Running \033[1m\033[92mkexec\033[0m with \033[1mold\033[0m KEXEC_LOAD ..."
# works on systems with <4GB # works on systems with <4GB
kexec -c -f /"${VMLINUZ}" --initrd="/initrd.img" --reuse-cmdline & kexec -c -f /boot/"${VMLINUZ}" --initrd="/initrd.img" --reuse-cmdline &
sleep 2 sleep 2
rm /{${VMLINUZ},initrd.img} rm /boot/"${VMLINUZ}"
rm /initrd.img
fi fi
while pgrep -x kexec > /dev/null 2>&1; do while pgrep -x kexec > /dev/null 2>&1; do
sleep 1 sleep 1