Skip to content

Commit bc1e487

Browse files
committed
2.0.0
1 parent 464b1a3 commit bc1e487

File tree

6 files changed

+26
-60
lines changed

6 files changed

+26
-60
lines changed

.SRCINFO

-12
This file was deleted.

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ramroot
33
=======
44

55
Run Linux entirely from RAM! This is customizable mkinitcpio_ hook
6-
that completely loads the *root* file system to a zram partition
6+
that completely loads the root file system to a zram partition
77
during the initramfs_ boot stage.
88

99

ramroot

+18-21
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dir_script="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4545
file_config='/etc/ramroot.conf'
4646
ram_machine=8000
4747
ps_default=no
48-
ps_timeout=8
48+
ps_timeout=5
4949
ram_min=750
5050
ram_pref=4000
5151
zram_min=250
@@ -188,6 +188,7 @@ ramroot_config_gen() {
188188
ps_input zram
189189
#global file_config flag_yes opt_output ps_default ps_timeout \
190190
#ram_machine ram_min ram_pref zram_max zram_min
191+
191192
# RETURN: trying to save to directory:
192193
if [ -d "$opt_output" ]; then
193194
msg_error "$opt_output is a directory"
@@ -200,32 +201,30 @@ ramroot_config_gen() {
200201
# RETURN:
201202
if [ "$ps_input" != 'y' ] && [ "$ps_input" != 'yes' ]; then
202203
return 0
203-
fi
204-
fi
204+
fi; fi
205205

206+
# only possible to generate custom config if root is mounted:
206207
if (mountpoint -q /); then
207208
zram=$(($(df -m / | \
208209
awk 'FNR==2 {print int($3)}')+ram_min+zram_min))
209-
# get /boot, /efi, /esp, /home from /etc/fstab:
210+
# source /etc/fstab:
210211
if [ -f /etc/fstab ]; then
211212
mapfile -t mounts_fstab < <(sed -En \
212213
's@^\s*((UUID|PARTUUID)=[^\s]+)\s+(/[^ \s]+).*$@\3:\1@p;' \
213214
/etc/fstab | sort)
214215
for mount in ${mounts_fstab[@]}; do
215216
mount_id="${mount#*:}"
216217
mount_path="${mount%:*}"
217-
# attempt to check if mount is small enough:
218-
if [[ "${mount_path,,}" =~ /(boot|efi|esp|home)$ ]] || \
219-
(mountpoint -q "$mount_path") && \
220-
[ $((ram_machine - zram - $(df -m "$mount_path" | \
221-
awk 'FNR==2 {print int($3)}'))) -gt 0 ]; then
222-
zram=$((zram+$(df -m "$mount_path" | \
223-
awk 'FNR==2 {print int($3)}')))
224-
mounts_zram+=("$mount_id:$mount_path")
225-
fi
226-
done
227-
fi
228-
fi
218+
# get /boot, /efi, /esp, /home from /etc/fstab:
219+
if [[ "${mount_path,,}" =~ /(boot|efi|esp|home)$ ]] && \
220+
(mountpoint -q "$mount_path"); then
221+
# attempt to determine if mount is small enough:
222+
part=$(df -m "$mount_path" | \
223+
awk 'FNR==2 {print int($3)}')
224+
if [ $((ram_machine-zram-part)) -gt 0 ]; then
225+
zram=$((zram+part))
226+
mounts_zram+=("$mount_id:$mount_path")
227+
fi; fi; done; fi; fi
229228

230229
# build config:
231230
config=$'#!usr/bin/ash\n\n# mounts loaded to zram:\nmounts_zram=\''
@@ -252,7 +251,7 @@ ramroot_config_gen() {
252251
config+=$'\n\n# maximum Mb free ram:\nzram_max='
253252
config+="$zram_max"
254253

255-
# save config:
254+
# write config:
256255
printf '%s\n' "$config" > "$opt_output"
257256
}
258257

@@ -317,10 +316,8 @@ if [ $EUID -ne 0 ]; then
317316
cut -c9)" != 'w' ]; then
318317
msg_error 'you must be root to perform this operation'
319318
exit 1
320-
fi
321-
fi
322-
fi
323-
fi
319+
fi; fi; fi; fi
320+
324321
# FAIL: both disable and enable:
325322
if [ "$flag_disable" = 'true' ] && [ "$flag_enable" = 'true' ]; then
326323
msg_error 'cannot both disable and enable'

ramroot.install

-21
This file was deleted.

usr/lib/initcpio/hooks/ramroot

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ run_hook() {
4242
[ -z "$mount_id" ] || [ -z "$mount_path" ]; then
4343
printf '\e[1;31m==> FAILED: \e[1;37m%s %s\e[0;37m\n' \
4444
'ramroot mount not found:' "$mount"
45+
sleep 2
4546
return 1
4647
fi
4748
done
@@ -54,7 +55,7 @@ run_hook() {
5455
fi
5556
if (! echo "$ps_timeout" | grep -Ei \
5657
'^[1-9]+[0-9]*$' &>/dev/null); then
57-
ps_timeout=8
58+
ps_timeout=5
5859
fi
5960

6061
# set sizes:
@@ -91,6 +92,7 @@ run_hook() {
9192
if [ $? -ne 0 ]; then
9293
printf '\e[1;31m==> FAILED: \e[1;37m%s %s\e[0;37m\n' \
9394
'ramroot unable to mount:' "${mount%:*}"
95+
sleep 2
9496
return 1
9597
fi
9698
zram=$((zram+$(df /local_root/ | \
@@ -102,6 +104,7 @@ run_hook() {
102104
if [ $((ram-ram_min-zram-zram_min)) -le 0 ]; then
103105
printf '\e[1;33m==> SKIPPED: \e[1;37m%s\e[0;37m\n' \
104106
'ramroot: not enough ram'
107+
sleep 2
105108
return 0
106109
# calculate zram size:
107110
elif [ $((ram-ram_pref-zram-zram_min)) -gt 0 ]; then

usr/lib/ramroot/ramroot.conf

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!usr/bin/ash
22

33
# mounts loaded to zram:
4-
mounts_zram='UUID=1911-B161:/EFI
5-
UUID=d00c61d4-d89d-4a54-ba6c-76a0b910a07f:/home'
4+
mounts_zram=''
65

76
# mounts ignored:
87
mounts_null=''
@@ -11,7 +10,7 @@ mounts_null=''
1110
ps_default=no
1211

1312
# prompt timout:
14-
ps_timeout=8
13+
ps_timeout=5
1514

1615
# minimum Mb free ram:
1716
ram_min=750
@@ -22,5 +21,5 @@ zram_min=250
2221
# preferred Mb free ram:
2322
ram_pref=4000
2423

25-
# maximum Mb free zram:
24+
# maximum Mb free ram:
2625
zram_max=1000

0 commit comments

Comments
 (0)