mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-20 03:50:37 +02:00
huge RAM improvement on latest image
This commit is contained in:
parent
1e588a4c2b
commit
f2a70dd30b
1 changed files with 47 additions and 18 deletions
|
@ -24,6 +24,32 @@ kver() {
|
||||||
[[ "${_HWKVER}" == "" ]] && _HWKVER="$(uname -r)"
|
[[ "${_HWKVER}" == "" ]] && _HWKVER="$(uname -r)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zram_mount() {
|
||||||
|
modprobe zram
|
||||||
|
echo zstd >/sys/block/zram0/comp_algorithm
|
||||||
|
echo 3G >/sys/block/zram0/disksize
|
||||||
|
echo 4 >/sys/block/zram0/max_comp_streams
|
||||||
|
mkfs.btrfs --mixed /dev/zram0 > /dev/tty7 2>&1 || exit 1
|
||||||
|
mkdir "${_W_DIR}"
|
||||||
|
# use -o discard for RAM cleaning on delete
|
||||||
|
# (online fstrimming the block device!)
|
||||||
|
# fstrim <mountpoint> for manual action
|
||||||
|
# it needs some seconds to get RAM free on delete!
|
||||||
|
mount -o discard /dev/zram0 "${_W_DIR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_archboot() {
|
||||||
|
# remove everything not necessary
|
||||||
|
rm -rf "/usr/lib/firmware"
|
||||||
|
rm -rf "/usr/lib/modules"
|
||||||
|
rm -rf /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
|
||||||
|
rm -rf "/usr/share/${i}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
usage () {
|
usage () {
|
||||||
echo "Update installer, launch latest environment or create latest image files:"
|
echo "Update installer, launch latest environment or create latest image files:"
|
||||||
echo "-------------------------------------------------------------------------"
|
echo "-------------------------------------------------------------------------"
|
||||||
|
@ -32,11 +58,11 @@ usage () {
|
||||||
echo ""
|
echo ""
|
||||||
echo "On fast internet connection (100Mbit) (approx. 5 minutes):"
|
echo "On fast internet connection (100Mbit) (approx. 5 minutes):"
|
||||||
echo " -latest Launch latest archboot environment (using kexec)."
|
echo " -latest Launch latest archboot environment (using kexec)."
|
||||||
echo " This operation needs at least 2.3 GB RAM."
|
echo " This operation needs at least 1.8 GB RAM."
|
||||||
echo ""
|
echo ""
|
||||||
echo " -latest-install Launch latest archboot environment with downloaded"
|
echo " -latest-install Launch latest archboot environment with downloaded"
|
||||||
echo " package cache (using kexec)."
|
echo " package cache (using kexec)."
|
||||||
echo " This operation needs at least 2.7 GB RAM."
|
echo " This operation needs at least 2.5 GB RAM."
|
||||||
echo ""
|
echo ""
|
||||||
echo " -latest-image Generate latest image files in /archboot-release directory"
|
echo " -latest-image Generate latest image files in /archboot-release directory"
|
||||||
echo " This operation needs at least 4.6 GB RAM."
|
echo " This operation needs at least 4.6 GB RAM."
|
||||||
|
@ -106,16 +132,9 @@ if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
touch /.update-installer
|
touch /.update-installer
|
||||||
# remove everything not necessary
|
zram_mount
|
||||||
echo "Step 1/9: Removing not necessary files from / ..."
|
echo "Step 1/9: Removing not necessary files from / ..."
|
||||||
[[ -d "/usr/lib/firmware" ]] && rm -r "/usr/lib/firmware"
|
clean_archboot
|
||||||
[[ -d "/usr/lib/modules" ]] && rm -r "/usr/lib/modules"
|
|
||||||
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}"
|
|
||||||
done
|
|
||||||
echo "Step 2/9: Waiting for gpg pacman keyring import to finish ..."
|
echo "Step 2/9: Waiting for gpg pacman keyring import to finish ..."
|
||||||
while pgrep -x gpg > /dev/null 2>&1; do
|
while pgrep -x gpg > /dev/null 2>&1; do
|
||||||
sleep 1
|
sleep 1
|
||||||
|
@ -144,7 +163,7 @@ if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
||||||
fi
|
fi
|
||||||
echo "Step 4/9: Moving kernel ${VMLINUZ} to ${_W_DIR} ..."
|
echo "Step 4/9: Moving kernel ${VMLINUZ} to ${_W_DIR} ..."
|
||||||
kver
|
kver
|
||||||
mv "${_W_DIR}"/boot/${VMLINUZ} "${_W_DIR}"/ || exit 1
|
mv "${_W_DIR}"/boot/${VMLINUZ} / || exit 1
|
||||||
echo "Step 5/9: Collect initramfs files in ${_W_DIR} ..."
|
echo "Step 5/9: Collect initramfs files in ${_W_DIR} ..."
|
||||||
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
|
||||||
|
@ -155,6 +174,8 @@ if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
||||||
#mv "${_W_DIR}/tmp" /initrd || exit 1
|
#mv "${_W_DIR}/tmp" /initrd || exit 1
|
||||||
echo "Step 6/9: Cleanup ${_W_DIR} ..."
|
echo "Step 6/9: 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
|
||||||
|
sleep 10
|
||||||
echo "Step 7/9: Create initramfs initrd.img ..."
|
echo "Step 7/9: Create initramfs initrd.img ..."
|
||||||
echo " This will need some time ..."
|
echo " This will need some time ..."
|
||||||
# move cache back to initramfs directory in online mode
|
# move cache back to initramfs directory in online mode
|
||||||
|
@ -166,7 +187,7 @@ if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
||||||
cd "${_W_DIR}"/tmp || exit 1
|
cd "${_W_DIR}"/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 -T0 -10> "${_W_DIR}"/initrd.img
|
bsdtar --null -cf - --format=newc @- | zstd -T0 -10> /initrd.img
|
||||||
for i in $(find . -mindepth 1 -type f | sort); do
|
for i in $(find . -mindepth 1 -type f | sort); do
|
||||||
rm "${i}" >/dev/null 2>&1
|
rm "${i}" >/dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
@ -174,23 +195,31 @@ if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
echo "Step 8/9: Cleanup ${_W_DIR}/tmp ..."
|
echo "Step 8/9: Cleanup ${_W_DIR}/tmp ..."
|
||||||
rm -r "${_W_DIR}"/tmp
|
cd /
|
||||||
|
umount ${_W_DIR}
|
||||||
|
echo 1 > /sys/block/zram0/reset
|
||||||
|
sleep 5
|
||||||
echo "Step 9/9: Loading files through kexec into kernel now ..."
|
echo "Step 9/9: Loading files through kexec into kernel now ..."
|
||||||
# load kernel and initrds into running kernel in background mode!
|
# load kernel and initrds into running kernel in background mode!
|
||||||
kexec -f "${_W_DIR}"/${VMLINUZ} --initrd="${_W_DIR}"/initrd.img --reuse-cmdline&
|
kexec -f /"${VMLINUZ}" --initrd="/initrd.img" --reuse-cmdline&
|
||||||
sleep 1
|
# wait 1 seconds for getting a complete initramfs
|
||||||
# remove kernel and initrd to save RAM for kexec in background
|
# remove kernel and initrd to save RAM for kexec in background
|
||||||
rm "${_W_DIR}"/{initrd.img,${VMLINUZ}}
|
sleep 2
|
||||||
|
rm /{initrd.img,${VMLINUZ}}
|
||||||
while pgreg -x kexec >/dev/null 2>&1; do
|
while pgreg -x kexec >/dev/null 2>&1; do
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
echo "Finished: Rebooting in a few seconds ..."
|
echo "Finished: Rebooting in a few seconds ..."
|
||||||
|
# don't show active prompt wait for kexec to be launched
|
||||||
sleep 30
|
sleep 30
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate new images
|
# Generate new images
|
||||||
if [[ "${_G_RELEASE}" == "1" ]]; then
|
if [[ "${_G_RELEASE}" == "1" ]]; then
|
||||||
echo "Step 1/1: Generating new iso files now in ${_W_DIR} ..."
|
zram_mount
|
||||||
|
echo "Step 1/2: Removing not necessary files from / ..."
|
||||||
|
clean_archboot
|
||||||
|
echo "Step 2/2: Generating new iso files now in ${_W_DIR} ..."
|
||||||
echo " This will need some time ..."
|
echo " This will need some time ..."
|
||||||
"archboot-${_RUNNING_ARCH}-release.sh" "${_W_DIR}" >/dev/tty7 2>&1 || exit 1
|
"archboot-${_RUNNING_ARCH}-release.sh" "${_W_DIR}" >/dev/tty7 2>&1 || exit 1
|
||||||
echo "Finished: New isofiles are located in ${_W_DIR}"
|
echo "Finished: New isofiles are located in ${_W_DIR}"
|
||||||
|
|
Loading…
Reference in a new issue