Skip to content

Commit 6cf6877

Browse files
committed
now works with encryption, plus a bunch of syntax improvements
1 parent 821ce17 commit 6cf6877

File tree

5 files changed

+212
-213
lines changed

5 files changed

+212
-213
lines changed

README.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ <h1>Issues / Future Implementations</h1>
667667
automatically if installed)</li>
668668
<li>option to create a unique hostname for each RAM boot instance</li>
669669
<li>improve security features<ul>
670-
<li>test compatibility with full disk encryption</li>
671670
<li>option to require removal of boot media before starting userspace</li>
672671
<li>option to fail boot unless loaded to RAM (requires <em>chroot</em> to
673672
make changes; advanced users)</li>
@@ -688,7 +687,7 @@ <h1>Credits</h1>
688687
<tbody valign="top">
689688
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Chris Magyar</td>
690689
</tr>
691-
<tr class="field"><th class="field-name">Version:</th><td class="field-body">1.1.7</td>
690+
<tr class="field"><th class="field-name">Version:</th><td class="field-body">1.1.8</td>
692691
</tr>
693692
<tr class="field"><th class="field-name">License:</th><td class="field-body">GPL 3.0</td>
694693
</tr>

README.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ Issues / Future Implementations
160160

161161
* improve security features
162162

163-
+ test compatibility with full disk encryption
164-
165163
+ option to require removal of boot media before starting userspace
166164

