summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-04-23 20:40:06 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-04-23 20:40:06 -0400
commit6d7f30baa5c8c4d5ca9b5ec8f07f0ae0c510b710 (patch)
treee7ed8ecbb5dd78d8c15b2b8d45aff2f9b779e1a7
parent7739d1863cb6ea5de819e1ae1c1ee10e8109d32b (diff)
downloadminitramfs-6d7f30baa5c8c4d5ca9b5ec8f07f0ae0c510b710.tar.xz
minitramfs-6d7f30baa5c8c4d5ca9b5ec8f07f0ae0c510b710.zip
fixes, updates, LICENSE file
-rw-r--r--LICENSE19
-rw-r--r--README21
-rwxr-xr-xcomp_bench21
3 files changed, 50 insertions, 11 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9485952
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+The file gen_init_cpio.c is from the Linux kernel source file
+usr/gen_init_cpio.c. It was released under the GNU General Public License,
+version 2, and is redistributed under those terms.
+
+Other files are subject to the following copyright:
+
+Copyright 2020 Alex Xu.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License, version 3, as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+A copy of the GNU General Public License, version 3 can be found in
+gpl-3.0.txt. It can also be obtained from <http://www.gnu.org/licenses/>.
diff --git a/README b/README
index 4630f38..323f402 100644
--- a/README
+++ b/README
@@ -6,11 +6,13 @@ You need something else? Patch it, it's only 117 lines.
Features:
+- uses existing system tools, no compilation necessary
- password LUKS unlock
- SSH remote unlock
-- firmware loading
+- firmware loading (trivial, done by kernel)
- extremely fast initramfs creation: compression off: ~70ms cold cache, ~30ms
warm; lz4 --best: 1.6s
+- no temporary files during creation
- extremely fast initramfs runtime: ~zero overhead compared to direct kernel
loading
- minimal code: 117 SLOC total (init + make + Makefile + unlock)
@@ -18,6 +20,7 @@ Features:
Drawbacks:
+- uses existing system tools, no compilation possible
- no modprobe support. custom kernel is required to use myinitramfs. if you
want configurability, probably better to use mkinitcpio or dracut.
- pure POSIX shell + POSIX Makefile
@@ -26,21 +29,23 @@ Usage:
0. Read (skim) https://wiki.gentoo.org/wiki/Custom_Initramfs.
-1. Install busybox, dropbear, e2fsprogs (if you use ext4).
+1. Install busybox, dropbear, e2fsprogs if you use ext4, and C toolchain for
+ building gen_init_cpio.
2. Adjust ./init as required:
a) Adjust networking as required (e.g. maybe static IP instead of DHCP, or
- you don't use eth0)
- b) Adjust UUID (probably yours is not the same as mine)
- c) Adjust fsck as needed (if you are not using ext4)
- d) Put whatever you want:
+ you don't use eth0, but remember that myinitramfs has no udev, so no
+ predictable interface names)
+ b) Adjust UUID (most likely yours is not the same as mine)
+ c) Change or remove fsck for non-ext4 roots
+ d) Put whatever you want: usr mount, NFS root, whatever.
3. Adjust ./make as required:
a) Put your needed commands in gen_cpio_list.
b) Select your desired compressor at the end. Try make comp_bench for a comparison.
summary: lz4 is usually best, xz if storage is important above all (saves
a few MB but adds ~0.5s to boot), gzip is mediocre on both size and
- speed, lzo is almost always worse than lz4, never use bzip2 or lzma.
+ speed, lzo is usually worse than gzip, never use bzip2 or lzma.
4. Customize cpio_list.txt with your required files. Remember that commands
must go in ./make (for library detection), and device files except
@@ -54,3 +59,5 @@ Usage:
7. sudo make install
8. Configure your boot loader/boot manager to use initramfs.img.
+
+9. Use as usual. For remote unlock, SSH to port 2222 and "exec unlock".
diff --git a/comp_bench b/comp_bench
index 01387da..d7f929d 100755
--- a/comp_bench
+++ b/comp_bench
@@ -1,18 +1,31 @@
#!/bin/sh
+[ "$1" = -v ] && verbose=1
+
set -e
+do_time() {
+ exec 3>&1
+ (time "$@") 2>&1 >&3 | grep . >&2
+}
+
do_bench() {
tmpfile=$(mktemp)
- trap 'rm -f "$tmpfile"' EXIT
- compressor=cat outfile=/proc/self/fd/1 ./make | "$@" -c < initramfs.img > "$tmpfile"
- printf '%s: %s bytes\n' "$1" "$(wc -c < "$tmpfile")"
- time $1 -dc < "$tmpfile" >/dev/null
+ trap 'rm -f "$tmpfile"' HUP INT QUIT TERM EXIT
+ [ -z "$verbose" ] || printf '%s compression:\n' "$1"
+ ${verbose+do_time} "$@" -c <initramfs.img >"$tmpfile"
+ printf '%s size: %s bytes\n' "$1" "$(wc -c < "$tmpfile")"
+ printf '%s decompression:\n' "$1"
+ do_time "$1" -dc <"$tmpfile" >/dev/null
rm "$tmpfile"
trap '' EXIT
echo
}
+if [ -e initramfs.img ] && [ "$(file -b initramfs.img)" != "ASCII cpio archive (SVR4 with no CRC)" ]; then
+ echo "warning: overwriting initramfs.img" >&2
+ compressor=cat ./make > initramfs.img
+fi
do_bench gzip -9
do_bench bzip2 -9
do_bench lzma -9e --check=crc32