diff --git a/.SRCINFO b/.SRCINFO deleted file mode 100644 index 2ba211e..0000000 --- a/.SRCINFO +++ /dev/null @@ -1,12 +0,0 @@ -pkgbase = ramroot - pkgdesc = Load root filesystem completely to RAM during boot - pkgver = 1.1.8 - pkgrel = 1 - url = https://github.com/arcmags/ramroot - arch = any - license = GPL - depends = sudo - source = https://github.com/arcmags/ramroot/1.1.8.tar.gz - md5sums = 9412771e7ba0736c37d87f05c28abe24 - -pkgname = ramroot diff --git a/README.rst b/README.rst index 7388964..1ee9857 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ ramroot ======= Run Linux entirely from RAM! This is customizable mkinitcpio_ hook -that completely loads the *root* file system to a zram partition +that completely loads the root file system to a zram partition during the initramfs_ boot stage. diff --git a/ramroot b/ramroot index 6580073..4d4105a 100755 --- a/ramroot +++ b/ramroot @@ -45,7 +45,7 @@ dir_script="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" file_config='/etc/ramroot.conf' ram_machine=8000 ps_default=no -ps_timeout=8 +ps_timeout=5 ram_min=750 ram_pref=4000 zram_min=250 @@ -188,6 +188,7 @@ ramroot_config_gen() { ps_input zram #global file_config flag_yes opt_output ps_default ps_timeout \ #ram_machine ram_min ram_pref zram_max zram_min + # RETURN: trying to save to directory: if [ -d "$opt_output" ]; then msg_error "$opt_output is a directory" @@ -200,13 +201,13 @@ ramroot_config_gen() { # RETURN: if [ "$ps_input" != 'y' ] && [ "$ps_input" != 'yes' ]; then return 0 - fi - fi + fi; fi + # only possible to generate custom config if root is mounted: if (mountpoint -q /); then zram=$(($(df -m / | \ awk 'FNR==2 {print int($3)}')+ram_min+zram_min)) - # get /boot, /efi, /esp, /home from /etc/fstab: + # source /etc/fstab: if [ -f /etc/fstab ]; then mapfile -t mounts_fstab < <(sed -En \ 's@^\s*((UUID|PARTUUID)=[^\s]+)\s+(/[^ \s]+).*$@\3:\1@p;' \ @@ -214,18 +215,16 @@ ramroot_config_gen() { for mount in ${mounts_fstab[@]}; do mount_id="${mount#*:}" mount_path="${mount%:*}" - # attempt to check if mount is small enough: - if [[ "${mount_path,,}" =~ /(boot|efi|esp|home)$ ]] || \ - (mountpoint -q "$mount_path") && \ - [ $((ram_machine - zram - $(df -m "$mount_path" | \ - awk 'FNR==2 {print int($3)}'))) -gt 0 ]; then - zram=$((zram+$(df -m "$mount_path" | \ - awk 'FNR==2 {print int($3)}'))) - mounts_zram+=("$mount_id:$mount_path") - fi - done - fi - fi + # get /boot, /efi, /esp, /home from /etc/fstab: + if [[ "${mount_path,,}" =~ /(boot|efi|esp|home)$ ]] && \ + (mountpoint -q "$mount_path"); then + # attempt to determine if mount is small enough: + part=$(df -m "$mount_path" | \ + awk 'FNR==2 {print int($3)}') + if [ $((ram_machine-zram-part)) -gt 0 ]; then + zram=$((zram+part)) + mounts_zram+=("$mount_id:$mount_path") + fi; fi; done; fi; fi # build config: config=$'#!usr/bin/ash\n\n# mounts loaded to zram:\nmounts_zram=\'' @@ -252,7 +251,7 @@ ramroot_config_gen() { config+=$'\n\n# maximum Mb free ram:\nzram_max=' config+="$zram_max" - # save config: + # write config: printf '%s\n' "$config" > "$opt_output" } @@ -317,10 +316,8 @@ if [ $EUID -ne 0 ]; then cut -c9)" != 'w' ]; then msg_error 'you must be root to perform this operation' exit 1 - fi - fi - fi -fi +fi; fi; fi; fi + # FAIL: both disable and enable: if [ "$flag_disable" = 'true' ] && [ "$flag_enable" = 'true' ]; then msg_error 'cannot both disable and enable' diff --git a/ramroot.install b/ramroot.install deleted file mode 100644 index e327f9c..0000000 --- a/ramroot.install +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -post_install() { - /usr/bin/ramroot -CE -} - -pre_upgrade() { - if [[ "$2" =~ ^1 ]]; then - /user/bin/ramroot remove - fi -} - -post_upgrade() { - if [[ "$2" =~ ^1 ]]; then - /user/bin/ramroot -CE - fi -} - -pre_remove() { - /usr/bin/ramroot -D -} diff --git a/usr/lib/initcpio/hooks/ramroot b/usr/lib/initcpio/hooks/ramroot index 291f1c0..aa66d22 100644 --- a/usr/lib/initcpio/hooks/ramroot +++ b/usr/lib/initcpio/hooks/ramroot @@ -42,6 +42,7 @@ run_hook() { [ -z "$mount_id" ] || [ -z "$mount_path" ]; then printf '\e[1;31m==> FAILED: \e[1;37m%s %s\e[0;37m\n' \ 'ramroot mount not found:' "$mount" + sleep 2 return 1 fi done @@ -54,7 +55,7 @@ run_hook() { fi if (! echo "$ps_timeout" | grep -Ei \ '^[1-9]+[0-9]*$' &>/dev/null); then - ps_timeout=8 + ps_timeout=5 fi # set sizes: @@ -91,6 +92,7 @@ run_hook() { if [ $? -ne 0 ]; then printf '\e[1;31m==> FAILED: \e[1;37m%s %s\e[0;37m\n' \ 'ramroot unable to mount:' "${mount%:*}" + sleep 2 return 1 fi zram=$((zram+$(df /local_root/ | \ @@ -102,6 +104,7 @@ run_hook() { if [ $((ram-ram_min-zram-zram_min)) -le 0 ]; then printf '\e[1;33m==> SKIPPED: \e[1;37m%s\e[0;37m\n' \ 'ramroot: not enough ram' + sleep 2 return 0 # calculate zram size: elif [ $((ram-ram_pref-zram-zram_min)) -gt 0 ]; then diff --git a/usr/lib/ramroot/ramroot.conf b/usr/lib/ramroot/ramroot.conf index 4d6c4bc..a02394c 100644 --- a/usr/lib/ramroot/ramroot.conf +++ b/usr/lib/ramroot/ramroot.conf @@ -1,8 +1,7 @@ #!usr/bin/ash # mounts loaded to zram: -mounts_zram='UUID=1911-B161:/EFI - UUID=d00c61d4-d89d-4a54-ba6c-76a0b910a07f:/home' +mounts_zram='' # mounts ignored: mounts_null='' @@ -11,7 +10,7 @@ mounts_null='' ps_default=no # prompt timout: -ps_timeout=8 +ps_timeout=5 # minimum Mb free ram: ram_min=750 @@ -22,5 +21,5 @@ zram_min=250 # preferred Mb free ram: ram_pref=4000 -# maximum Mb free zram: +# maximum Mb free ram: zram_max=1000