mount /usr to zram device to save RAM on running update-installer.sh

This commit is contained in:
Tobias Powalowski 2022-05-17 08:12:51 +02:00
parent df5b88d3da
commit f9390379d8
3 changed files with 44 additions and 16 deletions

View file

@ -17,6 +17,8 @@ _HIDE_MENU="xfce4-mail-reader xfce4-about"
_VNC_PW="archboot" _VNC_PW="archboot"
### zram setup ### zram setup
_ZRAM_ALGORITHM="zstd" _ZRAM_ALGORITHM="zstd"
# size for /usr.zram
_ZRAM_USR="1900M"
# size for --latest and --latest-install option # size for --latest and --latest-install option
_ZRAM_SIZE="3G" _ZRAM_SIZE="3G"
# size used for --latest-image option # size used for --latest-image option

View file

@ -29,7 +29,8 @@ if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
_update_installer_check _update_installer_check
touch /.update-installer touch /.update-installer
_umount_w_dir _umount_w_dir
_zram_mount "${_ZRAM_SIZE}" _zram_mount "${_ZRAM_USR}"
_zram_w_dir "${_ZRAM_SIZE}"
echo -e "\033[1mStep 1/9:\033[0m Waiting for gpg pacman keyring import to finish ..." echo -e "\033[1mStep 1/9:\033[0m Waiting for gpg pacman keyring import to finish ..."
_gpg_check _gpg_check
echo -e "\033[1mStep 2/9:\033[0m Removing not necessary files from / ..." echo -e "\033[1mStep 2/9:\033[0m Removing not necessary files from / ..."
@ -70,7 +71,8 @@ fi
# Generate new images # Generate new images
if [[ "${_G_RELEASE}" == "1" ]]; then if [[ "${_G_RELEASE}" == "1" ]]; then
_ZRAM_IMAGE_SIZE=${_ZRAM_IMAGE_SIZE:-"5G"} _ZRAM_IMAGE_SIZE=${_ZRAM_IMAGE_SIZE:-"5G"}
_zram_mount "${_ZRAM_IMAGE_SIZE}" _zram_mount "${_ZRAM_USR}"
_zram_w_dir "${_ZRAM_IMAGE_SIZE}"
echo -e "\033[1mStep 1/2:\033[0m Removing not necessary files from / ..." echo -e "\033[1mStep 1/2:\033[0m Removing not necessary files from / ..."
_clean_archboot _clean_archboot
echo -e "\033[1mStep 2/2:\033[0m Generating new iso files in ${_W_DIR} now ..." echo -e "\033[1mStep 2/2:\033[0m Generating new iso files in ${_W_DIR} now ..."
@ -82,6 +84,7 @@ fi
# Launch xfce # Launch xfce
if [[ "${_L_XFCE}" == "1" ]]; then if [[ "${_L_XFCE}" == "1" ]]; then
if ! [[ -e /usr/bin/startxfce4 ]]; then if ! [[ -e /usr/bin/startxfce4 ]]; then
_zram_mount "${_ZRAM_USR}"
echo -e "\033[1mStep 1/4:\033[0m Waiting for gpg pacman keyring import to finish ..." echo -e "\033[1mStep 1/4:\033[0m Waiting for gpg pacman keyring import to finish ..."
_gpg_check _gpg_check
echo -e "\033[1mStep 2/4:\033[0m Installing XFCE desktop now ..." echo -e "\033[1mStep 2/4:\033[0m Installing XFCE desktop now ..."

View file

@ -32,7 +32,7 @@ usage () {
echo -e " This operation needs at least \033[1m3.9 GB RAM\033[0m." echo -e " This operation needs at least \033[1m3.9 GB RAM\033[0m."
echo "" echo ""
echo -e " \033[1m-launch-xfce\033[0m Launch XFCE desktop with VNC sharing enabled." echo -e " \033[1m-launch-xfce\033[0m Launch XFCE desktop with VNC sharing enabled."
echo -e " This operation needs at least \033[1m3.2 GB RAM\033[0m." echo -e " This operation needs at least \033[1m2.5 GB RAM\033[0m."
echo "" echo ""
echo -e " \033[1m-h\033[0m This message." echo -e " \033[1m-h\033[0m This message."
exit 0 exit 0
@ -90,26 +90,49 @@ _umount_w_dir() {
echo "Unmounting ${_W_DIR} ..." > /dev/tty7 echo "Unmounting ${_W_DIR} ..." > /dev/tty7
# umount all possible mountpoints # umount all possible mountpoints
umount -R "${_W_DIR}" umount -R "${_W_DIR}"
echo 1 > /sys/block/zram0/reset echo 1 > /sys/block/zram1/reset
# wait 5 seconds to get RAM cleared and set free # wait 5 seconds to get RAM cleared and set free
sleep 5 sleep 5
fi fi
} }
# 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!
_zram_mount() { _zram_mount() {
# add defaults if ! mountpoint /usr; then
_ZRAM_ALGORITHM=${_ZRAM_ALGORITHM:-"zstd"} # add defaults
modprobe zram > /dev/tty7 2>&1 _ZRAM_ALGORITHM=${_ZRAM_ALGORITHM:-"zstd"}
echo "${_ZRAM_ALGORITHM}" >/sys/block/zram0/comp_algorithm modprobe -o num_devices=2 zram > /dev/tty7 2>&1
echo "${1}" >/sys/block/zram0/disksize echo "${_ZRAM_ALGORITHM}" >/sys/block/zram0/comp_algorithm
echo "Creating btrfs filesystem with ${_DISKSIZE} on /dev/zram0 ..." > /dev/tty7 echo "${1}" >/sys/block/zram0/disksize
mkfs.btrfs -q --mixed /dev/zram0 > /dev/tty7 2>&1 echo "Creating btrfs filesystem with ${_DISKSIZE} on /dev/zram0 ..." > /dev/tty7
mkfs.btrfs -q --mixed /dev/zram0 > /dev/tty7 2>&1
mkdir /usr.zram
mount -o discard /dev/zram0 "/usr.zram" > /dev/tty7 2>&1
echo "Moving /usr to /usr.zram ..." > /dev/tty7
cp -r /usr/* /usr.zram/
ln -sfn /usr.zram/lib /lib
ln -sfn /usr.zram/lib /lib64
echo /usr.zram/lib > /etc/ld.so.conf
ldconfig
ln -sfn /usr.zram/bin /bin
ln -sfn /usr.zram/bin /sbin
rm -r /usr/*
/usr.new/bin/./mount --bind /usr.zram /usr
systemctl daemon-reload
systemctl restart dbus
fi
}
_zram_w_dir() {
echo "${_ZRAM_ALGORITHM}" >/sys/block/zram1/comp_algorithm
echo "${1}" >/sys/block/zram1/disksize
echo "Creating btrfs filesystem with ${_DISKSIZE} on /dev/zram1 ..." > /dev/tty7
mkfs.btrfs -q --mixed /dev/zram1 > /dev/tty7 2>&1
[[ -d "${_W_DIR}" ]] || mkdir "${_W_DIR}" [[ -d "${_W_DIR}" ]] || mkdir "${_W_DIR}"
# use -o discard for RAM cleaning on delete mount -o discard /dev/zram1 "${_W_DIR}" > /dev/tty7 2>&1
# (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}" > /dev/tty7 2>&1
} }
_clean_archboot() { _clean_archboot() {