Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
arcmags committed Oct 25, 2019
1 parent 464b1a3 commit bc1e487
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 60 deletions.
12 changes: 0 additions & 12 deletions .SRCINFO

This file was deleted.

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
39 changes: 18 additions & 21 deletions ramroot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -200,32 +201,30 @@ 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;' \
/etc/fstab | sort)
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=\''
Expand All @@ -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"
}

Expand Down Expand Up @@ -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'
Expand Down
21 changes: 0 additions & 21 deletions ramroot.install

This file was deleted.

5 changes: 4 additions & 1 deletion usr/lib/initcpio/hooks/ramroot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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/ | \
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions usr/lib/ramroot/ramroot.conf
Original file line number Diff line number Diff line change
@@ -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=''
Expand All @@ -11,7 +10,7 @@ mounts_null=''
ps_default=no

# prompt timout:
ps_timeout=8
ps_timeout=5

# minimum Mb free ram:
ram_min=750
Expand All @@ -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

0 comments on commit bc1e487

Please sign in to comment.