167165
+ option to fail boot unless loaded to RAM (requires *chroot* to
@@ -183,7 +181,7 @@ by several inquisitive `forum posts`_.
183181
Chris Magyar
184182

185183
:Version:
186-
1.1.7
184+
1.1.8
187185

188186
:License:
189187
GPL 3.0

lib/hooks/ramroot

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,90 @@
44

55
run_hook() {
66
# root (and boot) UUID
7-
bootUUID=''
8-
rootUUID=''
7+
UUID_BOOT=''
8+
UUID_ROOT=''
99
# ramroot prompt:
10-
promptDefault='yes'
11-
promptTimeout=15
10+
LOAD_DEFAULT='yes'
11+
LOAD_TIMEOUT=15
1212
# options:
13-
fstabMount='false'
14-
issueRAM='false'
13+
FLAG_FSTAB='false'
14+
FLAG_ISSUE='false'
1515

1616
# wait for output from other init processes:
1717
sleep 4
1818

1919
# detect available RAM:
20-
ramM=`free --mega | awk '/Mem/ {print int($2)}'`
21-
ramG=$(( $ramM / 1000 ))
20+
RAM_M=`free --mega | awk '/Mem/ {print int($2)}'`
21+
RAM_G=$(( $RAM_M / 1000 ))
2222

2323
# mount root partition to /local_root:
24-
poll_device "/dev/disk/by-uuid/${rootUUID}" 20
25-
mount -U "${rootUUID}" /local_root
24+
poll_device "/dev/disk/by-uuid/$UUID_ROOT" 20
25+
mount -U "$UUID_ROOT" /local_root
2626
# get size of /local_root:
27-
rootM=`df -BM /local_root/ | awk 'FNR==2 {print int($3)}'`
27+
ROOT_M=`df -BM /local_root/ | awk 'FNR==2 {print int($3)}'`
2828

2929
# mount boot partition (if exists) to /local_boot:
30-
if [ -n "$bootUUID" ]; then
31-
poll_device "/dev/disk/by-uuid/${bootUUID}" 20
32-
mount -U "${bootUUID}" /local_boot
30+
if [ -n "$UUID_BOOT" ]; then
31+
poll_device "/dev/disk/by-uuid/$UUID_BOOT" 20
32+
mount -U "$UUID_BOOT" /local_boot
3333
# add size of /local_boot:
34-
rootM=$(( $rootM + `df -BM /local_boot/ | \
34+
ROOT_M=$(( $ROOT_M + `df -BM /local_boot/ | \
3535
awk 'FNR==2 {print int($3)}'` ))
3636
fi
3737

3838
# check and print available memory:
39-
echo ":: Total RAM available : ${ramM}M"
40-
echo ":: Root filesystem size : ${rootM}M"
41-
diffM=$(( $ramM - $rootM ))
42-
if [ $diffM -lt 500 ]; then
39+
echo ":: Total RAM available : ${RAM_M}M"
40+
echo ":: Root filesystem size : ${ROOT_M}M"
41+
RAM_EXTRA_M=$(( $RAM_M - $ROOT_M ))
42+
if [ $RAM_EXTRA_M -lt 500 ]; then
4343
echo ":! Not enough RAM available."
44-
inputYN='n'
44+
INPUT='n'
4545

4646
# prompt [Y/n] to load filesystem to RAM:
47-
elif [ "$promptDefault" = 'yes' ]; then
47+
elif [ "$LOAD_DEFAULT" = 'yes' ]; then
4848
echo -n ">: Load root filesystem to RAM? [Y/n] "
49-
inputYN='y'
50-
read -s -r -t $promptTimeout -n 1 inputYN
51-
if [ "${inputYN}" = 'n' ] || [ "${inputYN}" = 'N' ] || \
52-
[ "${inputYN}" = 'q' ] || [ "${inputYN}" = 'Q' ]; then
53-
inputYN='n'
49+
INPUT='y'
50+
read -s -r -t $LOAD_TIMEOUT -n 1 INPUT
51+
if [ "$INPUT" = 'n' ] || [ "$INPUT" = 'N' ] ||
52+
[ "$INPUT" = 'q' ] || [ "INPUT" = 'Q' ]; then
53+
INPUT='n'
5454
else
55-
inputYN='y'
55+
INPUT='y'
5656
fi
5757
# prompt [y/N] to load filesystem to RAM:
5858
else
5959
echo -n ">: Load root filesystem to RAM? [y/N] "
60-
inputYN='n'
61-
read -s -r -t $promptTimeout -n 1 inputYN
62-
if [ "${inputYN}" = 'y' ] || [ "${inputYN}" = 'Y' ]; then
63-
inputYN='y'
60+
INPUT='n'
61+
read -s -r -t $LOAD_TIMEOUT -n 1 INPUT
62+
if [ "$INPUT" = 'y' ] || [ "INPUT" = 'Y' ] ; then
63+
INPUT='y'
6464
else
65-
inputYN='n'
65+
INPUT='n'
6666
fi
6767
fi
6868

6969
# copy root filesystem to RAM:
70-
if [ "${inputYN}" = 'y' ]; then
70+
if [ "$INPUT" = 'y' ]; then
7171
echo "yes"
7272
echo ":: Copying root filesystem to RAM..."
73+
7374
# enable zRAM devices:
7475
if [ ! -b "/dev/zram0" ]; then
7576
modprobe zram num_devices=$(nproc)
7677
fi
7778

7879
# make zRAM partition using half of available free RAM (max +6G)
79-
addM=$(( $diffM / 2 ))
80-
if [ $addM -gt 6000 ]; then
81-
addM=6000
82-
else
83-
addM=$(( $diffM / 2 ))
80+
ROOT_ADD_M=$(( $RAM_EXTRA_M / 2 ))
81+
if [ $ROOT_ADD_M -gt 6000 ]; then
82+
ROOT_ADD_M=6000
8483
fi
85-
zramM=$(( $rootM + $addM ))
86-
zdevice=$(zramctl -f -s "${zramM}M" -a lzo -t $(nproc))
87-
mkfs.ext4 -q "$zdevice"
84+
ZRAM_M=$(( $ROOT_M + $ROOT_ADD_M ))
85+
ZRAM_DEVICE=$(zramctl -f -s "${ZRAM_M}M" -a lzo -t $(nproc))
86+
mkfs.ext4 -q "$ZRAM_DEVICE"
8887

8988
# mount zRAM partition to /zram_root:
90-
mount "$zdevice" /zram_root
91-
export zdevice
89+
mount "$ZRAM_DEVICE" /zram_root
90+
export ZRAM_DEVICE
9291
# copy files from local root to zRAM root:
9392
cp -a /local_root/* /zram_root/
9493

@@ -97,30 +96,29 @@ run_hook() {
9796
mv /zram_root/etc/fstab /zram_root/etc/fstab~
9897
fi
9998
# use other mount points from /etc/fstab normally:
100-
if [ "$fstabMount" = 'true' ] && [ -f /zram_root/etc/fstab~ ]; then
99+
if [ "$FLAG_FSTAB" = 'true' ] && [ -f /zram_root/etc/fstab~ ]; then
101100
sed 's@\(.* /boot .*\)@#\1@g; s@\(.* / .*\)@#\1@g;' \
102101
/zram_root/etc/fstab~ > /zram_root/etc/fstab
103102
fi
104103
# use custom /etc/issue file:
105-
if [ "$issueRAM" = 'true' ] &&
104+
if [ "$FLAG_ISSUE" = 'true' ] &&
106105
[ -f /zram_root/usr/lib/ramroot/etc/issue ]; then
107106
if [ -f /zram_root/etc/issue ]; then
108107
mv /zram_root/etc/issue /zram_root/etc/issue~
109108
fi
110109
cp /zram_root/usr/lib/ramroot/etc/issue /zram_root/etc/issue
111-
chmod +x /zram_root/etc/issue
112110
fi
113111

114112
# copy files from local boot partition (if exists) to zRAM boot:
115-
if [ -n "$bootUUID" ]; then
113+
if [ -n "$UUID_BOOT" ]; then
116114
mkdir -p /zram_root/boot
117115
cp -a /local_boot/* /zram_root/boot/
118116
fi
119117
# unmount zRAM root:
120118
umount /zram_root
121119
# set new mount_handler to use zRAM device:
122120
oroot_mount() {
123-
mount "$zdevice" "$1"
121+
mount "$ZRAM_DEVICE" "$1"
124122
}
125123
# don't perform filesystem check on new zRAM partition:
126124
fsck_root() {
@@ -136,7 +134,7 @@ run_hook() {
136134

137135
# unmount /local_root and /local_boot:
138136
umount /local_root
139-
if [ -n "$bootUUID" ]; then
137+
if [ -n "$UUID_BOOT" ]; then
140138
umount /local_boot
141139
fi
142140
}

lib/man/ramroot.8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH RAMROOT 8 "December 2017" "ramroot 1.1.7" "Ramroot Manual"
1+
.TH RAMROOT 8 "January 2018" "ramroot 1.1.8" "Ramroot Manual"
22
.SH NAME
33
ramroot \- load root filesystem entirely to RAM during boot
44
.SH SYNOPSIS

0 commit comments

Comments
 (0)