├── usr ├── bin │ └── .keep-bin-dir ├── sbin │ └── .keep-sbin-dir ├── etc │ ├── splash │ │ └── .keep-splash-dir │ ├── modprobe.d │ │ └── zfs.conf │ ├── group │ └── mdev.conf ├── share │ ├── keymaps │ │ └── .keep-keymaps-dir │ ├── consolefonts │ │ └── .keep-consolefonts-dir │ └── gnupg │ │ └── options.skel ├── root │ └── .gnupg │ │ └── gpg.conf └── lib │ ├── mkinitramfs-ll │ ├── helpers │ └── functions │ └── mdev │ ├── dm_link │ └── ide_links ├── mkinitramfs-ll.conf ├── AUTHORS ├── hooks ├── fb-video ├── disable-bcache ├── bcache ├── mkswap-zfs ├── zram ├── btrfs └── zfs ├── svc ├── zram.confd ├── tmpdir.confd ├── squashdir.confd ├── tmpdir.initd ├── zram.initd ├── squashdir.initd ├── sdr.sh ├── sdr.zsh └── sdr.bash ├── scripts ├── minimal.applets ├── xcpio ├── gnupg.sh ├── busybox.sh └── suspend ├── BUGS ├── COPYING ├── mkinitramfs-ll.conf.in-sh ├── mkinitramfs-ll.conf.in ├── Makefile ├── README.md ├── mkinitramfs-ll.8 ├── init ├── ChangeLog ├── mkinitramfs-ll.sh ├── mkinitramfs-ll.zsh ├── mkinitramfs-ll.bash └── mkinitramfs-ll.5 /usr/bin/.keep-bin-dir: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /usr/sbin/.keep-sbin-dir: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /usr/etc/splash/.keep-splash-dir: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /usr/share/keymaps/.keep-keymaps-dir: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /mkinitramfs-ll.conf: -------------------------------------------------------------------------------- 1 | mkinitramfs-ll.conf.in-sh -------------------------------------------------------------------------------- /usr/share/consolefonts/.keep-consolefonts-dir: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | CopyLeft (c) 2011-2016 tokiclover 2 | -------------------------------------------------------------------------------- /usr/etc/modprobe.d/zfs.conf: -------------------------------------------------------------------------------- 1 | options zfs zfs_arc_max=536870912 2 | -------------------------------------------------------------------------------- /usr/root/.gnupg/gpg.conf: -------------------------------------------------------------------------------- 1 | no-greeting 2 | #charset utf-8 3 | #lock-once 4 | keyserver hkp://keys.gnupg.net 5 | -------------------------------------------------------------------------------- /usr/lib/mkinitramfs-ll/helpers: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: /lib/mkinitramfs-ll/helpers Exp $ 3 | # $Author: (c) 2011-2015 -tclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.19.0 2015/02/20 12:33:03 Exp $ 6 | # 7 | 8 | # @DESCRIPTION: Handle scripts fatal error 9 | # @ARG: 10 | die() { 11 | local ret=$? 12 | [ -n "$@" ] && msg -e "$@" 13 | exit $ret 14 | } 15 | 16 | # 17 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 18 | # 19 | -------------------------------------------------------------------------------- /usr/etc/group: -------------------------------------------------------------------------------- 1 | root:x:0:root 2 | bin:x:1:root,bin,daemon 3 | daemon:x:2:root,bin,daemon 4 | sys:x:3:root,bin,adm 5 | adm:x:4:root,adm,daemon 6 | tty:x:5: 7 | disk:x:6:root,adm 8 | lp:x:7:lp 9 | mem:x:8: 10 | kmem:x:9: 11 | wheel:x:10:root 12 | floppy:x:11:root 13 | mail:x:12: 14 | news:x:13:news 15 | uucp:x:14:uucp 16 | man:x:15: 17 | cron:x:16: 18 | console:x:17: 19 | audio:x:18: 20 | cdrom:x:19: 21 | dialout:x:20: 22 | sshd:x:22: 23 | tape:x:26:root 24 | video:x:27:root 25 | cdrw:x:80: 26 | usb:x:85: 27 | nullmail:x:88: 28 | users:x:100: 29 | dnsmasq:x:101: 30 | fcron:x:102: 31 | input:x:105: 32 | ntp:x:123: 33 | utmp:x:406: 34 | -------------------------------------------------------------------------------- /hooks/fb-video: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/hooks/bacache Exp $ 3 | # $Author: (c) 2011-19 tokiclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # 6 | 7 | [ -z "$video" ] && get_cmdline_option "video" 8 | 9 | video() { 10 | echo $$ >/run/${0##*/}.pid 11 | local _bin name=fbset 12 | $CHECK_ENV && debug -d check_bin fbset 13 | 14 | fbset -fb /dev/fb0 -g "$1" "$2" "$1" "$2" "$3" 15 | 16 | rm /run/${0##*/}.pid 17 | } 18 | 19 | if [ -n "$video" ]; then 20 | debug video $(echo "$video" | sed 's,[x-], ,g') 21 | fi 22 | 23 | # 24 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 25 | # 26 | -------------------------------------------------------------------------------- /svc/zram.confd: -------------------------------------------------------------------------------- 1 | # 2 | # $Id: mkinitramfs-ll/svc/zram.confd, 2016/06/06 Exp $ 3 | # 4 | 5 | # Set the number of zram devices to use 6 | ZRAM_DEVICE_NUMBER=4 7 | # Set compressor algorithm to use 8 | ZRAM_COMPRESSOR=lz4 9 | # Set the maximum number of streams for (de)compression per device 10 | ZRAM_STREAM_NUMBER=2 11 | # 12 | # ZRAM device definition is defined like: 13 | # 14 | # device size should not excede 2xRAM-SIZE to avoid memory waste 15 | # 16 | ZRAM_DEVICE_0='512M swap' 17 | ZRAM_DEVICE_1='4G ext4 /var/tmp user_xattr 1777' 18 | ZRAM_DEVICE_2='512M ext4 /tmp user_xattr 1777' 19 | 20 | # 21 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 22 | # 23 | -------------------------------------------------------------------------------- /hooks/disable-bcache: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/hooks/bacache Exp $ 3 | # $Author: (c) 2011-6 tokiclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.22.1 2019/01/02 12:33:03 Exp $ 6 | # 7 | 8 | [ -z "$bcache" ] && get_cmdline_option "bcache" 9 | 10 | undobcahe() { 11 | echo $$ >/run/${0##*/}.pid 12 | local IFS=":$IFS" _dev _DEV 13 | 14 | for _dev in $bcache; do 15 | blk "$_dev" "_DEV" 16 | _dev=${_DEV##*/} 17 | echo 1 > /sys/block/${_dev:0:3}/$_dev/bcache/running 18 | done 19 | rm -f /run/${0##*/}.pid 20 | } 21 | 22 | [ -n "$bcache" ] && undobcache 23 | 24 | # 25 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 26 | # 27 | -------------------------------------------------------------------------------- /usr/lib/mdev/dm_link: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | # 3 | # $Header: mkinitramfs-ll: /lib/mdev/dm_link Exp $ 4 | # $Author: (c) 2011-2014 -tclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.14.4 2014/10/10 12:33:03 Exp $ 7 | # 8 | 9 | if [ "$ACTION" = "add" ]; then 10 | mkdir -m 755 -p /dev/mapper 11 | name="$(cat /sys/block/${MDEV}/dm/name)" 12 | [ -n "$name" ] && ln -f -s /dev/${MDEV} /dev/mapper/$name 13 | fi 14 | 15 | [ "$ACTION" = "remove" ] && 16 | for dm in /dev/mapper/*; do 17 | test -h $dm -a "$(readlink $dm)" = "/dev/$MDEV" && rm -f $dm && break 18 | done 19 | 20 | unset name 21 | 22 | # 23 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 24 | # 25 | -------------------------------------------------------------------------------- /svc/tmpdir.confd: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/svc/tmpdir.confd, 2015/04/18 Exp $ 3 | # 4 | # tmpdir maintain a temporary directory hierarchy on a tmpfs or zram 5 | # backed device. Keeping the state of a diretory across machine reboot 6 | # is available & optional, comes with a tarball. 7 | # 8 | 9 | # Enable zram backed device (instead of regular tmpfs) 10 | use_zram=yes 11 | # Root directory of the file system hierachy 12 | tmpdir_root=/var/tmp 13 | # Set the size to use (tmpfs case) 14 | tmpdir_size=20% 15 | 16 | # Colon separated list of directory to archive 17 | tmpdir_saved= 18 | # Colon separated list of direcory (without saved state, backup) 19 | tmpdir_unsaved= 20 | # Set the compressor to use (for state saved directory) 21 | compressor="lz4 -1 -" 22 | 23 | # 24 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 25 | # 26 | -------------------------------------------------------------------------------- /usr/lib/mdev/ide_links: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Header: mkinitramfs-ll: /lib/mdev/ide_links Exp $ 4 | # $License: GPL-2 Exp $ 5 | # 6 | 7 | [ -f /proc/ide/$MDEV/media ] || exit 8 | 9 | media=`cat /proc/ide/$MDEV/media` 10 | for i in $media $media[0-9]* ; do 11 | if [ "`readlink $i 2>/dev/null`" = $MDEV ] ; then 12 | LINK=$i 13 | break 14 | fi 15 | done 16 | 17 | # link exist, remove if necessary and exit 18 | if [ -n "$LINK" ] ; then 19 | [ "$ACTION" = remove ] && rm $LINK 20 | exit 21 | fi 22 | 23 | # create a link 24 | num=0 25 | for m in $media[0-9]*; do 26 | num="$(expr $num + 1)" 27 | done 28 | 29 | ln -sf "$MDEV" "$media$num" 30 | [ -e "$media" ] || ln -sf $MDEV "$media" 31 | 32 | unset media num 33 | 34 | # 35 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 36 | # 37 | -------------------------------------------------------------------------------- /hooks/bcache: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/hooks/bacache Exp $ 3 | # $Author: (c) 2011-6 tokiclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.22.1 2016/06/02 12:33:03 Exp $ 6 | # 7 | 8 | [ -z "$bcache" ] && get_cmdline_option "bcache" 9 | 10 | # 11 | # FIXME: luks, lvm, raid support? 12 | # 13 | enable_bcache() { 14 | echo $$ >/run/${0##*/}.pid 15 | debug MODPROBE bcache 16 | 17 | local IFS=":$IFS" _dev _DEV 18 | for _dev in $bcache; do 19 | blk "$_dev" "_DEV" 20 | echo $_DEV >/sys/fs/bcache/register_quiet 21 | done 22 | rm -f /run/${0##*/}.pid 23 | } 24 | 25 | retval=0 26 | 27 | if [ -n "$bcache" ]; then 28 | enable_bcache 29 | retval="$?" 30 | fi 31 | 32 | exit "$retval" 33 | 34 | # 35 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 36 | # 37 | -------------------------------------------------------------------------------- /svc/squashdir.confd: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/svc/squashdir.confd, 2015/05/28 Exp $ 3 | # 4 | 5 | # Squash directory root, where to put the merged hierchy filesystem 6 | squash_rootdir=/squash 7 | # File system to use for the merged hierachy 8 | # Supported value: aufs, overlay; or else, auto-detected 9 | #squash_filesystem=aufs 10 | 11 | # System wide squash-ed directory-ies 12 | #squash_sysdir="/usr /opt" 13 | 14 | # Local squash-ed directory-ies 15 | squash_localdir="/var/db /var/cache/edb" 16 | 17 | # Squashed directory-ies to rebuild before shutting down the service 18 | # WARN: This list should be in either squash_sysdir|localdir group 19 | squash_rebuild_dir= 20 | # 21 | # Full path to sdr script, or else default to $(which sdr) 22 | sdr=/usr/sbin/sdr 23 | # Offset to use when rebuilding (in percent) 24 | offset=10 25 | 26 | # 27 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 28 | # 29 | -------------------------------------------------------------------------------- /scripts/minimal.applets: -------------------------------------------------------------------------------- 1 | bin/ash 2 | bin/awk 3 | sbin/blkid 4 | bin/bunzip2 5 | bin/bzip2 6 | bin/cat 7 | bin/chattr 8 | bin/chgrp 9 | bin/chmod 10 | bin/chown 11 | sbin/chroot 12 | bin/chvt 13 | bin/clear 14 | bin/cp 15 | bin/cpio 16 | bin/cut 17 | bin/dd 18 | bin/diff 19 | bin/dirname 20 | bin/dmesg 21 | bin/dumpkmap 22 | bin/ed 23 | bin/egrep 24 | bin/env 25 | bin/expr 26 | sbin/fsck 27 | bin/grep 28 | bin/gunzip 29 | bin/gzip 30 | sbin/halt 31 | bin/head 32 | sbin/init 33 | bin/ln 34 | sbin/loadfont 35 | sbin/loadkmap 36 | sbin/losetup 37 | bin/lsattr 38 | bin/lzma 39 | sbin/mdev 40 | bin/mkdir 41 | bin/mknod 42 | sbin/modinfo 43 | sbin/modprobe 44 | bin/mount 45 | bin/mv 46 | bin/openvt 47 | bin/patch 48 | bin/printf 49 | bin/readlink 50 | bin/rm 51 | bin/rmdir 52 | sbin/rmmod 53 | bin/sed 54 | bin/seq 55 | sbin/setconsole 56 | sbin/setfont 57 | bin/setkeycodes 58 | sbin/setlogcons 59 | bin/setsid 60 | bin/sleep 61 | sbin/switch_root 62 | bin/tar 63 | bin/test 64 | bin/tr 65 | bin/tty 66 | bin/umount 67 | bin/uncompress 68 | bin/unlzma 69 | bin/unxz 70 | bin/unzip 71 | bin/vi 72 | bin/which 73 | bin/xargs 74 | bin/xz 75 | -------------------------------------------------------------------------------- /hooks/mkswap-zfs: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/hooks/mkswap.zfs Exp $ 3 | # $Author: (c) 2011-6 tokiclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.14.7 2014/11/11 12:33:03 Exp $ 6 | # 7 | 8 | mkswap_zfs() { 9 | usage() { 10 | cat <<-EOH 11 | usage: mkswap_zfs: [options] -s|--size pool/volume 12 | -o|--option zpool-option 13 | -b|--bs 8k block-size, default 4k 14 | EOH 15 | } 16 | if ! test $# -ge 2; then 17 | usage 18 | return 1 19 | fi 20 | local _bs _opt _size 21 | while test $# > 1; do 22 | case "$1" in 23 | (-b|--bs) 24 | _bs=$2 25 | shift 2;; 26 | (-o|--option) 27 | _opt="$_opt -o $2" 28 | shift 2;; 29 | (-s|--size) 30 | _size=$2 31 | shift;; 32 | (-h|--help) usage;; 33 | esac 34 | done 35 | if ! test $# -eq 1 -a -n "$1" -a -n "$_size"; then 36 | usage 37 | return 2 38 | fi 39 | 40 | zfs create -o sync=always -o primarycache=metadata \ 41 | -o secondarycache=none $_opt -b ${_bs:-4k} -V $_size $1 42 | } 43 | 44 | [ "${0##*/}" = "mkswap-zfs" ] && mkswap_zfs "$@" 45 | 46 | # 47 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 48 | # 49 | -------------------------------------------------------------------------------- /BUGS: -------------------------------------------------------------------------------- 1 | Header: mkinitramfs-ll/BUGS, 2015/01/20 2 | 3 | --- 4 | rescue shell (rsh): 5 | Sometimes exit-ing in a rescue shell does not work, init will be stuck in 6 | place. In this case *do not* exit a second or a kernel panic await. It's 7 | better to unmount everything, close dm-crypt cyphertext and reboot. 8 | --- 9 | /etc/mdev.conf: 10 | uid:gid should be use instead of user:group, or else, expect failure. 11 | --- 12 | /etc/mtab: 13 | this file should be readable, or else a `/mtab' whould be created. 14 | --- 15 | die (helper): 16 | die() does not work properly in a script/module (rsh is ignored all together). 17 | So helper alternative (in LIBDIR/helpers) is available that will properly exit. 18 | ___ 19 | squashdir.initd: 20 | this init service cannot manage mounting in time with newer >=udev-182, so 21 | some depend() hacks were added, still system directories should listed first 22 | especially `usr'. 23 | ___ 24 | echo: 25 | echo-ing return values is problematic, this should be minimized or replaced 26 | by global variables. 27 | ___ 28 | swsusp: 29 | *resume=device resume_offset=value* are required when resuming from a file 30 | with swsusp (default implementation if not using a TuxOnIce patched kernel). 31 | Beware that a plain partition is necessary, or else, resuming will fails. 32 | (The issue is there is no delay nor a sysfs file to echo the offset value.) 33 | --- 34 | 35 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | COPYLEFT 2 | ALL WRONGS RESERVED 3 | 4 | --- 5 | 6 | CopyLeft 2011-2016 tokiclover 7 | 8 | Redistribution and use in source and binary forms, with or without modification, are 9 | permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, this list of 12 | conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | of conditions and the following disclaimer in the documentation and/or other materials 16 | provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY TOKICLOVER/-TCLOVER ''AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOKICLOVER OR 21 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | The views and conclusions contained in the software and documentation are those of the 29 | authors and should not be interpreted as representing official policies, either expressed 30 | or implied, of tokiclover. 31 | 32 | --- 33 | -------------------------------------------------------------------------------- /scripts/xcpio: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Header: mkinitramfs-ll/scripts/xcpio Exp $ 4 | # $Author: (c) 2011-2015 -tclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 2015/01/20 12:33:03 Exp $ 7 | # 8 | 9 | usage() { 10 | cat <<-EOH 11 | usage: xcpio [options] files 12 | -l, --list list files 13 | -x, --extract extract files 14 | -d, --decompress decompress files 15 | EOH 16 | exit 17 | } 18 | 19 | [ "$#" = 0 ] && usage 20 | 21 | comp() { 22 | local comp 23 | case "$2" in 24 | (*.bz*2) comp='bzip2 -d -k' ;; 25 | (*.gz*) comp='gzip -d' ;; 26 | (*.xz|*.lzma) comp='xz -d -k';; 27 | (*.lzo*) comp='lzop -d -k' ;; 28 | (*.lz4) comp='lz4 -d' ;; 29 | (*.lz*) comp='lzip -d -k' ;; 30 | (*) echo "xcpio: unsupported compression format" 31 | exit 2;; 32 | esac 33 | $comp $@ 34 | } 35 | 36 | case "$1" in 37 | (-l|--list) opt=-t 38 | shift;; 39 | (-x|-*xtract) opt=-id 40 | shift;; 41 | (-d|*compress) opt= 42 | shift;; 43 | (*) opt=-t;; 44 | esac 45 | 46 | for file in $*; do 47 | if [ -f "$file" ]; then 48 | tmpdir=${file##*/} 49 | tmpdir=$(mktemp -d ${tmpdir%.cpio*}-XXXXXX) 50 | cd $tmpdir || exit $? 51 | if [ -n "$opt" ]; then 52 | comp "-c" "$file" | cpio $opt -v 53 | else 54 | comp "$file" 55 | fi 56 | [ "$?" = 0 ] && echo "xcpio: successfuly deflated to $tmpdir" || 57 | echo "xcpio: failed to process file" 58 | else 59 | echo "xcpio: $file file not found" 60 | fi 61 | done 62 | 63 | unset -v file opt pipe tmpdir 64 | 65 | # 66 | # vim:fenc=utf-8:ci:pi:sts=0:sw=4:ts=4: 67 | # 68 | -------------------------------------------------------------------------------- /hooks/zram: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/hooks/zram Exp $ 3 | # $Author: (c) 2011-6 tokiclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.22.1 2019/01/02 12:33:03 Exp $ 6 | # 7 | 8 | [ -z "$zram" ] && get_cmdline_option "zram" 9 | 10 | enable_zram() { 11 | echo $$ >/run/${0##*/}.pid 12 | eval set -- $(echo "${zram%%:*}" | sed -e 's/-/ /g') 13 | 14 | local compressor="$3" devices="${1:-4}" streams="${2:-2}" 15 | debug -d modprobe zram num_devices=$devices 16 | case "$compressor" in 17 | (lz4|lzo) :;; 18 | (*) compressor=lz4;; 19 | esac 20 | [ -w /sys/block/zram0/comp_algorithm ] || compressor= 21 | [ -w /sys/block/zram0/max_comp_streams ] || streams= 22 | 23 | local name=zram num=0 dev device fs mopt size 24 | for device in $(echo "${zram#*:}" | sed -e 's/:/ /g'); do 25 | [ "$num" = "$num_devices" ] && break 26 | 27 | eval set -- $(echo "$device" | sed -e 's/-/ /g') 28 | size="$1" fs="$2" dev=/sys/block/zram$num 29 | [ -n "$size" ] || continue 30 | [ -b /dev/zram$num ] || break 31 | 32 | [ -n "$compressor" ] && echo $compressor >$dev/comp_algorithm 33 | [ -n "$streams" ] && echo $streams >$dev/max_comp_streams 34 | echo $size >$dev/disksize 35 | num=$(($num + 1)) 36 | [ -n "$fs" ] || continue 37 | if [ -x /sbin/mkfs.$fs ]; then 38 | debug -d /sbin/mkfs.$fs /dev/${dev##*/} 39 | else 40 | error "mkfs.$fs not found" 41 | fi 42 | done 43 | rm -f /run/${0##*/}.pid 44 | } 45 | 46 | retval=0 47 | 48 | if [ -n "$zram" ]; then 49 | enable_zram 50 | retval="$?" 51 | fi 52 | 53 | exit "$retval" 54 | 55 | # 56 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 57 | # 58 | -------------------------------------------------------------------------------- /hooks/btrfs: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/hooks/btrfs Exp $ 3 | # $Author: (c) 2011-6 tokiclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.22.1 2019/01/02 12:33:03 Exp $ 6 | # 7 | 8 | [ -z "$bcache" ] && get_cmdline_option "btrfs" 9 | [ -n "$btrfs" ] || exit 10 | 11 | mount_btrfs() { 12 | echo $$ >/run/${0##*/}.pid 13 | local _bin _CHK _dev _DEV DEV name=btrfs 14 | $CHECK_ENV && debug -d check_bin btrfs 15 | debug MODPROBE btrfs 16 | 17 | debug -d test -n "$1" -a -n "$2" -a -n "$3" 18 | local _cut _env="$1" _grp="$2" _KEY _vol="$3" 19 | CUT "_CHK" "$rootfstype" ":" "2" "-s" 20 | [ $_grp -ge 2 ] && _cut=-s 21 | [ -n "$btrfs" ] && CUT "_DEV" "$btrfs" "," "$_grp" "$_cut" 22 | [ -n "$luks" ] && CUT "_KEY" "$luks" "," "$_grp" "$_cut" 23 | [ -n "$_DEV" ] || return 24 | debug -d get_key "$_KEY" 25 | eval set -- $(echo "$_DEV" | sed 's/:/ /g') 26 | 27 | if ! btrfs filesystem show "${_vol#*=}" >$NULL 2>&1; then 28 | if yesno "$_DEV"; then 29 | error "No $_vol filesystem found" 30 | [ -n "$_CHK" ] || return 31 | fi 32 | if [ "$KEYMODE" != "none" ]; then 33 | for _dev in "$@"; do 34 | debug -d dmopen "$_dev" "_DEV" 35 | DEV="$_DEV $DEV" 36 | done 37 | fi 38 | fi 39 | if [ "$KEYMODE" = "none" ]; then 40 | for _dev in "$@"; do 41 | blk "$_dev" "_DEV" 42 | DEV="$_DEV $DEV" 43 | done 44 | fi 45 | debug -d btrfs device scan $DEV 46 | 47 | if [ -n "$_CHK" ]; then 48 | yesno "$_CHK" && _CHK=-d || _CHK=-e 49 | for _dev in $DEV; do 50 | debug $_CHK btrfs check --repair $_dev 51 | done 52 | fi 53 | debug -d mount -t btrfs ${rootflags:+-o} $rootflags $_vol $newroot 54 | echo "$_env=$_vol" >>/run/env 55 | rm -f /run/${0##*/}.pid 56 | } 57 | 58 | retval=0 59 | 60 | if [ -n "$root" ]; then 61 | debug mount_btrfs "ROOT" "1" "$root" 62 | retval="$?" 63 | fi 64 | 65 | exit "$retval" 66 | 67 | # 68 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 69 | # 70 | -------------------------------------------------------------------------------- /scripts/gnupg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # $Header: mkinitramfs-ll/gnupg.sh Exp $ 4 | # $Author: (c) 2011-2015 -tclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.20.0 2015/05/24 12:33:03 Exp $ 7 | # 8 | 9 | name=gnupg 10 | shell=sh 11 | version=0.20.0 12 | 13 | # @FUNCTION: Print help message 14 | usage() { 15 | cat <<-EOH 16 | ${name}.${shell} version ${version} 17 | usage: ${name}.${shell} [OPTIONS] 18 | 19 | -d, --usrdir=usr USRDIR to use for binary/options.skel copy 20 | -u, --useflag=flags Set extra USE flags to use 21 | -v, --version= Set version to use instead of latest 1.4.x 22 | -h, --help, -? Print this help message and and exit 23 | EOH 24 | exit $? 25 | } 26 | 27 | opt="$(getopt \ 28 | -o \?hd:u:v: \ 29 | -l help,useflag:,usrdir:,version: \ 30 | -n "${name}.${shell}" -s sh -- "$@" || usage)" 31 | [ ${?} = 0 ] || exit 1 32 | eval set -- ${opt} 33 | 34 | while true; do 35 | case "${1}" in 36 | (-d|--usrdir) usrdir="${2}"; shift;; 37 | (-u|--useflag) useflag="${2}"; shift;; 38 | (-v|--version) vsn="${2}"; shift;; 39 | (--) shift; break;; 40 | (-?|-h|--help|*) usage;; 41 | esac 42 | shift 43 | done 44 | 45 | [ -f /etc/portage/make.conf ] && source /etc/portage/make.conf || 46 | die "No /etc/portage/make.conf found" 47 | source "${usrdir}"/lib/mkinitramfs-ll/functions || exit 1 48 | eval_colors 49 | 50 | : ${usrdir:=${PWD}/usr} 51 | : ${vsn:=1.4} 52 | # @VARIABLE: GnuPG version to use 53 | pkg=$(emerge -pvO "=app-crypt/gnupg-${vsn}*" | 54 | grep -o "gnupg-[-0-9.r]*") 55 | 56 | mkdir -p "${usrdir}"/{bin,share/gnupg} 57 | cd ${PORTDIR:-/usr/portage}/app-crypt/gnupg 58 | ebuild ${pkg}.ebuild clean || die 59 | USE="nls static ${useflag}" ebuild ${pkg}.ebuild compile || die 60 | tmp="${PORTAGE_TMPDIR:-/var/tmp}/portage/app-crypt/${pkg}/work/${pkg}" 61 | cp -a ${tmp}/g10/gpg "${usrdir}"/bin/ || die 62 | cp -a ${tmp}/g10/options.skel "${usrdir}"/share/gnupg/ || die 63 | ebuild ${pkg}.ebuild clean || die 64 | cd "${OLDPWD}" 65 | 66 | # 67 | # vim:fenc=utf-8:ci:pi:sts=0:sw=4:ts=4: 68 | # 69 | -------------------------------------------------------------------------------- /hooks/zfs: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll/hooks/zfs Exp $ 3 | # $Author: (c) 2011-2015 -tclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.22.1 2019/01/02 12:33:03 Exp $ 6 | # 7 | 8 | [ -z "$zfs" ] && get_cmdline_option "zfs" 9 | [ -n "$zfs" ] || exit 10 | 11 | # @FUNCTION: dozfs 12 | # @DESCRIPTION: import a zfs pool 13 | # @USAGE: 14 | mount_zfs() { 15 | echo $$ >/run/${0##*/}.pid 16 | local bin name=zfs 17 | $CHECK_ENV && debug -d check_bin zfs spool 18 | debug -d test -n "$1" -a -n "$2" -a -n "$3" 19 | local _env="$1" _grp="$2" _vol="$3" _KEY _opt="$4" 20 | 21 | local _sign _type _vdev 22 | [ -n "$zfs" ] && CUT "_vdev" "$zfs" "," "$_grp" "${_opt:+-s}" 23 | [ -n "$luks" ] && CUT "_KEY" "$luks" "," "$_grp" "${_opt:+-s}" 24 | [ -n "$_vdev" ] || return 25 | 26 | if [ "$_grp" -ge 2 ]; then 27 | eval set -- $(echo "$_vol" | sed -e 's/:/ /g') 28 | _vol="$2" _sign="$3" _type="$1" 29 | fi 30 | debug -d MODPROBE zfs 31 | local _pool="${_vol%/*}" 32 | 33 | if ! zpool list -H $_pool >$NULL 2>&1; then 34 | if yesno "$_vdev"; then 35 | error "No $_pool pool found" 36 | return 37 | fi 38 | debug -d get_key "$_KEY" 39 | if [ "$KEYMODE" != "none" ]; then 40 | for _dev in $(echo "$_vdev" | sed 's/:/ /g'); do 41 | debug -d dmopen "$_dev" 42 | done 43 | _opt="-d /dev/mapper $_opt" 44 | fi 45 | debug -d zpool import -f $_opt -R $newroot "$_pool" 46 | fi 47 | if [ "$_grp" = 1 ]; then 48 | zfs mount | grep -q "$_vol" || debug -d zfs mount -vO -a 49 | else 50 | zfs list | grep -q "$_vol" || die "$_vol volume not found" 51 | _vol=/dev/zvol/$_vol 52 | fi 53 | rm /run/${0##*/}.pid 54 | echo "$_env=${_type:+$_type:}$_vol${_sign:+$_sign}" >> /run/env 55 | } 56 | 57 | retval=0 58 | 59 | if [ -n "$swap" ]; then 60 | debug dozfs "SWAP" "2" "$swap" "-N" 61 | retval="$?" 62 | fi 63 | if [ -n "$resume" ]; then 64 | debug dozfs "RESU" "3" "$resume" "-N" 65 | retval=$(($?+$ratval)) 66 | fi 67 | if [ -n "$root" ]; then 68 | debug mount_zfs "ROOT" "1" "$root" 69 | retval=$(($?+$retval)) 70 | fi 71 | 72 | exit "$retval" 73 | 74 | # 75 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 76 | # 77 | -------------------------------------------------------------------------------- /scripts/busybox.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Header: mkinitramfs-ll/busybox.sh Exp $ 4 | # $Author: (c) 2011-2015 -tclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.22.0 2016/11/06 12:33:03 Exp $ 7 | 8 | name=busybox 9 | shell=sh 10 | version=0.20.0 11 | 12 | # @FUNCTION: Print help message 13 | usage() { 14 | cat <<-EOH 15 | ${name}.${shell} version ${version} 16 | usage: ${name}.${shell} [OPTIONS] 17 | 18 | -d, --usrdir=usr USRDIR to use (where to copy BusyBox binary) 19 | -v, --version=1.20.0 Set version to build instead of latest 20 | -h, --help, -? Print the help message and exit 21 | EOH 22 | exit $? 23 | } 24 | 25 | die() { 26 | local ret="${?}"; error "${@}"; exit ${ret} 27 | } 28 | 29 | opt="$(getopt \ 30 | -o \?hd:v: \ 31 | -l help,usrdir:,version: \ 32 | -n ${name}.${shell} -s sh -- "${@}" || usage)" 33 | [ ${?} = 0 ] || exit 1 34 | eval set -- ${opt} 35 | while true; do 36 | case "${1}" in 37 | (-d|--usrdir) usrdir="${2}"; shift;; 38 | (-v|--version) vsn="${2}"; shift;; 39 | (--) shift; break;; 40 | (-?|-h|--help|*) usage;; 41 | esac 42 | shift 43 | done 44 | 45 | : ${usrdir:=${PWD}/usr} 46 | pkg=busybox 47 | 48 | [ -f /etc/portage/make.conf ] && source /etc/portage/make.conf || 49 | die "No /etc/portage/make.conf found" 50 | source "${usrdir}"/lib/mkinitramfs-ll/functions || exit 1 51 | eval_colors 52 | 53 | if [ -n "${vsn}" ]; then 54 | pkg=${pkg}-${vsn} 55 | else 56 | pkg=$(emerge -pvO ${pkg} | grep -o "busybox-[-0-9.r]*") 57 | fi 58 | 59 | cd ${PORTDIR:-/usr/portage}/sys-apps/busybox 60 | mkdir -p "${usrdir}"/bin 61 | USE="-pam static" ebuild ${pkg}.ebuild clean || die "clean failed" 62 | USE=static ebuild ${pkg}.ebuild configure || die "configure failed" 63 | # Small modprobe is not able to properly resolve dependencies, though it should 64 | sed -e "s/CONFIG_MODPROBE_SMALL=y/# CONFIG_MODPROBE_SMALL is not set/" \ 65 | -i "${PORTAGE_TMPDIR:-/var/tmp}"/portage/sys-apps/${pkg}/work/${pkg}/.config 66 | USE="-pam static" ebuild ${pkg}.ebuild compile || die "compile failed" 67 | cp "${PORTAGE_TMPDIR:-/var/tmp}"/portage/sys-apps/${pkg}/work/${pkg}/busybox \ 68 | "${usrdir}"/bin/ || die 69 | ebuild ${pkg}.ebuild clean || die 70 | cd "${OLDPWD}" 71 | 72 | # 73 | # vim:fenc=utf-8:ci:pi:sts=0:sw=4:ts=4: 74 | # 75 | -------------------------------------------------------------------------------- /usr/etc/mdev.conf: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: mkinitramfs-ll: /etc/mdev.conf Exp $ 3 | # $Author: (c) 2011-2014 -tclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.14.4 2014/10/10 12:33:03 Exp $ 6 | # 7 | # Syntax: 8 | # [-][ENVVAR=regex;]...devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] 9 | # [-][ENVVAR=regex;]...@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] 10 | # [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...] 11 | # 12 | # [-]: do not stop on this match, continue reading mdev.conf 13 | # =: move, >: move and create a symlink 14 | # !: do not create device node 15 | # @|$|*: run cmd if $ACTION=remove, @cmd if $ACTION=add, *cmd in all cases 16 | # 17 | 18 | $MODALIAS=.* 0:0 660 @modprobe "$MODALIAS" 19 | 20 | null 0:0 666 @chmod 666 $MDEV 21 | zero 0:0 666 22 | full 0:0 666 23 | random 0:0 444 24 | urandom 0:0 444 25 | hwrandom 0:0 444 26 | grsec 0:0 660 27 | 28 | loop-control 0:0 600 29 | device-mapper 0:0 600 =mapper/control 30 | dm-[0-9]* 0:6 660 */lib/mdev/dm_link 31 | 32 | kmem 0:0 640 33 | mem 0:0 640 34 | port 0:0 640 35 | console 0:5 600 @chmod 600 $MDEV 36 | ptmx 0:5 666 37 | pty.* 0:5 660 38 | 39 | tty 0:5 666 40 | tty[0-9]* 0:5 660 41 | vcsa*[0-9]* 0:5 660 42 | ttyS[0-9]* 0:14 660 43 | 44 | ram([0-9]*) 0:6 660 >rd/%1 45 | loop([0-9]+) 0:6 660 >loop/%1 46 | hd[a-z][0-9]* 0:6 660 */lib/mdev/ide_links 47 | md[0-9]* 0:6 660 48 | sr[0-9]* 0:19 660 @ln -sf $MDEV cdrom 49 | fd[0-9]* 0:11 660 50 | 51 | -net/.* 0:0 600 @nameif 52 | tun[0-9]* 0:0 600 =net/ 53 | tap[0-9]* 0:0 600 =net/ 54 | 55 | cciss!(.*) 0:6 660 =cciss/%1 56 | ida!(.*) 0:6 660 =ida/%1 57 | rd!(.*) 0:6 660 =rd/%1 58 | 59 | ttyLTM[0-9] 0:20 660 @ln -sf $MDEV modem 60 | ttySHSF[0-9] 0:20 660 @ln -sf $MDEV modem 61 | slamr 0:20 660 @ln -sf $MDEV slamr0 62 | slusb 0:20 660 @ln -sf $MDEV slusb0 63 | 64 | fuse 0:0 666 65 | 66 | card[0-9] 0:27 660 =dri/ 67 | 68 | agpgart 0:0 660 69 | psaux 0:0 660 70 | rtc 0:0 664 71 | 72 | event[0-9]+ 0:0 640 =input/ 73 | mice 0:0 640 =input/ 74 | mouse[0-9] 0:0 640 =input/ 75 | ts[0-9] 0:0 600 =input/ 76 | 77 | usbdev[0-9]* 0:0 660 78 | 79 | zap(.*) 0:20 660 =zap/%1 80 | dahdi!(.*) 0:20 660 =dahdi/%1 81 | 82 | # 83 | # vim:fenc=utf-8:ci:pi:sts=0:sw=4:ts=4: 84 | # 85 | -------------------------------------------------------------------------------- /scripts/suspend: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Header: mkinitramfs-ll/scripts/suspend Exp $ 4 | # $Author: (c) 2011-2014 -tclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.14.7 2014/11/11 12:33:03 Exp $ 7 | # 8 | 9 | pkg=${0##*/} 10 | 11 | usage() { 12 | cat <<-EOH 13 | usage: $pkg [OPTIONS] [(toi) file/swap | (swsusp) major:minor] 14 | -o, --option platform|shutdown Set swsusp suspend mode (ACPI/shutdown) 15 | -m, --method [mem|disk]|[3|4|5] Set suspend method (ACPI S2/4/5) 16 | First set for swsusp; Second set for TuxOnIce 17 | -c, --compression Set TuxOnIce compression algorithm 18 | -s, --size N Set image size limit to N bytes 19 | -t, --tuxonice use ToI hibernation implementation 20 | -H, --hibernate Foricibly hibernate at the end 21 | -h, --help Print this help message 22 | EOH 23 | } 24 | 25 | while [ $# -ge 1 ]; do 26 | case "$1" in 27 | (-c|--compression) 28 | comp=$2; 29 | shift 2;; 30 | (-m|--method) 31 | method=$2 32 | shift 2;; 33 | (-o|--option) 34 | option=$2 35 | shift 2;; 36 | (-s|--size) 37 | size=$2 38 | shift 2;; 39 | (-t|--tuxonice) 40 | tuxonice=true 41 | shift 2;; 42 | (-H|--hibernate) 43 | hibernate=true 44 | shift;; 45 | (-h|--help) 46 | usage 47 | exit;; 48 | esac 49 | done 50 | 51 | if [ $# != 1 ]; then 52 | echo "$pkg: missing required argument" >&2 53 | exit 1 54 | fi 55 | 56 | if [ -n "$tuxonice" ]; then 57 | if [ ! -d /sys/power/tuxonice ]; then 58 | echo "$pkg: Error: TuxOnIce hibernation is not supported" >&2 59 | exit 2 60 | fi 61 | [ -n "$comp" ] && echo $size > /sys/power/tuxonice/compression/algorithm 62 | [ -n "$size" ] && echo $size > /sys/power/tuxonice/image_size_limit 63 | echo ${method:-4} > /sys/power/tuxonice/powerdown_method 64 | echo $1 > /sys/power/tuxonice/swap/swapfile 65 | echo "Resume device: (ToI) $(cat /sys/power/tuxonice/swap/headerlocations)" 66 | cmd='echo > /sys/power/tuxonice/do_hibernate' 67 | else 68 | [ -n "$size" ] && echo $size > /sys/power/image_size 69 | echo $1 > /sys/power/resume 70 | echo ${option:-platform} > /sys/power/disk 71 | cmd='echo ${method:-disk} > /sys/power/state' 72 | fi 73 | 74 | [ -n "$hibernate" ] && eval $cmd 75 | 76 | unset cmd comp hibernate method size tuxonice 77 | 78 | # 79 | # vim:fenc=utf-8:ci:pi:sts=0:sw=4:ts=4: 80 | # 81 | -------------------------------------------------------------------------------- /svc/tmpdir.initd: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | # 3 | # $Header: mkinitramfs-ll/svc/squashdir.initd Exp $ 4 | # $Author: (c) 2012-6 tokiclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.20.0 2016/07/20 12:33:03 Exp $ 7 | # 8 | 9 | description="Temporary directory (with optional backup) setup" 10 | extra_commands="restore save" 11 | description_restore="Restore temporary directories" 12 | description_save="Archive temporary directories" 13 | 14 | : ${compressor:=lz4 -1} 15 | : ${extension:=.tar.${compressor%% *}} 16 | : ${NULL=/dev/null} 17 | mount="$(command -v mount 2>${NULL})" 18 | umount="$(command -v umount 2>${NULL})" 19 | 20 | depend() 21 | { 22 | if yesno ${use_zram}; then 23 | need zram 24 | fi 25 | before logger 26 | } 27 | 28 | start() 29 | { 30 | local DIR IFS=":${IFS}" dir 31 | 32 | for dir in ${tmpdir_saved} ${tmpdir_unsaved}; do 33 | DIR="${tmpdir_root}${dir}" 34 | mountinfo -q "${DIR}" && continue 35 | mkdir -p "${DIR}" 36 | ebegin "Mounting ${DIR}" 37 | ${mount} --bind "${DIR}" "${dir}" >${NULL} 2>&1 38 | eend "$?" 39 | done 40 | restore 41 | return 0 42 | } 43 | 44 | stop() 45 | { 46 | save 47 | local IFS=":${IFS}" DIR dir 48 | 49 | for dir in ${tmpdir_saved} ${tmpdir_unsaved}; do 50 | case "${dir}" in 51 | (*/log|*/run|*/tmp) continue;; 52 | esac 53 | DIR="${tmpdir_root}${dir}" 54 | mountinfo -q "${DIR}" || continue 55 | ebegin "Unmounting ${DIR}" 56 | ${umount} -l "${DIR}" >${NULL} 2>&1 57 | eend "$?" 58 | done 59 | return 0 60 | } 61 | 62 | start_pre() 63 | { 64 | local IFS=":${IFS}" dir ret 65 | for dir in ${tmpdir_saved}; do 66 | [ -e "${dir}${extension}" ] && continue 67 | [ -d "${dir}" ] && save "${dir}" || mkdir -p "${dir}" 68 | done 69 | 70 | mountinfo -q "${tmpdir_root}" && return 71 | yesno ${use_zram} && ewarn "No suitable (zram) root-dir found" 72 | mkdir -p "${tmpdir_root}" 73 | ${mount} -o rw,nodev,relatime,mode=0755,size=${tmpdir_size:-20%} \ 74 | -t tmpfs tmp "${tmpdir_root}" || return 2 75 | } 76 | 77 | restart() 78 | { 79 | start 80 | } 81 | 82 | restore() 83 | { 84 | local IFS=":${IFS}" swd="${PWD}" tarball 85 | 86 | for dir in ${@:-${tmpdir_saved}}; do 87 | cd "${dir%/*}" >${NULL} 2>&1 || continue 88 | 89 | if [ -f "${dir}${extension}" ]; then 90 | : tarball="${dir}${extension}" 91 | elif [ -f "${dir}.old${extension}" ]; then 92 | : tarball="${dir}.old${extension}" 93 | else 94 | ewarn "No tarball found for ${dir}" 95 | continue 96 | fi 97 | ebegin "Restoring ${dir}" 98 | tar -xpf "${tarball}" -I "${compressor}" 99 | eend "${?}" 100 | done 101 | cd "${swd}" >${NULL} 2>&1 102 | } 103 | 104 | save() 105 | { 106 | local IFS=":${IFS}" swd="${PWD}" 107 | 108 | for dir in ${@:-${tmpdir_saved}}; do 109 | cd "${dir%/*}" >${NULL} 2>&1 || continue 110 | 111 | if [ -f "${dir}${extension}" ]; then 112 | mv -f "${dir}${extension}" "${dir}.old${extension}" 113 | fi 114 | ebegin "Saving ${dir}" 115 | tar -cpf "${dir}${extension}" -I "${compressor}" ${dir##*/} 116 | eend "${?}" 117 | done 118 | cd "${swd}" >${NULL} 2>&1 119 | } 120 | 121 | # 122 | # vim:fenc=utf-8:ft=gentoo-init-d:ci:pi:sts=0:sw=4:ts=4: 123 | # 124 | -------------------------------------------------------------------------------- /svc/zram.initd: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | # 3 | # $Header: mkinitramfs-ll/svc/zram.initd Exp $ 4 | # $Author: (c) 2012-6 tokiclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.22.1 2016/07/20 12:33:03 Exp $ 7 | # 8 | 9 | description="Initialize ZRAM devices and filesystems" 10 | description_reset="Reset ZRAM devices" 11 | extra_commands=reset 12 | 13 | : ${ZRAM_DEVICE_NUMBER:=4} 14 | : ${NULL=/dev/null} 15 | 16 | depend() 17 | { 18 | before bootmisc 19 | } 20 | 21 | start() 22 | { 23 | local blk_dir cmd dev type mode mnt_dir num=0 offset=0 mnt_opts ret 24 | local CONTINUE='{ num=$((${num}+1)); continue; }' 25 | 26 | for cmd in mkfs mount mkswap swapon; do 27 | eval ${cmd}="$(command -v "${cmd}" 2>${NULL})" 28 | done 29 | 30 | while true; do 31 | # 32 | # Find the first free device 33 | # 34 | dev=/dev/zram$((${num}+${offset})) 35 | [ -b ${dev} ] || break 36 | if [ "$(cat /sys/block/${dev##*/}/size)" != 0 ]; then 37 | offset=$((${offset}+1)); continue; 38 | fi 39 | eval set -- \${ZRAM_DEVICE_${num}} 40 | size="${1}" type="${2}" mnt_dir="${3}" mnt_opts="${4}" mode="${5}" 41 | # 42 | # Initialize device if defined 43 | # 44 | blk_dir="/sys/block/${dev##*/}" 45 | [ -n "${size}" ] || break 46 | [ -n "${ZRAM_COMPRESSOR}" ] && 47 | echo "${ZRAM_COMPRESSOR}" >${blk_dir}/comp_algorithm 48 | [ -n "${ZRAM_STREAM_NUMBER}" ] && 49 | echo "${ZRAM_STREAM_NUMBER}" >${blk_dir}/max_comp_streams 50 | echo "${size}" >${blk_dir}/disksize 51 | # 52 | # Setup device if requested 53 | # 54 | [ -n "${type}" ] || eval ${CONTINUE} 55 | case "${type}" in 56 | (swap) 57 | ebegin "Activating ${dev} swap device" 58 | ${mkswap} ${dev} >${NULL} 2>&1 && 59 | ${swapon} ${dev} >${NULL} 2>&1 60 | eend "${?}" 61 | ;; 62 | (*) 63 | ebegin "Formating ${dev} (${type} filesystem)" 64 | ${mkfs} -t ${type} ${dev} >${NULL} 2>&1 65 | ret="${?}" 66 | eend "${ret}" 67 | 68 | if [ "${ret}" = 0 ] && [ -n "${mnt_dir}" ]; then 69 | [ -d "${mnt_dir}" ] || mkdir -p "${mnt_dir}" 70 | 71 | ebegin "Mounting ${dev} to ${mnt_dir}" 72 | ${mount} -t ${type} ${mnt_opts:+-o} ${mnt_opts} ${dev} "${mnt_dir}" 73 | eend "${?}" 74 | [ -n "${mode}" ] && chmod ${mode} "${mnt_dir}" 75 | fi;; 76 | esac 77 | eval ${CONTINUE} 78 | done 79 | return 0 80 | } 81 | 82 | start_pre() 83 | { 84 | case "${ZRAM_COMPRESSOR}" in 85 | (lz4|lzo) ;; 86 | (*) ZRAM_COMPRESSOR=;; 87 | esac 88 | [ -w /sys/block/zram0/comp_algorithm ] || ZRAM_COMPRESSOR= 89 | [ -w /sys/block/zram0/max_comp_streams ] || ZRAM_STREAM_NUMBER= 90 | 91 | if grep -qw zram /proc/modules; then 92 | rmmod zram 2>${NULL} || 93 | { reset && rmmod zram 2>${NULL}; } || 94 | { ewarn "Cannot initialize kernel module"; return; } 95 | fi 96 | modprobe zram num_devices=${ZRAM_DEVICE_NUMBER} 2>${NULL} || reset 97 | } 98 | 99 | stop() 100 | { 101 | local dev type mnt_dir num=0 102 | while true; do 103 | eval set -- \${ZRAM_DEVICE_${num}} 104 | type="${2}" mnt_dir="${3}" 105 | case "${type}" in 106 | (swap) ;; 107 | ([a-z]*) 108 | case "${mnt_dir}" in 109 | (*/run|*/tmp) ;; 110 | (*) 111 | if mountinfo -q "${mnt_dir}"; then 112 | ebegin "Unmounting ${mnt_dir}" 113 | umount -l "${mnt_dir}" 2>${NULL} 114 | eend "${?}" 115 | fi;; 116 | esac;; 117 | (*) break;; 118 | esac 119 | num=$((${num}+1)); continue; 120 | done 121 | return 0 122 | } 123 | 124 | reset() 125 | { 126 | local dev ret=0 127 | for dev in /dev/zram[0-9]*; do 128 | if grep -Eqw "${dev}[[:space:]]" /proc/mounts || 129 | grep -Eqw "${dev}[[:space:]]" /proc/swaps; then 130 | ewarn "${dev} device is mounted" 131 | ret=$((${ret}+1)) 132 | continue 133 | fi 134 | echo 1 >/sys/block/${dev##*/}/reset 135 | done 136 | return ${ret} 137 | } 138 | 139 | restart() 140 | { 141 | start 142 | } 143 | 144 | # 145 | # vim:fenc=utf-8:ft=gentoo-init-d:ci:pi:sts=0:sw=4:ts=4: 146 | # 147 | -------------------------------------------------------------------------------- /svc/squashdir.initd: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | # 3 | # $Header: mkinitramfs-ll/svc/squashdir.initd Exp $ 4 | # $Author: (c) 2012-6 tokiclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.22.0 2016/07/20 12:33:03 Exp $ 7 | # 8 | 9 | description="Set up (AUFS|OverlayFS+SquashFS) union filesystems" 10 | 11 | : ${NULL=/dev/null} 12 | : ${sdr:=$(command -v sdr 2>${NULL})} 13 | : ${squash_rootdir:=/squash} 14 | case "${squash_filesystem}" in 15 | (aufs|overlay) ;; 16 | (*) squash_filesystem=;; 17 | esac 18 | mount="$(command -v mount 2>${NULL})" 19 | umount="$(command -v umount 2>${NULL})" 20 | 21 | depend() 22 | { 23 | after localmount 24 | if [ "${RC_RUNLEVEL}" = "boot" ]; then 25 | before consolefont bootmisc acpid keymaps 26 | fi 27 | } 28 | 29 | start_pre() 30 | { 31 | local mod 32 | ebegin "Setting up kernel modules" 33 | for mod in ${squash_filesystem:-aufs overlay} squashfs; do 34 | grep -q ${mod} /proc/filesystems || modprobe ${mod} >${NULL} 2>&1 || 35 | case "${mod}" in 36 | (overlay|squashfs) { eend 1 ${mod}; return 1; };; 37 | (aufs) continue;; 38 | esac 39 | case "${mod}" in 40 | (aufs|overlay) squash_filesystem="${mod}"; break;; 41 | esac 42 | done 43 | eend ${?} 44 | } 45 | 46 | start() 47 | { 48 | local dir 49 | for dir in ${squash_sysdir} ${squash_localdir}; do 50 | squash_mount "${squash_rootdir}" "${dir}" 51 | done 52 | return 0 53 | } 54 | 55 | stop() 56 | { 57 | local dir 58 | for dir in ${squash_localdir}; do 59 | squash_umount "${squash_rootdir}" "${dir}" 60 | done 61 | for dir in ${squash_sysdir}; do 62 | squash_remount "${dir}" "ro" 63 | done 64 | return 0 65 | } 66 | 67 | stop_pre() 68 | { 69 | local mod 70 | for mod in ${squash_filesystem:-aufs overlay}; do 71 | grep -q ${mod} /proc/filesystems && 72 | { squash_filesystem="${mod}"; break; } 73 | done 74 | [ -n "${squash_filesystem}" ] || return 75 | [ -n "${squash_rebuild_dir}" ] || return 0 76 | [ -n "${sdr}" -a -x "${sdr}" ] || { ewarn "No suitable sdr found."; return; } 77 | 78 | ebegin "Rebuilding ${squash_rebuild_dir}" 79 | ${sdr} -o${offset:-5} -f${squash_filesystem} ${squash_rebuild_dir} >${NULL} 2>&1 80 | eend ${?} 81 | } 82 | 83 | restart() 84 | { 85 | stop 86 | start 87 | local dir 88 | for dir in ${squash_sysdir}; do 89 | squash_remount "${dir}" "rw" 90 | done 91 | return 0 92 | } 93 | 94 | squash_mount() 95 | { 96 | local DIR message mnt_opts 97 | DIR="${1}/${2#/}" dir="/${2#/}" 98 | grep -qs ${squash_filesystem}:${dir} /proc/mounts && return 99 | [ -f ${DIR}.squashfs ] || return 100 | 101 | case "${squash_filesystem}" in 102 | (aufs) 103 | mkdir -p -m 0755 ${DIR}/rr ${DIR}/rw 104 | mnt_opts="nodev,udba=reval,br:${DIR}/rw:${DIR}/rr" 105 | message=AUFS;; 106 | (overlay) 107 | mkdir -p -m 0755 ${DIR}/rr ${DIR}/up ${DIR}/wk 108 | mnt_opts="nodev,upperdir=${DIR}/up,lowerdir=${DIR}/rr,workdir=${DIR}/wk" 109 | message=OverlayFS;; 110 | esac 111 | 112 | ebegin "Mounting ${squash_filesystem}:${dir}" 113 | if ! mountinfo -q ${DIR}/rr; then 114 | ${mount} -t squashfs -o nodev,ro ${DIR}.squashfs ${DIR}/rr \ 115 | >${NULL} 2>&1 || { eend 1 SquashFS; return 1; } 116 | fi 117 | ${mount} -t ${squash_filesystem} -o ${mnt_opts} \ 118 | ${squash_filesystem}:${dir} ${dir} >${NULL} 2>&1 119 | eend "${?}" "${message}" 120 | } 121 | 122 | squash_umount() 123 | { 124 | local DIR mnt_opts message 125 | DIR="${1}/${2#/}" dir="/${2#/}" 126 | grep -qs ${squash_filesystem}:${dir} /proc/mounts || return 127 | 128 | if [ "${RC_UNAME}" = "Linux" ]; then 129 | mnt_opts="-O no_netdev" 130 | fi 131 | case "${squash_filesystem}" in 132 | (aufs) auplink ${dir} flush >${NULL} 2>&1 133 | message=AUFS;; 134 | (*) message=OverlayFS;; 135 | esac 136 | ebegin "Umounting ${squash_filesystem}:${dir}" 137 | ${umount} -l ${mnt_opts} ${squash_filesystem}:${dir} >${NULL} 2>&1 || 138 | { eend 1 ${message}; return 1; } 139 | ${umount} -l ${mnt_opts} ${DIR}/rr >${NULL} 2>&1 140 | eend "${?}" SquashFS 141 | } 142 | 143 | squash_remount() 144 | { 145 | local message mnt_opts="${2:-ro}" 146 | dir="/${1#/}" 147 | if [ "${mnt_opts}" = "ro" ]; then 148 | message=read-only 149 | else 150 | message=read-write 151 | fi 152 | grep -qs ${squash_filesystem}:${dir} /proc/mounts || return 153 | ebegin "Remounting ${squash_filesystem}:${dir} (${message})" 154 | ${mount} -o remount,${mnt_opts} ${squash_filesystem}:${dir} >${NULL} 2>&1 155 | eend "${?}" 156 | } 157 | 158 | # 159 | # vim:fenc=utf-8:ft=gentoo-init-d:ci:pi:sts=0:sw=4:ts=4: 160 | # 161 | -------------------------------------------------------------------------------- /mkinitramfs-ll.conf.in-sh: -------------------------------------------------------------------------------- 1 | # 2 | # Header: mkinitramfs-ll/mkinitramfs-ll.conf, 2015/05/28 Exp 3 | # 4 | # To enable default options e.g. {all,luks,lvm,toi,gpg,squashd} use 'option_luks=:', 5 | # 'option_lvm=:' etc. 6 | # 7 | # module_ a list of kernel module group, nls_cp437,vfat should be putted 8 | # to remdev group for vfat remdev users for example. 9 | # 10 | # Support kernel module dependencies, so no need to stuff modules groups; 11 | # Support kernel module groups in the boot group e.g. kms group. 12 | # 13 | # Support an improved regular expression kernel module name, e.g. appending 14 | # `serpent' to module_dm_crypt would rightly add serpent_generic and 15 | # architecture specific modules serpent-{avx{2,-x86_64},sse-x86_64}. 16 | # 17 | # Support extended kernel module group that can be appended directly to 18 | # `module' kernel cmdline argument: module=group; 19 | # just create module_ grooups and then append them to module_group. 20 | # 21 | # Every item if built as module will be included or nothing if not, so one 22 | # can leave as is or add a few items. 23 | # 24 | 25 | # 26 | # Default kernel module groups (WARN: Replace `_' by `-' in `module_group', 27 | # e.g `module_dm_crypt' contains the list of `dm-crypt' group, so, append 28 | # `dm-crypt' group name to `module_group'.) 29 | # User groups are also supported e.g. kms module group 30 | # 31 | module_boot="kms crc32 btrfs ext2 ext3 ext4 jfs xfs thunderbolt-net thunderbolt intel-wmi intel-hid hid-generic i2c-hid i2c-isch i2c-i801 i2c-smbus spi-pxa2xx-platform spi-pxa2xx-pci intel-lpss-pci intel-lpss-acpi pwm-lpss pwm-lpss-platform" 32 | module_boot="kms ext2 ext3 ext4" 33 | module_device_mapper="dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror" 34 | module_dm_crypt="aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent" 35 | module_dm_raid="dm-raid dm-mirror dm-multipath dm-snapshot" 36 | module_gpg="cast5" 37 | module_kms="i915 nouveau radeon" 38 | module_raid="raid0 raid10 raid1 raid456" 39 | module_remdev="nls_cp437 vfat" 40 | module_squashd="aufs overlay squashfs" 41 | module_swsusp="" 42 | module_tuxonice="tuxonice_swap tuxonice_userui tuxonice_file" 43 | module_zfs="zlib_deflate spl zavl zcommon znvpair zunicode zfs" 44 | module_zram="zram" 45 | module_bcache="bcache" 46 | module_btrfs="btrfs" 47 | 48 | firmwares="${firmwares} iwlwifi-7260" 49 | 50 | # 51 | # A list of kernel modules to include in the initramfs that can be loaded 52 | # at boot time if passed to *module* kernel cmdline argument 53 | # 54 | modules="boot kms remdev swsusp uvesafb" 55 | 56 | # 57 | # Default kernel module group included in the initramfs 58 | # 59 | module_group="boot kms remdev swsusp" 60 | 61 | # 62 | # A list of binaries to include into the initramfs, library 63 | # dependencies will be copied over using `$(ldd /path/to/bin)'. 64 | # 65 | bins="blkid v86d" 66 | 67 | # 68 | # bin_ are list of binaries to include if hook or script 69 | # is included in the initramfs 70 | # 71 | bin_zfs="zfs zpool mount.zfs zdb fsck.zfs" 72 | bin_btrfs="btrfs btrfsck fsck.btrfs" 73 | 74 | # 75 | # A colon separated list of console fonts to include into the initramfs 76 | # 77 | fonts="ter-g12n ter-g14n ter-112n ter-v12n" 78 | 79 | # 80 | # A colon separated list of keymap to include in the initramfs 81 | # 82 | keymaps="azerty dvorak unicode" 83 | 84 | # 85 | # Enable LVM[2] 86 | # 87 | #option_lvm=: 88 | # 89 | # Enable dm-crypt LUKS 90 | # 91 | #option_luks=: 92 | # 93 | # Enable extra flesystem 94 | # 95 | #hooks="${hooks} zfs zram btrfs" 96 | 97 | # 98 | # This variable keeps *environment* variables or kernel cmdline arguments; 99 | # To disable default kernel cmdline, append `env=0' 100 | # or case insensitive Disable|False|Off|No for that matter. 101 | # 102 | # Note, however, this will disbale everything. Or else, a colon separated 103 | # list can be used instead e.g. `env=:root:'; (NOTE: begin/end with a colon `:'). 104 | # 105 | env="${MIR_EXTRA_ENV}" 106 | # Disable applets/binaries checking 107 | env="${env} CHECK_ENV=false" 108 | # Set a default rootfs mount option 109 | #env="${env} rootflags=user_xattr" 110 | # Set up root options with fsck disabled 111 | #env="${env} root=root-sda2 rootfs=ext4:no" 112 | # Set up root key mode (dm-crypt LUKS) 113 | #env="${env} luks=pwd" 114 | # Setup init variable if necessary 115 | #env="${env} init=/sbin/runit-init" 116 | # Set up extra option (squash(ed) directory) 117 | #env="${env} squashd=:aufs:+LOCAL:opt" 118 | # Set this variable to keep some system file systems mounted 119 | #env="${env} SYSFS=/run:/sys:/dev:/proc" 120 | 121 | # 122 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 123 | # 124 | -------------------------------------------------------------------------------- /mkinitramfs-ll.conf.in: -------------------------------------------------------------------------------- 1 | # 2 | # Header: mkinitramfs-ll/mkinitramfs-ll.conf, 2015/05/28 Exp 3 | # 4 | # opts an associative array which hold pretty much every single option, 5 | # so one could assign default values for pretty much everything: opts[-arg] 6 | # being an options or a command line switch. opts[-arg] is a colon ':' 7 | # separated list for each option or arg that is a list. 8 | # 9 | # To enable default options e.g. {all,hook,luks,lvm,toi,gpg,squashd,...} use 10 | # 'opts[-luks]=:', 'opts[-lvm]=:', opts[-hook]+=:zram:zfs etc. 11 | # 12 | # opts[-module-] a list of kernel module group, nls_cp437:vfat should be putted 13 | # to remdev group for vfat remdev users for example. 14 | # 15 | # Support kernel module dependencies, so no need to stuff modules groups; 16 | # Support kernel module groups in the boot group e.g. kms group. 17 | # 18 | # Support an improved regular expression kernel module name, e.g. appending 19 | # `serpent' to opts[-module-dm-crypt] would rightly add serpent_generic and 20 | # architecture specific modules serpent-{avx{2,-x86_64},sse-x86_64}. 21 | # 22 | # Support extended kernel module group that can be appended directly to 23 | # `module' kernel cmdline argument: module=group; 24 | # just create opts[-module-] grooups and then append them to 25 | # opts[-module-group]. 26 | # 27 | # Every item if built as module will be included or nothing if not, so one 28 | # can leave as is or add a few items. 29 | # 30 | 31 | # 32 | # Default kernel module groups: 33 | # User groups are also supported e.g. kms module group 34 | # 35 | opts[-module-boot]+=:kms:crc32:btrfs:ext2:ext3:ext4:jfs:xfs:thunderbolt-net:thunderbolt:intel-wmi:intel-hid:hid-generic:i2c-hid:i2c-isch:i2c-i801:i2c-smbus:spi-pxa2xx-platform:spi-pxa2xx-pci:intel-lpss-pci:intel-lpss-acpi:pwm-lpss:pwm-lpss-platform: 36 | opts[-module-device-mapper]+=:dm-thin-pool:dm-mirror:dm-cache:dm-multipath:dm-snapshot 37 | opts[-module-dm-crypt]+=aes:dm-crypt:sha256:sha512:wp512:ecb:lrw:xts:twofish:serpent 38 | opts[-module-dm-raid]+=:dm-raid:dm-mirror:dm-multipath:dm-snapshot 39 | opts[-module-gpg]+=:cast5 40 | opts[-module-kms]+=:i915:nouveau:radeon 41 | opts[-module-raid]+=:raid0:raid10:raid1:raid456 42 | opts[-module-remdev]+=:nls_cp437:vfat 43 | opts[-module-squashd]+=:aufs:overlay:squashfs 44 | opts[-module-swsusp]+= 45 | opts[-module-tuxonice]+=:tuxonice_swap:tuxonice_userui:tuxonice_file 46 | opts[-module-zfs]+=:zlib_deflate:spl:zavl:zcommon:znvpair:zunicode:zfs 47 | opts[-module-zram]+=:zram 48 | opts[-module-bcache]+=:bcache 49 | opts[-module-btrfs]+=:btrfs 50 | 51 | opts[-firmware]=:iwlwifi-7260 52 | # 53 | # A list of kernel modules to include in the initramfs that can be loaded 54 | # at boot time if passed to *module* kernel cmdline argument 55 | # 56 | opts[-module]+=:boot:kms:remdev:uvesafb 57 | 58 | # 59 | # Default kernel module group included in the initramfs 60 | # 61 | opts[-module-group]+=:boot:kms:remdev:swsusp 62 | 63 | # 64 | # A list of binaries to include into the initramfs, library 65 | # dependencies will be copied over using `$(ldd /path/to/bin)'. 66 | # 67 | opts[-bin]+=:blkid:v86d 68 | 69 | # 70 | # opts[-bin-] are list of binaries to include if hook or script 71 | # is included in the initramfs 72 | # 73 | opts[-bin-zfs]=zfs:zpool:mount.zfs:zdb:fsck.zfs 74 | opts[-bin-btrfs]=btrfs:btrfsck:fsck.btrfs 75 | 76 | # 77 | # A colon separated list of console fonts to include into the initramfs 78 | # 79 | opts[-font]+=:ter-g12n:ter-g14n:ter-112n:ter-v12n 80 | 81 | # 82 | # A colon separated list of keymap to include in the initramfs 83 | # 84 | opts[-keymap]+=:azerty:dvorak:unicode 85 | 86 | # 87 | # Enable LVM[2] 88 | # 89 | #opts[-lvm]=: 90 | # 91 | # Enable dm-crypt LUKS 92 | # 93 | #opts[-luks]=: 94 | # 95 | # Enable extra flesystem 96 | # 97 | #opts[-hook]=zfs:zram:btrfs 98 | 99 | # 100 | # An array holding *environment* variables or kernel cmdline arguments, 101 | # To disable default kernel cmdline, append `env=0' 102 | # or case insensitive disable|false|off|no for that matter. 103 | # 104 | # Note, however, this will disbale everything. Or else, a colon separated 105 | # list can be used instead e.g. `env=:root:'; (NOTE: start/end with a colon `:'). 106 | # 107 | env=( 108 | ${MIR_EXTRA_ENV} 109 | # Disable applets/binaries checking 110 | 'CHECK_ENV=false' 111 | # Set a default rootfs mount option 112 | #'rootflags=user_xattr' 113 | # Set up root options with fsck enabled 114 | #'root=root-sda2' 'rootfs=ext4:no' 115 | # Set up root key mode (dm-crypt LUKS) 116 | #'luks=pwd' 117 | # Setup init variable if necessary 118 | #'init=/sbin/runit-init' 119 | # Set up extra option (squash(ed) directory) 120 | #'squashd=:aufs:+LOCAL:opt' 121 | # Set this variable to keep some system file systems mounted 122 | #'SYSFS=/run:/sys:/dev:/proc' 123 | ) 124 | 125 | # 126 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 127 | # 128 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PACKAGE = mkinitramfs-ll 2 | VERSION = $(shell sed -nre '3s/(.*):/\1/p' ChangeLog) 3 | 4 | PREFIX = /usr/local 5 | SBINDIR = $(PREFIX)/sbin 6 | SYSCONFDIR = /etc 7 | SVCCONFDIR = $(SYSCONFDIR)/conf.d 8 | SVCINITDIR = $(SYSCONFDIR)/init.d 9 | DATADIR = $(PREFIX)/share 10 | DOCDIR = $(DATADIR)/doc 11 | MANDIR = $(DATADIR)/man 12 | 13 | INSTALL = install 14 | install_SCRIPT = $(INSTALL) -m 755 15 | install_DATA = $(INSTALL) -m 644 16 | MKDIR_P = mkdir -p 17 | 18 | dist_EXTRA = \ 19 | AUTHORS \ 20 | BUGS \ 21 | COPYING \ 22 | README.md \ 23 | ChangeLog 24 | dist_HOOKS = \ 25 | bcache \ 26 | disable-bcache \ 27 | btrfs \ 28 | fb-video \ 29 | zfs \ 30 | mkswap-zfs\ 31 | zram 32 | dist_COMMON = \ 33 | usr/etc/mdev.conf \ 34 | usr/etc/group \ 35 | usr/etc/modprobe.d/zfs.conf \ 36 | scripts/minimal.applets \ 37 | usr/lib/$(PACKAGE)/functions \ 38 | usr/lib/$(PACKAGE)/helpers \ 39 | usr/root/.gnupg/gpg.conf \ 40 | usr/share/gnupg/options.skel 41 | dist_SCRIPTS= \ 42 | init \ 43 | scripts/busybox.sh \ 44 | scripts/gnupg.sh \ 45 | scripts/suspend \ 46 | scripts/xcpio \ 47 | usr/lib/mdev/ide_links \ 48 | usr/lib/mdev/dm_link 49 | DISTFILES = $(dist_COMMON) $(dist_SCRIPTS) 50 | .SECONDEXPANSION: 51 | base_DIRS = $(SBINDIR) $(SYSCONFDIR) \ 52 | $(MANDIR)/man5 $(MANDIR)/man8 \ 53 | $(DATADIR)/$(PACKAGE) $(DOCDIR)/$(PACKAGE)-$(VERSION) 54 | keep_DIRS = \ 55 | hooks scripts \ 56 | usr/bin usr/sbin \ 57 | usr/etc/$(PACKAGE) \ 58 | usr/etc/splash usr/etc/modprobe.d \ 59 | usr/lib/mdev usr/lib/$(PACKAGE) \ 60 | usr/root/.gnupg usr/share/gnupg \ 61 | usr/share/consolefonts \ 62 | usr/share/keymaps 63 | DISTDIRS = $(base_DIRS) $(keep_DIRS) 64 | 65 | .FORCE: 66 | 67 | all: 68 | 69 | install-all: install install-services install-sh-scripts 70 | install: install-dir install-dist 71 | install-dist: $(DISTFILES) install-doc install-hooks 72 | sed -e 's:\$${PWD}.*/usr:$(DATADIR)/$(PACKAGE)/usr:g' \ 73 | -i $(DESTDIR)$(DATADIR)/$(PACKAGE)/scripts/*.sh 74 | install-dir : $(keep_DIRS) 75 | $(MKDIR_P) $(base_DIRS:%=$(DESTDIR)%) 76 | install-doc : install-extra 77 | for man in man5/$(PACKAGE).5 man8/$(PACKAGE).8; do \ 78 | sed -e 's|@SYSCONFDIR@|$(SYSCONFDIR)|g' -e 's|@DATADIR@|$(DATADIR)|g' \ 79 | $${man#*/} >$(DESTDIR)$(MANDIR)/$${man}; \ 80 | done 81 | install-services: install-squashdir-svc install-zram-svc install-tmpdir-svc 82 | 83 | $(dist_COMMON): .FORCE 84 | $(install_DATA) $@ $(DESTDIR)$(DATADIR)/$(PACKAGE)/$@ 85 | install-extra: 86 | $(install_DATA) $(dist_EXTRA) $(DESTDIR)$(DOCDIR)/$(PACKAGE)-$(VERSION) 87 | install-hooks: 88 | $(install_DATA) $(dist_HOOKS:%=hooks/%) $(DESTDIR)$(DATADIR)/$(PACKAGE)/hooks 89 | $(dist_SCRIPTS): .FORCE 90 | $(install_SCRIPT) $@ $(DESTDIR)$(DATADIR)/$(PACKAGE)/$@ 91 | $(keep_DIRS): .FORCE 92 | $(MKDIR_P) $(DESTDIR)$(DATADIR)/$(PACKAGE)/$@ 93 | echo > $(DESTDIR)$(DATADIR)/$(PACKAGE)/$@/.keep-$(@F)-dir 94 | 95 | install-%-scripts: 96 | $(install_SCRIPT) $(PACKAGE).$* svc/sdr.$* $(DESTDIR)$(SBINDIR) 97 | if test $* = sh; then \ 98 | $(install_DATA) $(PACKAGE).conf.in-sh $(DESTDIR)$(SYSCONFDIR)/$(PACKAGE).conf; \ 99 | sed -e 's:\$${PWD}.*/usr:$(DATADIR)/\$${package}/usr:g' \ 100 | -e 's:\./\$${package}.conf:$(SYSCONFDIR)/\$${package}.conf:g' \ 101 | -i $(DESTDIR)$(SBINDIR)/$(PACKAGE).sh; \ 102 | else \ 103 | $(install_DATA) $(PACKAGE).conf.in $(DESTDIR)$(SYSCONFDIR)/$(PACKAGE).conf; \ 104 | sed -e 's:"\$${PWD}"/usr:$(DATADIR)/$${PKGINFO[name]}/usr:g' \ 105 | -e 's:"\$${PKGINFO\[name\]}".conf:$(SYSCONFDIR)/$${PKGINFO[name]}.conf:g' \ 106 | -i $(DESTDIR)$(SBINDIR)/$(PACKAGE).$*; \ 107 | fi 108 | ln -f -s $(PACKAGE).$* $(DESTDIR)$(SBINDIR)/mkinitramfs 109 | ln -f -s sdr.$* $(DESTDIR)$(SBINDIR)/sdr 110 | install-%-svc: 111 | $(MKDIR_P) $(DESTDIR)$(SVCCONFDIR) $(DESTDIR)$(SVCINITDIR) 112 | $(install_SCRIPT) svc/$*.initd $(DESTDIR)$(SVCINITDIR)/$* 113 | $(install_DATA) svc/$*.confd $(DESTDIR)$(SVCCONFDIR)/$* 114 | 115 | uninstall-all: uninstall uninstall-services uninstall-sh-scripts 116 | uninstall: uninstall-dist 117 | for dir in $(keep_DIRS); do \ 118 | rm -f $(DESTDIR)$(DATADIR)/$(PACKAGE)/$${dir}/.keep-*-dir; \ 119 | rmdir $(DESTDIR)$(DATADIR)/$(PACKAGE)/$${dir}; \ 120 | done 121 | -for dir in usr/etc usr/lib usr/root usr/share usr; do \ 122 | rmdir $(DESTDIR)$(DATADIR)/$(PACKAGE)/$${dir}; \ 123 | done 124 | -rmdir $(base_DIRS:%=$(DESTDIR)%) 125 | uninstall-dist: uninstall-doc 126 | rm -f $(dist_COMMON:%=$(DESTDIR)$(DATADIR)/$(PACKAGE)/%) \ 127 | $(dist_SCRIPTS:%=$(DESTDIR)$(DATADIR)/$(PACKAGE)/%) \ 128 | $(dist_HOOKS:%=$(DESTDIR)$(DATADIR)/$(PACKAGE)/hooks/%) 129 | uninstall-doc: 130 | rm -f $(DESTDIR)$(MANDIR)/man1/$(PACKAGE).1 \ 131 | $(DESTDIR)$(MANDIR)/man8/$(PACKAGE).8 \ 132 | $(dist_EXTRA:%=$(DESTDIR)$(DOCDIR)/$(PACKAGE)-$(VERSION)/%) 133 | uninstall-services: uninstall-squashdir-svc \ 134 | uninstall-zram-svc uninstall-tmpdir-svc 135 | uninstall-%-scripts: 136 | rm -f $(DESTDIR)$(SYSCONFDIR)/$(PACKAGE).conf \ 137 | $(DESTDIR)$(SBINDIR)/$(PACKAGE).$* \ 138 | $(DESTDIR)$(SBINDIR)/sdr.$* \ 139 | $(DESTDIR)$(SBINDIR)/mkinitramfs \ 140 | $(DESTDIR)$(SBINDIR)/sdr 141 | uninstall-%-svc: 142 | rm -f $(DESTDIR)$(SVCCONFDIR)/$* $(DESTDIR)$(SVCINITDIR)/$* 143 | -rmdir $(DESTDIR)$(SVCCONFDIR) $(DESTDIR)$(SVCINITDIR) 144 | 145 | .PHONY: clean 146 | 147 | clean: 148 | 149 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Header: mkinitramfs-ll/README.md,v 0.21.0 2015/05/28 Exp 2 | 3 | > A lightweight, modular and yet powerfull initramfs generating tool 4 | with RAID (ATA RAID & SOFTWARE RAID), dm-crypt LUKS, LVM(2), BTRFS, ZFS, 5 | TuxOnIce/SwSusp hibernation, AUFS|OverlayFS+SquashFS, ZRAM and bCache support 6 | 7 | INTRODUCTION 8 | ----------- 9 | 10 | **BIG FAT NOTE:** 11 | 12 | **SUPPORTED BLOCK DEVICE STACK: [RAID]+[LUKS]+[LVM] or [LUKS]+[BTRFS|ZFS]** 13 | 14 | It is possible to add ZFS on the first stack variant, but it does not make any 15 | sense and expect horrible performance with such a mix bag. And this variant is 16 | not implemented although it could be done easily. 17 | (The same goes for BTRFS support (require >=btrfs-progs-3.12)) 18 | 19 | The order of LUKS/LVM and LUKS/RAID can be changed, that is, use any on top of 20 | the other. 21 | 22 | 23 | GETTING AN INTRAMFS QUICKLY AND READY 24 | ------------------------------------- 25 | 26 | An initramfs can be made in matter of secondes with locales settings 27 | (keymap and consolefont) if a busybox binary is available. 28 | media-fonts/terminus-font is recomanded to get a nice and neat interface 29 | in early boot up. 30 | 31 | app-crypt/gnupg-1.4.x is mandatory for GnuPG support (a binary along with 32 | its options.skel file is required.) 33 | 34 | And then run `mkinitramfs-ll.$SHELL -a -f$FONT -y$LINGUAS` to build an initramfs. 35 | The appended font and keymap will be the default if there is no *keymap* kernel 36 | cmdline argument. 37 | 38 | Of course, one can append extra fonts and keymaps with `-fter-g12n -yfr-latin1` 39 | etc. and the `-a|--all` option depend on `mkinitramfs-ll.conf` 40 | so one can put many sane default values there. 41 | 42 | One can get more info on the scripts by running `$SCRIPT -?|-h|--help` 43 | 44 | **EFI STUB Kernel NOTE** 45 | 46 | If using a kernel stub with EFI boot loader, build an uncompressed 47 | initramfs, by passing `--compressor=none` command line to mkinitramfs-ll.$SHELL, 48 | and leave the compression to the kernel. Second, set up `env` variable in the 49 | configuration file with the appropriate kernel command line. This will ensure a 50 | more reliable and consistent kernel command line across various boot loaders. 51 | 52 | DOCUMENTATION 53 | ------------- 54 | 55 | See mkinitramfs-ll(5) for more info on kernel command line options 56 | 57 | See mkinitramfs-ll(8) for more info on the build script options 58 | 59 | INSTALLATION 60 | ------------ 61 | 62 | `make DESTDIR=/tmp PREFIX=/usr/local install` to install initramfs files hierarchy; 63 | `install-{,ba,z}sh-scripts` for POSIX, Bourne Again or Z shell build script; 64 | `install-{squashd,tmpdir,zram}-svc` for extra init scripts service (refer to FILES 65 | sub-section); 66 | `install-all` for everything minus {ba,z}sh scripts... 67 | 68 | **WARING:** POSIX build script cannot be used with {ba,z}sh build script because of 69 | a configuration file mismatch (associative array usage.) Or else, a few quick 70 | edits would do the trick! 71 | 72 | COPYING 73 | ------- 74 | 75 | **BIG FAT WARN:** 76 | 77 | **USE AT YOUR OWN RISK! EVERYTHING IS GIVEN "AS IS" (SEE COPYING FILE)** 78 | **Distributed under the 2-clause/new/simplified BSD License** 79 | 80 | FILES 81 | ----- 82 | ### /usr 83 | 84 | An image like directory with extra files required for the initramfs. 85 | Extra files (binaries along with library dependencies), user scripts, 86 | keymaps and fonts can be directly putted there. 87 | 88 | ### /scripts 89 | 90 | Some extra scripts are available there, notably {busybox,gpg}.{ba,z}sh for 91 | Gentoo Users. 92 | 93 | A suspend/hibernation script along with an initramfs utility (decompress 94 | and list) are available. 95 | 96 | ### /svc (service) 97 | 98 | Some init service files for OpenRC are available... Or else, grab *svc/sdr.$SHELL* 99 | instead of *svc/squashdir.{init,conf}d* and [tmpdirs.{sh|pl|py}][2] instead of both 100 | *svc/tmpdir.{init,conf}d* and *svc/zram.{init,conf}d*. 101 | 102 | #### AUFS|OverlayFS+SquashFS 103 | 104 | An init service script along with a build script for squashed directory are 105 | available. Managing system wide directories is problematic, so put `usr' 106 | first (if squashded.) And this require a static busybox to function at all. 107 | 108 | #### ZRAM 109 | 110 | Two init service scripts are available, one that can be used to set up zram 111 | devices directly for space usage efficiency (compared to a regular tmpfs.) 112 | 113 | Another one, an optional client of zram, handles temporary directory with an 114 | optional saved state (tarball backup.) 115 | 116 | The later can be used on a tmpfs based device instead of zram, configuration 117 | edit is required (use zram by default.) 118 | 119 | CONTRIBUTORS 120 | ------------ 121 | 122 | Thanks to: 123 | 124 | Federico Zagarzazu (early init script with LUKS/Suspend2 support); 125 | Jan Matějka aka yaccz for his suggestions (debug...); 126 | Simon Buehler for debugging...; 127 | And others; 128 | 129 | GENTOO USERS NOTE 130 | ----------------- 131 | 132 | An [ebuild][1] for Gentoo users. 133 | 134 | Gentoo users can use provided scripts to build static busybox/gnupg. 135 | (See in /scripts directory for extra scripts.) 136 | 137 | `gnupg.sh` will build a binary in the current directory 138 | (with a USRDIR/bin/gpg and USRDIR/share/gnupg/options.skel) 139 | or else in DATADIR/mkiniramfs-ll directory if installed variant. 140 | The same goes for `busybox.sh' which build a static binary. 141 | 142 | [1]: https://gitlab.com/tokiclover/bar-overlay 143 | [2]: https://gitlab.com/tokiclover/browser-home-profile 144 | -------------------------------------------------------------------------------- /svc/sdr.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Header: mkinitramfs-ll/svc/sdr.sh Exp $ 4 | # $Author: (c) 2011-2015 -tclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.21.0 2015/05/28 12:33:03 Exp $ 7 | # 8 | 9 | name=sdr 10 | version=0.21.0 11 | NULL=/dev/null 12 | 13 | # @FUNCTION: Print help message 14 | usage() { 15 | cat <<-EOH 16 | ${name} version ${version} 17 | usage: ${0##*/} [OPTIONS] 18 | 19 | -f, --filesystem=aufs Set the merge-filesystem to use 20 | -q, --squash-root= Set root directory (default '/squash') 21 | -b, --block-size=131072 Set block size in bytes (default 128KB) 22 | -x, --busybox=busybox Static BusyBox to use (System Wide case) 23 | -c, --compressor=gzip Set compressor to use (default to lzo) 24 | -X, --exclude= Director-ies-y (list) to exlude from image 25 | -o, --offset=0 Offset to use when rebuilding (default 10%) 26 | -u, --update Update the underlying source directory 27 | -r, --remove Remove the underlying source directory 28 | -m, --mount Enable mount-only mode, no-(re)build 29 | -n, --no-mount Disable mount, (re-)build-only mode 30 | -M, --unmount Enable unmount-only mode, no-build 31 | -h, --help, -? Print this help message and exit 32 | EOH 33 | ${1:+exit $1} 34 | } 35 | 36 | [ ${#} = 0 ] && usage 1 37 | 38 | busybox= block_size= compressor= exclude= filesystem= keep_dir= mount_dir= 39 | squash_root= offset= 40 | opt="$(getopt \ 41 | -o \?b:c:f:o:Mmnhruq:X:x: \ 42 | -l block-size:,busybox:,compressor:,exclude:,filesystem:,offset,help \ 43 | -l mount,no-mount,squash-root:,remove,update,unmount \ 44 | -n "${name}" -s sh -- "${@}" || usage)" 45 | [ ${?} = 0 ] || exit 2 46 | eval set -- ${opt} 47 | 48 | while true; do 49 | case "${1}" in 50 | (-x|--busybox) shift; busybox="${1}";; 51 | (-X|--exclude) shift; exclude="${exlude} ${1}";; 52 | (-f|--filesystem) shift; filesystem="${1}";; 53 | (-b|--block-*) shift; block_size="${1}";; 54 | (-c|--compre*) shift; compressor="${1}";; 55 | (-q|--squash-root) shift; squash_root="${1}";; 56 | (-o|--offset) shift; offset="${1}";; 57 | (-n|--no-mount) mount_dir=0;; 58 | (-m|--mount) mount_dir=2;; 59 | (-M|--unmount) mount_dir=3;; 60 | (-u|--update) keep_dir=1;; 61 | (-r|--remove) keep_dir=0;; 62 | (--) shift; break;; 63 | (-h|--help|-?|*) usage 0;; 64 | esac 65 | shift 66 | done 67 | 68 | : ${usrdir:=${PWD}/usr} 69 | source "${usrdir}"/lib/mkinitramfs-ll/functions || exit 1 70 | eval_colors 71 | : ${squash_root:=/squash} 72 | : ${block_size:=131072} 73 | : ${busybox:=$(type -p busybox 2>${NULL})} 74 | : ${compressor:=lzo -Xcompression-level 1} 75 | : ${offset:=10} 76 | : ${mount_dir:=1} 77 | 78 | # 79 | # @FUNCTION: Print error message to stderr & exit 80 | # 81 | die() 82 | { 83 | local ret=${?}; error "${@}"; exit ${ret} 84 | } 85 | 86 | # @FUNCTION: Helper to mount squashed directory 87 | squash_mount() { 88 | local cp grep mv rm mount umount mkdir 89 | case "${dir}" in 90 | (/bin|/sbin|/lib32|/lib64) 91 | ldd ${busybox} >${NULL} 2>&1 && die "No static busybox binary found" 92 | cp ${busybox} /tmp && bb=/tmp/busybox || die 93 | cp="${bb} cp -a" mv="${bb} mv" rm="${bb} rm -fr" 94 | mount="${bb} mount" umount="${bb} umount" 95 | grep="${bb} grep" mkdir="${bb} mkdir -p -m 0755" 96 | ;; 97 | (*) 98 | cp="cp -a" grep=grep mv=mv rm="rm -fr" 99 | mount=mount umount=umount mkdir="mkdir -p -m 0755" 100 | ;; 101 | esac 102 | 103 | if ${grep} -q ${filesystem}:${dir} /proc/mounts; then 104 | case "${filesystem}" in 105 | (aufs) auplink ${dir} flush >${NULL} 2>&1;; 106 | esac 107 | ${umount} -l ${filesystem}:${dir} >${NULL} 2>&1 || 108 | die "Failed to umount aufs:${dir}" 109 | fi 110 | if ${grep} -q ${DIR}/rr /proc/mounts; then 111 | ${umount} -l ${DIR}/rr >${NULL} 2>&1 || 112 | die "Failed to umount ${DIR}.squashfs" 113 | fi 114 | [ "${mount_dir}" -gt 2 ] && return 115 | 116 | [ -e ${DIR}.squashfs -a -e ${DIR}.tmp.squashfs ] && 117 | ${rm} ${DIR}.squashfs && ${mv} ${DIR}.tmp.squashfs ${DIR}.squashfs 118 | case "${filesystem}" in 119 | (aufs) ${rm} ${DIR}/rw && ${mkdir} ${DIR}/rw || 120 | die "Failed to clean up ${DIR}/rw";; 121 | (overlay) ${rm} ${DIR}/up ${DIR}/wk && ${mkdir} ${DIR}/up ${DIR}/wk || 122 | die "Failed to clean up ${DIR}/{up,wk}";; 123 | esac 124 | ${mount} -t squashfs -o nodev,ro ${DIR}.squashfs ${DIR}/rr >${NULL} 2>&1 || 125 | die "Failed to mount ${DIR}.squashfs" 126 | 127 | if [ -n "${keep_dir}" ]; then 128 | ${rm} ${dir} && ${mkdir} ${dir} || 129 | die "Failed to remove ${dir}" 130 | fi 131 | case "${keep_dir}" in 132 | (1) ${rm} ${dir} && ${cp} ${DIR}/rr ${dir} || 133 | die "Failed to update ${dir}";; 134 | esac 135 | 136 | ${mount} -t ${filesystem} -o ${opt} \ 137 | ${filesystem}:${dir} ${dir} >${NULL} 2>&1 || 138 | die "Failed to mount ${filesystem}:${dir}" 139 | } 140 | # @FUNCTION: Helper to squash-directory 141 | squash_dir() { 142 | case "${filesystem}" in 143 | (aufs) 144 | opt=nodev,udba=reval,br:${DIR}/rw:${DIR}/rr 145 | mkdir -p -m 0755 ${DIR}/rr ${DIR}/rw;; 146 | (overlay) 147 | opt=nodev,upperdir=${DIR}/up,lowerdir=${DIR}/rr,workdir=${DIR}/wk 148 | mkdir -p -m 0755 ${DIR}/rr ${DIR}/up ${DIR}/wk;; 149 | esac 150 | [ "${?}" = 0 ] || die "Failed to create required directories" 151 | [ "${mount_dir}" -gt 1 ] && { squash_mount; return; } 152 | 153 | mksquashfs ${dir} ${DIR}.tmp.squashfs -b ${block_size} -comp ${compressor} \ 154 | ${exclude:+-wildcards -regex -e} ${exclude} || 155 | die "Failed to build ${dir}.squashfs image" 156 | echo -e "\e[1;36m>>>\e[0m Sucessfully build ${DIR}.tmp.squashfs" 157 | 158 | [ "${mount_dir}" = 1 ] && squash_mount 159 | } 160 | 161 | for mod in ${filesystem:-aufs overlay} squashfs; do 162 | grep -q ${mod} /proc/filesystems || modprobe ${mod} >${NULL} 2>&1 || 163 | case ${mod} in 164 | (aufs|overlay) error "Failed to load ${mod} module"; mount_dir=0;; 165 | (squashfs) die "Failed to load ${mod} module";; 166 | esac 167 | case "${mod}" in 168 | (aufs|overlay) filesystem="${mod}" 169 | case "${mod}" in 170 | (aufs) RW=rw;; 171 | (ove*) RW=up;; 172 | esac 173 | break;; 174 | esac 175 | done 176 | 177 | for dir in ${*}; do 178 | DIR="/${squash_root#/}/${dir#/}" dir="/${dir#/}" 179 | if [ -e ${DIR}.squashfs ]; then 180 | case "${mount_dir}" in 181 | (3) echo -e "\e[1;34m>>>\e[0m Umounting ${dir}..." 182 | squash_dir; continue;; 183 | (2) echo -e "\e[1;35m>>>\e[0m Mounting ${dir}..." 184 | squash_dir; continue;; 185 | esac 186 | if [ ${offset} != 0 ]; then 187 | rr=$(du -sk ${DIR}/rr | awk '{print $1}') 188 | rw=$(du -sk ${DIR}/${RW} | awk '{print $1}') 189 | if [ $((${rw} * 100 / ${rr})) -lt ${offset} ]; then 190 | echo -e "\e[1;31m>>>\e[0m Skiping ${dir}... or use -o option" 191 | else 192 | echo -e "\e[1;32m>>>\e[0m Updating squashed ${dir}..." 193 | squash_dir 194 | fi 195 | else 196 | echo -e "\e[1;32m>>>\e[0m Updating squashed ${dir}..." 197 | squash_dir 198 | fi 199 | else 200 | echo -e "\e[1;32m>>>\e[0m Building squashed ${dir}..." 201 | squash_dir 202 | fi 203 | end "${?}" 204 | done 205 | 206 | [ -x "${bb}" ] && rm -f "${bb}" 207 | 208 | unset DIR RW dir exclude filesystem rr rw opt mount_dir squash_root 209 | 210 | # 211 | # vim:fenc=utf-8:ci:pi:sts=0:sw=4:ts=4: 212 | # 213 | -------------------------------------------------------------------------------- /mkinitramfs-ll.8: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" CopyLeft (c) 2015 -tclover 3 | .\" 4 | .\" Distributed under the terms of the 2-clause BSD License as 5 | .\" stated in the COPYING file that comes with the source files 6 | .\" 7 | .pc 8 | .TH MKINITRAMFS-LL 8 "2015-05-28" "0.21.0" "System Manager's Manual" 9 | .SH NAME 10 | mkinitramfs-ll \- tool for building initramfs 11 | .SH DESCRIPTION 12 | .B mkinitramfs-ll 13 | is an initramfs building script. It requires 14 | .IR mkinitramfs-ll.conf 15 | configuration file and the associated 16 | `\fIinit\fR' script file and `\fIusr\fR' (USRDIR) 17 | directory to complete the task. Those two requirements are not 18 | .IR scrictly 19 | necessary, but are 20 | .IR necessary 21 | to build a 22 | .IR functionnal 23 | initramfs. 24 | 25 | It also require `/lib/modules/$KV' kernel object directory along with its 26 | `modules.dep' file, or else, no kernel module would be added. Fonts should 27 | be available in `/usr/share/consolefonts'; Keymaps in `/usr/share/keymaps'; 28 | splash Themes in `/etc/splash'; Firmwares in `/lib/firmware'; Binaries in `$PATH'; 29 | Or else, use full path to file instead. 30 | 31 | Aything can be bundled directly in USRDIR for convenience for the end user. 32 | However, it's useless to waste disk space if the files are available in a live system. 33 | Editing the configuration file should suffice in most cases. 34 | 35 | If executed without arguments, an initramfs would be build for the current kernel 36 | with the default options defined in the configuration file. 37 | See the configuration file for more info. 38 | .SH SYNOPSIS 39 | .br 40 | .B mkinitramfs-ll 41 | .RB [\| OPTIONS \| ] 42 | 43 | .br 44 | .B mkinitramfs-ll 45 | .RB [\| \-a|\-\-all \|] 46 | .RB [\| \-f|\-\-font=REGEX \|]\|] 47 | .RB [\| \-F|\-\-firmware=REGEX \|]\|] 48 | .RB [\| \-k|\-\-kernel-version=VERSION \|] 49 | .RB [\| \-c|\-\-compressor=COMP \|] 50 | .RB [\| \-L|\-\-luks \] 51 | .RB [\| \-l|\-\-lvm \] 52 | .RB [\| \-b|\-\-bin=BINS \|]\|] 53 | .RB [\| \-d|\-\-usrdir=DIRECTORY \|] 54 | .RB [\| \-g|\-\-gpg \|] 55 | .RB [\| \-p|\-\-prefix=initrd- \|] 56 | .RB [\| \-H|\-\-hook=REGEX \|] 57 | .RB [\| \-m|\-\-module=REGEX \|] 58 | .RB [\| \-\-module-tuxonice=REGEX \|] 59 | .RB [\| \-\-module-remdev=REGEX \|] 60 | .RB [\| \-\-module-squashd=REGEX \|] 61 | .RB [\| \-\-module-gpg=REGEX \|] 62 | .RB [\| \-\-module-boot=REGEX \|] 63 | .RB [\| \-s|\-\-splash=THEMES \|] 64 | .RB [\| \-t|\-\-toi \|] 65 | .RB [\| \-q|\-\-squashd \|] 66 | .RB [\| \-r|\-\-rebuild \|] 67 | .RB [\| \-y|\-\-keymap=REGEX \|] 68 | .RB [\| \-K|\-\-keep-tmpdir \|] 69 | 70 | .br 71 | .B mkinitramfs-ll 72 | .RB [\| \-?|\-h|\-\-help \|] 73 | 74 | The following conventions apply to 75 | .B SYNOPSIS 76 | section and can be applied to the command line arguments. 77 | .TS 78 | tab (@); 79 | l lx. 80 | \fIitalic text\fR@T{ 81 | Replace with appropriate argument. 82 | T} 83 | [\|\fB\-short\fR|\fB\-\-long\fR\|]@T{ 84 | Any or all argument within [ ] are optional; and short or long option can be used. 85 | T} 86 | \fIREGEX\fR@T{ 87 | Replace regex with a regular expression, matching regex will be performed. 88 | T} 89 | \fBUSRDIR\fR@T{ 90 | Refer to `usr' directory (in `/' of the source files or DATADIR/mkinitramfs-ll/usr) 91 | T} 92 | .TE 93 | 94 | .SH OPTIONS 95 | .TP 96 | .B \-a|\-\-all 97 | Short variant or form of `\-\-font=: \-\-keymap=: \-\-luks \-\-lvm \-\-gpg 98 | \-\-hook='btrfs zfs zram' \-\-toi \-\-squashd' 99 | .TP 100 | .B \-f|\-\-font=\fIREGEX\fR 101 | Include a list of fonts either a full path or a regular expression name 102 | relative to `/usr/share/consolefonts' (or nothing would be included) 103 | .TP 104 | .B \-F|\-\-firmware=\fIREGEX\fR 105 | Include a list of firmware either a full path or a regular expression name 106 | relative to `/lib/firmware' (or nothing would be included) 107 | (`:' would add the whole firmware directoy) 108 | .TP 109 | .B \-k|\-\-kernel-version=\fIVERSION\fR 110 | Kernel version to use when building an initramfs 111 | .TP 112 | .B \-c|\-\-compressor=\fICOMP\fR 113 | Compressor to use for compression or `none' for uncompressed initramfs 114 | .TP 115 | .B \-L|\-\-luks 116 | Enable dm-crypt LUKS support (require cryptsetup) 117 | .TP 118 | .B \-l|\-\-lvm 119 | Enable device-mapper support (require lvm2) 120 | .TP 121 | .B \-b|\-\-bin=\fIBINS\fR 122 | Include a list of binary to the initramfs 123 | .TP 124 | .B \-d|\-\-usrdir=\fIDIRECTORY\fR 125 | Sse the appended directory as (USRDIR) `usr' directory 126 | .TP 127 | .B \-g|\-\-gpg 128 | Enable GnuPG support (require gnupg-1.4.x) 129 | .TP 130 | .B \-p|\-\-prefix=initrd- 131 | Use `initrd-' prefix to name initramfs 132 | .TP 133 | .B \-H|\-\-hook=\fIREGEX\fR 134 | Include alist of hooks or scripts to the initramfs 135 | .TP 136 | .B \-m|\-\-module=\fIREGEX\fR 137 | Include a list of kernel module to the initramfs 138 | .TP 139 | .B \-\-mtuxonice=\fIREGEX\fR 140 | Append a list of kernel module to tuxonice group 141 | .TP 142 | .B \-\-module-remdev=\fIREGEX\fR 143 | Append a list of kernel module to remdev group 144 | .TP 145 | .B \-\-module-squashd=\fIREGEX\fR 146 | Append a list of kernel module to remdev group 147 | .TP 148 | .B \-\-module-gpg=\fIREGEX\fR 149 | Append a list of kernel module to gpg group 150 | .TP 151 | .B \-\-module-boot=\fIREGEX\fR 152 | Append a list of kernel module to boot group 153 | .TP 154 | .B \-s|\-\-splash=\fITHEMES\fR 155 | Include a list of splash theme (require splashutils) 156 | .TP 157 | .B \-t|\-\-toi 158 | Enable TuxOnIce support (require tuxonice-userui for splash) 159 | .TP 160 | .B \-r|\-\-rebuild 161 | Rebuild an initramfs from an existant directory 162 | .TP 163 | .B \-y|\-\-keymap=\fIREGEX\fR 164 | .br 165 | Include a list of console keymap either a full path or regular expression name 166 | relative to `/usr/share/keymaps' (or nothing would be included) 167 | .TP 168 | .B \-K|\-\-keep-tmpdir 169 | Keep the temporary build directory 170 | .TP 171 | .B \-?|\-h|\-\-help 172 | Print the help message and exit 173 | .TP 174 | .B RAID (FAKE ATA & SOFWARE) 175 | Just append the appropriate binary, that is 176 | .IR dmraid 177 | or 178 | .IR mdadm 179 | with `-b|--bin' switch, 180 | to enable either dm-raid (fake ATA RAID) or mdadm software RAID 181 | .TP 182 | .B HOOKS & USER SCRIPTS 183 | Any hook or script should be in `USRDIR/../hooks', so `-H|--hook' switch would 184 | rightly add any appended hook (if any.) If module group and binary group 185 | are defined in the configuration file, the binaries, kernel modules and module 186 | group would be added. 187 | .TP 188 | .B BTRFS, BCACHE, ZFS & ZRAM SUPPORT 189 | To enable support for any of either bcache, btrfs, zfs & zram, 190 | append `-H|--hook' with a colon separated list of hooks (`-H$HOOKS'.) 191 | .SH EXAMPLES 192 | .TP 193 | .BI mkinitramfs-ll\ \-\-all\ \-\-font=ter-g12n\ \-\-keymap=fr\ \-\-firmware='nouveau/nv108\ iwlwifi-5000'\ \-\-kv=3.14.26-git 194 | Build an initramfs with 195 | .B GnuPG, LUKS, LVM2, 196 | .B BTRFS, ZFS, 197 | .B zram, AUFS|OverlayFS+SquashFS support for 198 | linux kernel 3.14.26-git; nVidia and iwlWIFI-5000 firmwares are included as well. 199 | .SH ENVIRONMENTS 200 | .TP 201 | .B MIR_EXTRA_ENV 202 | This environment variable would be used, if set, to generate the environment 203 | variables of 204 | .IR init 205 | script. 206 | .SH FILES 207 | .TP 208 | .RB @SYSCONFDIR@/mkinitramfs-ll.conf 209 | mkinitramfs-ll configuration file. 210 | .TP 211 | .RB @DATADIR@/mkinitramfs-ll/usr\ (USRDIR) 212 | mkinitramfs-ll `\fIusr\fR' directory that contains extra files 213 | (e.g. `\fIfunctions\fR' library file) for initramfs. 214 | .TP 215 | .RB USRDIR/../init 216 | (initramfs) init script 217 | .TP 218 | .RB USRDIR/../scripts/minimal.applets 219 | busybox minimal applet list (compatibility) 220 | .SH "SEE ALSO" 221 | .BR mkinitramfs-ll (1) 222 | .SH AUTHORS 223 | -tclover 224 | .\" 225 | .\" vim:fenc=utf-8:ft=groff:ci:pi:sts=2:sw=2:ts=2:expandtab: 226 | .\" 227 | -------------------------------------------------------------------------------- /svc/sdr.zsh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | # 3 | # $Header: mkinitramfs-ll/svc/sdr.bash Exp $ 4 | # $Author: (c) 2011-2015 -tclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.21.0 2015/05/28 12:33:03 Exp $ 7 | # 8 | 9 | typeset -A PKG 10 | PKG=( 11 | name sdr 12 | shell zsh 13 | version 0.21.0 14 | ) 15 | NULL=/dev/null 16 | 17 | # @FUNCTION: Print help message 18 | function usage { 19 | cat <<-EOH 20 | ${PKG[name]}.${PKG[shell]} version ${PKG[version]} 21 | usage: ${PKG[name]}.${PKG[shell]} [options] 22 | 23 | -f, --filesystem=aufs Set the merge-filesystem to use 24 | -q, --squash-root= Set root directory (default '/squash') 25 | -b, --block-size=131072 Set block size in bytes (default 128KB) 26 | -x, --busybox=busybox Static BusyBox to use (System Wide case) 27 | -c, --compressor=gzip Set compressor to use (default to lzo) 28 | -X, --exclude=: Director-ies-y (list) to exlude from image 29 | -o, --offset=0 Offset to use when rebuilding (default 10%) 30 | -u, --update Update the underlying source directory 31 | -r, --remove Remove the underlying source directory 32 | -m, --mount Enable mount-only mode, no-(re)build 33 | -n, --no-mount Disable mount, (re-)build-only mode 34 | -M, --unmount Enable unmount-only mode, no-build 35 | -h, --help, -? Print this help message and exit 36 | EOH 37 | exit $? 38 | } 39 | (( $# == 0 )) && usage 40 | 41 | typeset -A opts 42 | declare -a opt 43 | opt=( 44 | "-o" "?b:c:f:o:Mmnhruq:X:x:" 45 | "-l" "block-size:,busybox:,compressor:,exclude:,filesystem:,offset,help" 46 | "-l" "mount,no-mount,squash-root:,remove,update,unmount" 47 | "-n" ${PKG[name]}.${PKG[shell]} 48 | ) 49 | opt=($(getopt ${opt} -- ${argv} || usage)) 50 | eval set -- ${opt} 51 | while true; do 52 | case ${1} { 53 | (-x|--busybox) opts[-busybox]=${2}; shift;; 54 | (-b|--block-size) opts[-block-size]=${2}; shift;; 55 | (-f|--filesystem) opts[-filesystem]=${2}; shift;; 56 | (-q|--squash-root) opts[squash-root]=${2}; shift;; 57 | (-c|--compressor) opts[-compressor]=${2}; shift;; 58 | (-X|--exclude) opts[-exclude]+=:${2}; shift;; 59 | (-o|--offset) opts[-offset]=${2}; shift;; 60 | (-u|--update) opts[-keep-dir]=1;; 61 | (-r|--remove) opts[-keep-dir]=0;; 62 | (-n|--no-mount) opts[-mount]=0;; 63 | (-m|--mount) opts[-mount]=2;; 64 | (-M|--unmount) opts[-mount]=3;; 65 | (--) shift; break;; 66 | (-h|--help|-?|*) usage;; 67 | } 68 | shift 69 | done 70 | 71 | # @VARIABLE: Root directory (mount hierarchy) 72 | : ${opts[squash-root]:=/squash} 73 | # @VARIABLE: rw/rr branch ration (percent) 74 | : ${opts[-offset]:=10} 75 | # @VARIABLE: Block size of underlying SquashFS filesystem 76 | : ${opts[-block-size]:=131072} 77 | # @VARIABLE: Compression command 78 | : ${opts[-compressor]:=lzo -Xcompression-level 1} 79 | # @VARIABLE: Full path to a static busysbox (required for system update) 80 | : ${opts[-busybox]:=$commands[busyboxb]} 81 | : ${opts[-mount]:=1} 82 | 83 | # @FUNCTION: Print error message to stdout 84 | function error { 85 | print -P " %B%F{red}*%b %1x: %F{yellow}%U%I%u%f: $@" >&2 86 | } 87 | # @FUNCTION: Print info message to stdout 88 | function info { 89 | print -P " %B%F{green}*%b%f %1x: $@" 90 | } 91 | # @FUNCPTION: Fatal error heler 92 | function die { 93 | local ret=${?}; error "${@}"; exit ${ret} 94 | } 95 | 96 | setopt EXTENDED_GLOB NULL_GLOB 97 | 98 | # @FUNCTION: Helper to mount squashed directory 99 | function squash-mount { 100 | local cp grep mv rm mount umount mkdir 101 | case ${dir} { 102 | (/bin|/sbin|/lib32|/lib64) 103 | ldd ${opts[-busybox]} >${NULL} 2>&1 && die "No static busybox binary found" 104 | cp ${opts[-busybox]} /tmp && busybox=/tmp/busybox || die 105 | cp="${busybox} cp -a" mv="${busybox} mv" rm="${busybox} rm -fr" 106 | mount="${busybox} mount" umount="${busybox} umount" 107 | grep="${busybox} grep" mkdir="${busybox} mkdir -p -m 0755" 108 | ;; 109 | (*) 110 | cp="cp -a" grep=grep mv=mv rm="rm -fr" 111 | mount=mount umount=umount mkdir="mkdir -p -m 0755" 112 | ;; 113 | } 114 | 115 | if ${=grep} -q ${opts[-filesystem]}:${dir} /proc/mounts; then 116 | case ${opts[-filesystem]} { 117 | (aufs) auplink ${dir} flush >${NULL} 2>&1;; 118 | } 119 | ${=umount} -l ${opts[-filesystem]}:${dir} >${NULL} 2>&1 || 120 | die "Failed to umount ${opts[-filesystem]}:${dir}" 121 | fi 122 | if ${=grep} -q ${DIR}/rr /proc/mounts; then 123 | ${=umount} -l ${DIR}/rr >${NULL} 2>&1 || 124 | die "Failed to umount ${DIR}.squashfs" 125 | fi 126 | (( ${opts[-mount]} > 2 )) && return 127 | 128 | [[ -e ${DIR}.squashfs ]] && [[ -e ${DIR}.tmp.squashfs ]] && 129 | ${=rm} ${DIR}.squashfs && ${=mv} ${DIR}.tmp.squashfs ${DIR}.squashfs 130 | case ${opts[-filesystem]} { 131 | (aufs) ${=rm} ${DIR}/rw && ${=mkdir} ${DIR}/rw || 132 | die "Failed to clean up ${DIR}/rw";; 133 | (overlay) ${=rm} ${DIR}/{up,wk} && ${=mkdir} ${DIR}/{up,wk} || 134 | die "Failed to clean up ${DIR}/{up,wk}";; 135 | } 136 | ${=mount} -t squashfs -o nodev,ro ${DIR}.squashfs ${DIR}/rr >${NULL} 2>&1 || 137 | die "Failed to mount ${DIR}.squashfs" 138 | 139 | if (( ${+opts[-keep-dir]} )) { 140 | ${=rm} ${dir} && ${=mkdir} ${dir} || 141 | die "Failed to remove ${dir}" 142 | } 143 | case ${opts[-keep-dir]} { 144 | (1) ${=rm} ${dir} && ${=cp} ${DIR}/rr /${dir} || 145 | die "Failed to update ${dir}";; 146 | } 147 | 148 | ${mount} -t ${opts[-filesystem]} -o ${opt} \ 149 | ${opts[-filesystem]}:${dir} ${dir} >${NULL} 2>&1 || 150 | die "Failed to mount ${opts[-filesystem]}:${dir}" 151 | } 152 | # @FUNCTION: Helper to squash-directory 153 | function squash-dir { 154 | case ${opts[-filesystem]} { 155 | (aufs) 156 | opt=nodev,udba=reval,br:${DIR}/rw:${DIR}/rr 157 | mkdir -p -m 0755 ${DIR}/r{r,w};; 158 | (overlay) 159 | opt=nodev,upperdir=${DIR}/up,lowerdir=${DIR}/rr,workdir=${DIR}/wk 160 | mkdir -p -m 0755 ${DIR}/{rr,up,wk};; 161 | } 162 | (( ${?} == 0 )) || die "Failed to create required directories" 163 | (( ${opts[-mount]} > 1 )) && { squash-mount; return; } 164 | 165 | mksquashfs ${dir} ${DIR}.tmp.squashfs -b ${opts[-block-size]} -comp ${=opts[-compressor]} \ 166 | ${=opts[-exclude]:+-wildcards -regex -e ${(pws,:,)opts[-exclude]}} || 167 | die "Failed to build ${dir}.squashfs" 168 | print -P "%B%F{cyan}>>>%f%b Sucessfully ${DIR}.tmp.squashfs" 169 | 170 | (( ${opts[-mount]} )) && squash-mount 171 | } 172 | 173 | for mod (${=opts[-filesystem]:-aufs overlay} squashfs) { 174 | grep -q ${mod} /proc/filesystems || modprobe ${mod} >${NULL} 2>&1 || 175 | case ${mod} { 176 | (aufs|overlay) error "Failed to load ${mod} module"; opts[-mount]=0;; 177 | (squashfs) die "Failed to load ${mod} module";; 178 | } 179 | case ${mod} { 180 | (aufs|overlay) opts[-filesystem]=${mod} 181 | case ${mod} { 182 | (aufs) RW=rw;; 183 | (ove*) RW=up;; 184 | } 185 | break;; 186 | } 187 | } 188 | 189 | for dir (${(pws,:,)argv}) { 190 | DIR="/${opts[squash-root]#/}/${dir#/}" dir="/${dir#/}" 191 | if [[ -e ${DIR}.squashfs ]]; then 192 | case ${opts[-mount]} { 193 | (3) print -P "%B%F{blue}>>>%f%b Umounting ${dir}..." 194 | squash-dir; continue;; 195 | (2) print -P "%B%F{magenta}>>>%f%b Mounting ${dir}..." 196 | squash-dir; continue;; 197 | } 198 | if (( ${opts[-offset]} != 0 )); then 199 | rr=${$(du -sk ${DIR}/rr)[1]} 200 | rw=${$(du -sk ${DIR}/${RW})[1]} 201 | if (( (${rw}*100/${rr}) < ${opts[-offset]} )); then 202 | print -P "%B%F{red}>>>%f%b Skiping ${dir}... or use -o option" 203 | else 204 | print -P "%B%F{green}>>>%f%b Updating squashed ${dir}..." 205 | squash-dir 206 | fi 207 | else 208 | print -P "%B%F{green}>>>%f%b Updating squashed ${dir}..." 209 | squash-dir 210 | fi 211 | else 212 | print -P "%F{green}>>>%f Building squashed ${dir}..." 213 | squash-dir 214 | fi 215 | } 216 | 217 | [[ -x ${busybox} ]] && rm -f ${busybox} 218 | 219 | unset DIR RW dir opts rr rw 220 | 221 | # 222 | # vim:fenc=utf-8:ci:pi:sts=0:sw=4:ts=4: 223 | # 224 | -------------------------------------------------------------------------------- /svc/sdr.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # $Header: mkinitramfs-ll/svc/sdr.bash Exp $ 4 | # $Author: (c) 2011-2015 -tclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.21.0 2015/05/28 12:33:03 Exp $ 7 | # 8 | 9 | shopt -qs extglob 10 | typeset -A PKG 11 | PKG=( 12 | [name]=sdr 13 | [shell]=bash 14 | [version]=0.21.0 15 | ) 16 | NULL=/dev/null 17 | 18 | # @FUNCTION: Print help message 19 | function usage { 20 | cat <<-EOH 21 | ${PKG[name]}.${PKG[shell]} version ${PKG[version]} 22 | usage: ${PKG[name]}.${PKG[shell]} [options] 23 | 24 | -f, --filesystem=aufs Set the merge-filesystem to use 25 | -q, --squash-root= Set root directory (default '/squash') 26 | -b, --block-size=131072 Set block size in bytes (default 128KB) 27 | -x, --busybox=busybox Static BusyBox to use (System Wide case) 28 | -c, --compressor=gzip Set compressor to use (default to lzo) 29 | -X, --exclude=: Director-ies-y (list) to exlude from image 30 | -o, --offset=0 Offset to use when rebuilding (default 10%) 31 | -u, --update Update the underlying source directory 32 | -r, --remove Remove the underlying source directory 33 | -m, --mount Enable mount-only mode, no-(re)build 34 | -M, --no-mount Disable mount, (re-)build-only mode 35 | -U, --unmount Enable unmount-only mode, no-build 36 | -h, --help, -? Print this help message and exit 37 | EOH 38 | exit $? 39 | } 40 | (( $# == 0 )) && usage 41 | 42 | # @DESCRIPTION: declare if not declared while arsing options, 43 | # hold almost every single option/variable 44 | declare -A opts 45 | declare -a opt 46 | opt=( 47 | "-o" "?b:c:f:o:Mmnhruq:X:x:" 48 | "-l" "block-size:,busybox:,compressor:,exclude:,filesystem:,offset,help" 49 | "-l" "mount,no-mount,squash-root:,remove,update,unmount" 50 | "-n" "${PKG[name]}.${PKG[shell]}" 51 | "-s" "${PKG[shell]}" 52 | ) 53 | opt=($(getopt "${opt[@]}" -- "$@" || usage)) 54 | eval set -- "${opt[@]}" 55 | 56 | while true; do 57 | case "${1}" in 58 | (-x|--busybox) opts[-busybox]="${2}"; shift;; 59 | (-b|--block-size) opts[-block-size]="${2}"; shift;; 60 | (-f|--filesystem) opts[-filesystem]="${2}"; shift;; 61 | (-q|--squash-root) opts[squash-root]="${2}"; shift;; 62 | (-c|--compressor) opts[-compressor]="${2}"; shift;; 63 | (-X|--exclude) opts[-exclude]+=":${2}"; shift;; 64 | (-o|--offset) opts[-offset]="${2}"; shift;; 65 | (-u|--update) opts[-keep-dir]=1;; 66 | (-r|--remove) opts[-keep-dir]=0;; 67 | (-n|--no-mount) opts[-mount]=0;; 68 | (-m|--mount) opts[-mount]=2;; 69 | (-M|--unmount) opts[-mount]=3;; 70 | (--) shift; break;; 71 | (-h|--help|-?|*) usage;; 72 | esac 73 | shift 74 | done 75 | 76 | # @DESCRIPTION: print info message to stdout 77 | function info { 78 | echo -ne " \e[1;32m* \e[0m${PKG[name]}.${PKG[shell]}: $@\n" 79 | } 80 | # @FUNCTION: Print info message to stdout 81 | function error { 82 | echo -ne " \e[1;31m* \e[0m${PKG[name]}.${PKG[shell]}: $@\n" 83 | } 84 | # @FUNCPTION: Fatal error heler 85 | function die { 86 | local ret=${?}; error "${@}"; exit ${ret} 87 | } 88 | 89 | # @VARIABLE: Root directory (mount hierarchy) 90 | : ${opts[squash-root]:=/squash} 91 | : ${opts[-block-size]:=131072} 92 | # @VARIABLE: Full path to a static busysbox (required for system update) 93 | : ${opts[-busybox]:=$(type -p busybox 2>${NULL})} 94 | # @VARIABLE: Compression command 95 | : ${opts[-compressor]:=lzo -Xcompression-level 1} 96 | # @VARIABLE: rw/rr branch ration (percent) 97 | : ${opts[-offset]:=10} 98 | : ${opts[-mount]:=1} 99 | 100 | # @FUNCTION: Helper to mount squashed directory 101 | function squash-mount { 102 | local cp grep mv rm mount umount mkdir 103 | case "${dir}" in 104 | (/bin|/sbin|/lib32|/lib64) 105 | ldd ${busybox} >${NULL} 2>&1 && die "No static busybox binary found" 106 | cp ${busybox} /tmp && busybox=/tmp/busybox || die 107 | cp="${busybox} cp -a" mv="${busybox} mv" rm="${busybox} rm -fr" 108 | mount="${busybox} mount" umount="${busybox} umount" 109 | grep="${busybox} grep" mkdir="${busybox} mkdir -p -m 0755" 110 | ;; 111 | (*) 112 | cp="cp -a" grep=grep mv=mv rm="rm -fr" 113 | mount=mount umount=umount mkdir="mkdir -p -m 0755" 114 | ;; 115 | esac 116 | 117 | if ${grep} -q ${opts[-filesystem]}:${dir} /proc/mounts; then 118 | case "${opts[-filesystem]}" in 119 | (aufs) auplink ${dir} flush >${NULL} 2>&1;; 120 | esac 121 | ${umount} -l ${opts[-filesystem]}:${dir} >${NULL} 2>&1 || 122 | die "Failed to umount ${opts[-filesystem]}:${dir}" 123 | fi 124 | if ${grep} -q ${DIR}/rr /proc/mounts; then 125 | ${umount} -l ${DIR}/rr >${NULL} 2>&1 || 126 | die "Failed to umount ${DIR}.squashfs" 127 | fi 128 | (( ${opts[-mount]} > 2 )) && return 129 | 130 | [[ -e ${DIR}.squashfs ]] && [[ -e ${DIR}.tmp.squashfs ]] && 131 | ${rm} ${DIR}.squashfs && ${mv} ${DIR}.tmp.squashfs ${DIR}.squashfs 132 | case "${opts[-filesystem]}" in 133 | (aufs) ${rm} ${DIR}/rw && ${mkdir} ${DIR}/rw || 134 | die "Failed to clean up ${DIR}/rw";; 135 | (overlay) ${rm} ${DIR}/{up,wk} && ${mkdir} ${DIR}/{up,wk} || 136 | die "Failed to clean up ${DIR}/{up,wk}";; 137 | esac 138 | ${mount} -t squashfs -o nodev,ro ${DIR}.squashfs ${DIR}/rr >${NULL} 2>&1 || 139 | die "Failed to mount ${DIR}.squashfs" 140 | 141 | if [[ "${opts[-keep-dir]}" ]]; then 142 | ${rm} ${dir} && ${mkdir} ${dir} || 143 | die "Failed to remove ${dir}" 144 | fi 145 | case "${opts[-keep-dir]}" in 146 | (1) ${rm} ${dir} && ${cp} ${DIR}/rr ${dir} || 147 | die "Failed to update ${dir}";; 148 | esac 149 | 150 | ${mount} -t ${opts[-filesystem]} -o ${opt} \ 151 | ${opts[-filesystem]}:${dir} ${dir} >${NULL} 2>&1 || 152 | die "Failed to mount ${opts[-filesystem]}:${dir}" 153 | } 154 | # @FUNCTION: Helper to squash-directory 155 | function squash-dir { 156 | case "${opts[-filesystem]}" in 157 | (aufs) 158 | opt=nodev,udba=reval,br:${DIR}/rw:${DIR}/rr 159 | mkdir -p -m 0755 ${DIR}/r{r,w};; 160 | (overlay) 161 | opt=nodev,upperdir=${DIR}/up,lowerdir=${DIR}/rr,workdir=${DIR}/wk 162 | mkdir -p -m 0755 ${DIR}/{rr,up,wk};; 163 | esac 164 | (( ${?} == 0 )) || die "Failed to create required directories" 165 | (( ${opts[-mount]} > 1 )) && { squash-mount; return; } 166 | 167 | mksquashfs ${dir} ${DIR}.tmp.squashfs -b ${opts[-block-size]} -comp ${opts[-compressor]} \ 168 | ${opts[-exclude]:+-wildcards -regex -e} ${opts[-exclude]} || 169 | die "Failed to build ${dir}.squashfs image" 170 | echo -e "\e[1;36m>>>\e[0m Sucessfully build ${DIR}.tmp.squashfs" 171 | 172 | (( ${opts[-mount]} )) && squash-mount 173 | } 174 | 175 | for mod in ${opts[-filesystem]:-aufs overlay} squashfs; do 176 | grep -q ${mod} /proc/filesystems || modprobe ${mod} >${NULL} 2>&1 || 177 | case ${mod} in 178 | (aufsi|overlay) error "Failed to load ${mod} module"; opts[-mount]=0;; 179 | (squashfs) die "Failed to load ${mod} module";; 180 | esac 181 | case "${mod}" in 182 | (aufs|overlay) opts[-filesystem]="${mod}" 183 | case "${mod}" in 184 | (aufs) RW=rw;; 185 | (ove*) RW=up;; 186 | esac 187 | break;; 188 | esac 189 | done 190 | 191 | for dir in ${*//:/ }; do 192 | DIR="/${opts[squash-root]#/}/${dir#/}" dir="/${dir#/}" 193 | if [[ -e ${DIR}.squashfs ]]; then 194 | case "${opts[-mount]}" in 195 | (3) echo -e "\e[1;34m>>>\e[0m Umounting ${dir}..." 196 | squash-dir; continue;; 197 | (2) echo -e "\e[1;35m>>>\e[0m Mounting ${dir}..." 198 | squash-dir; continue;; 199 | esac 200 | if (( ${opts[-offset]} != 0 )); then 201 | rr=$(du -sk ${DIR}/rr | awk '{print $1}') 202 | rw=$(du -sk ${DIR}/${RW} | awk '{print $1}') 203 | if (( (${rw}*100/${rr}) < ${opts[-offset]} )); then 204 | echo -e "\e[1;31m>>>\e[0m Skiping ${dir}... or use -o option" 205 | else 206 | echo -e "\e[1;32m>>>\e[0m Updating squashed ${dir}..." 207 | squash-dir 208 | fi 209 | else 210 | echo -e "\e[1;32m>>>\e[0m Updating squashed ${dir}..." 211 | squash-dir 212 | fi 213 | else 214 | echo -e "\e[1;32m>>>\e[0m Building squashed ${dir}..." 215 | squash-dir 216 | fi 217 | done 218 | 219 | [[ -x "${busybox}" ]] && rm -f "${busybox}" 220 | 221 | unset DIR RW dir opt opts rr rw 222 | 223 | # 224 | # vim:fenc=utf-8:ci:pi:sts=0:sw=4:ts=4: 225 | # 226 | -------------------------------------------------------------------------------- /usr/share/gnupg/options.skel: -------------------------------------------------------------------------------- 1 | # These first three lines are not copied to the gpg.conf file in 2 | # the users home directory. 3 | # $Id: usr/share/gnupg/options.skel 5429 2010-09-28 16:13:24Z dshaw $ 4 | # Options for GnuPG 5 | # Copyright 1998, 1999, 2000, 2001, 2002, 2003, 6 | # 2010 Free Software Foundation, Inc. 7 | # 8 | # This file is free software; as a special exception the author gives 9 | # unlimited permission to copy and/or distribute it, with or without 10 | # modifications, as long as this notice is preserved. 11 | # 12 | # This file is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 14 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | # 16 | # Unless you specify which option file to use (with the command line 17 | # option "--options filename"), GnuPG uses the file ~/.gnupg/gpg.conf 18 | # by default. 19 | # 20 | # An options file can contain any long options which are available in 21 | # GnuPG. If the first non white space character of a line is a '#', 22 | # this line is ignored. Empty lines are also ignored. 23 | # 24 | # See the man page for a list of options. 25 | 26 | # Uncomment the following option to get rid of the copyright notice 27 | 28 | #no-greeting 29 | 30 | # If you have more than 1 secret key in your keyring, you may want to 31 | # uncomment the following option and set your preferred keyid. 32 | 33 | #default-key 621CC013 34 | 35 | # If you do not pass a recipient to gpg, it will ask for one. Using 36 | # this option you can encrypt to a default key. Key validation will 37 | # not be done in this case. The second form uses the default key as 38 | # default recipient. 39 | 40 | #default-recipient some-user-id 41 | #default-recipient-self 42 | 43 | # Use --encrypt-to to add the specified key as a recipient to all 44 | # messages. This is useful, for example, when sending mail through a 45 | # mail client that does not automatically encrypt mail to your key. 46 | # In the example, this option allows you to read your local copy of 47 | # encrypted mail that you've sent to others. 48 | 49 | #encrypt-to some-key-id 50 | 51 | # By default GnuPG creates version 4 signatures for data files as 52 | # specified by OpenPGP. Some earlier (PGP 6, PGP 7) versions of PGP 53 | # require the older version 3 signatures. Setting this option forces 54 | # GnuPG to create version 3 signatures. 55 | 56 | #force-v3-sigs 57 | 58 | # Because some mailers change lines starting with "From " to ">From " 59 | # it is good to handle such lines in a special way when creating 60 | # cleartext signatures; all other PGP versions do it this way too. 61 | 62 | #no-escape-from-lines 63 | 64 | # If you do not use the Latin-1 (ISO-8859-1) charset, you should tell 65 | # GnuPG which is the native character set. Please check the man page 66 | # for supported character sets. This character set is only used for 67 | # metadata and not for the actual message which does not undergo any 68 | # translation. Note that future version of GnuPG will change to UTF-8 69 | # as default character set. In most cases this option is not required 70 | # as GnuPG is able to figure out the correct charset at runtime. 71 | 72 | #charset utf-8 73 | 74 | # Group names may be defined like this: 75 | # group mynames = paige 0x12345678 joe patti 76 | # 77 | # Any time "mynames" is a recipient (-r or --recipient), it will be 78 | # expanded to the names "paige", "joe", and "patti", and the key ID 79 | # "0x12345678". Note there is only one level of expansion - you 80 | # cannot make an group that points to another group. Note also that 81 | # if there are spaces in the recipient name, this will appear as two 82 | # recipients. In these cases it is better to use the key ID. 83 | 84 | #group mynames = paige 0x12345678 joe patti 85 | 86 | # Lock the file only once for the lifetime of a process. If you do 87 | # not define this, the lock will be obtained and released every time 88 | # it is needed, which is usually preferable. 89 | 90 | #lock-once 91 | 92 | # GnuPG can send and receive keys to and from a keyserver. These 93 | # servers can be HKP, email, or LDAP (if GnuPG is built with LDAP 94 | # support). 95 | # 96 | # Example HKP keyserver: 97 | # hkp://keys.gnupg.net 98 | # hkp://subkeys.pgp.net 99 | # 100 | # Example email keyserver: 101 | # mailto:pgp-public-keys@keys.pgp.net 102 | # 103 | # Example LDAP keyservers: 104 | # ldap://keyserver.pgp.com 105 | # 106 | # Regular URL syntax applies, and you can set an alternate port 107 | # through the usual method: 108 | # hkp://keyserver.example.net:22742 109 | # 110 | # Most users just set the name and type of their preferred keyserver. 111 | # Note that most servers (with the notable exception of 112 | # ldap://keyserver.pgp.com) synchronize changes with each other. Note 113 | # also that a single server name may actually point to multiple 114 | # servers via DNS round-robin. hkp://keys.gnupg.net is an example of 115 | # such a "server", which spreads the load over a number of physical 116 | # servers. To see the IP address of the server actually used, you may use 117 | # the "--keyserver-options debug". 118 | 119 | keyserver hkp://keys.gnupg.net 120 | #keyserver mailto:pgp-public-keys@keys.nl.pgp.net 121 | #keyserver ldap://keyserver.pgp.com 122 | 123 | # Common options for keyserver functions: 124 | # 125 | # include-disabled : when searching, include keys marked as "disabled" 126 | # on the keyserver (not all keyservers support this). 127 | # 128 | # no-include-revoked : when searching, do not include keys marked as 129 | # "revoked" on the keyserver. 130 | # 131 | # verbose : show more information as the keys are fetched. 132 | # Can be used more than once to increase the amount 133 | # of information shown. 134 | # 135 | # use-temp-files : use temporary files instead of a pipe to talk to the 136 | # keyserver. Some platforms (Win32 for one) always 137 | # have this on. 138 | # 139 | # keep-temp-files : do not delete temporary files after using them 140 | # (really only useful for debugging) 141 | # 142 | # http-proxy="proxy" : set the proxy to use for HTTP and HKP keyservers. 143 | # This overrides the "http_proxy" environment variable, 144 | # if any. 145 | # 146 | # auto-key-retrieve : automatically fetch keys as needed from the keyserver 147 | # when verifying signatures or when importing keys that 148 | # have been revoked by a revocation key that is not 149 | # present on the keyring. 150 | # 151 | # no-include-attributes : do not include attribute IDs (aka "photo IDs") 152 | # when sending keys to the keyserver. 153 | 154 | #keyserver-options auto-key-retrieve 155 | 156 | # Display photo user IDs in key listings 157 | 158 | # list-options show-photos 159 | 160 | # Display photo user IDs when a signature from a key with a photo is 161 | # verified 162 | 163 | # verify-options show-photos 164 | 165 | # Use this program to display photo user IDs 166 | # 167 | # %i is expanded to a temporary file that contains the photo. 168 | # %I is the same as %i, but the file isn't deleted afterwards by GnuPG. 169 | # %k is expanded to the key ID of the key. 170 | # %K is expanded to the long OpenPGP key ID of the key. 171 | # %t is expanded to the extension of the image (e.g. "jpg"). 172 | # %T is expanded to the MIME type of the image (e.g. "image/jpeg"). 173 | # %f is expanded to the fingerprint of the key. 174 | # %% is %, of course. 175 | # 176 | # If %i or %I are not present, then the photo is supplied to the 177 | # viewer on standard input. If your platform supports it, standard 178 | # input is the best way to do this as it avoids the time and effort in 179 | # generating and then cleaning up a secure temp file. 180 | # 181 | # If no photo-viewer is provided, GnuPG will look for xloadimage, eog, 182 | # or display (ImageMagick). On Mac OS X and Windows, the default is 183 | # to use your regular JPEG image viewer. 184 | # 185 | # Some other viewers: 186 | # photo-viewer "qiv %i" 187 | # photo-viewer "ee %i" 188 | # 189 | # This one saves a copy of the photo ID in your home directory: 190 | # photo-viewer "cat > ~/photoid-for-key-%k.%t" 191 | # 192 | # Use your MIME handler to view photos: 193 | # photo-viewer "metamail -q -d -b -c %T -s 'KeyID 0x%k' -f GnuPG" 194 | 195 | # Passphrase agent 196 | # 197 | # We support the old experimental passphrase agent protocol as well as 198 | # the new Assuan based one (currently available in the "newpg" package 199 | # at ftp.gnupg.org/gcrypt/alpha/aegypten/). To make use of the agent, 200 | # you have to run an agent as daemon and use the option 201 | # 202 | # use-agent 203 | # 204 | # which tries to use the agent but will fallback to the regular mode 205 | # if there is a problem connecting to the agent. The normal way to 206 | # locate the agent is by looking at the environment variable 207 | # GPG_AGENT_INFO which should have been set during gpg-agent startup. 208 | # In certain situations the use of this variable is not possible, thus 209 | # the option 210 | # 211 | # --gpg-agent-info=::1 212 | # 213 | # may be used to override it. 214 | 215 | # Automatic key location 216 | # 217 | # GnuPG can automatically locate and retrieve keys as needed using the 218 | # auto-key-locate option. This happens when encrypting to an email 219 | # address (in the "user@example.com" form), and there are no 220 | # user@example.com keys on the local keyring. This option takes the 221 | # following arguments, in the order they are to be tried: 222 | # 223 | # cert = locate a key using DNS CERT, as specified in RFC-4398. 224 | # GnuPG can handle both the PGP (key) and IPGP (URL + fingerprint) 225 | # CERT methods. 226 | # 227 | # pka = locate a key using DNS PKA. 228 | # 229 | # ldap = locate a key using the PGP Universal method of checking 230 | # "ldap://keys.(thedomain)". For example, encrypting to 231 | # user@example.com will check ldap://keys.example.com. 232 | # 233 | # keyserver = locate a key using whatever keyserver is defined using 234 | # the keyserver option. 235 | # 236 | # You may also list arbitrary keyservers here by URL. 237 | # 238 | # Try CERT, then PKA, then LDAP, then hkp://subkeys.net: 239 | #auto-key-locate cert pka ldap hkp://subkeys.pgp.net 240 | -------------------------------------------------------------------------------- /init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Header: mkinitramfs-ll/init Exp $ 4 | # $Author: (c) 2011-19 tokiclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.22.2 2019/01/12 12:33:03 Exp $ 7 | # 8 | # WARNING: USE AT YOUR OWN RISK! EVERYTHING IS GIVEN “AS IS”, SEE COPYING FILE 9 | # 10 | 11 | CHECK_ENV=true 12 | init=/sbin/init 13 | confdir=/etc/mkinitramfs-ll 14 | libdir=/lib/mkinitramfs-ll 15 | logfile=$0.log 16 | mntdir=/mnt/tok 17 | newroot=/newroot 18 | splashd=false 19 | NULL=/dev/null 20 | export SHELL=/bin/sh 21 | export HOME=/root 22 | export PATH=/bin:/sbin:/usr/bin:/usr/sbin 23 | export TERM=linux 24 | exec 3>$logfile 25 | logfd=3 26 | PS1='-($(tty | cut -c6-):$PWD)-# ' 27 | PS2='-# ' 28 | 29 | # @FUNCTION: Handle fatal error 30 | # @ARG: 31 | die() { 32 | local _ret=$? 33 | [ -n "$@" ] && msg -e "[$_ret]: $@" 34 | echo -e "$color_fg_red>>>$color_rst Dropping to a Rescue Shell" 35 | $splashd && splashd_stop 36 | debug rescue_shell || debug $SHELL -lim 37 | } 38 | 39 | . $libdir/functions || $SHELL -lim 40 | eval_colors 41 | name=init 42 | 43 | # @FUNCTION: Shell Run Level helper 44 | # @ARG: 45 | level() { 46 | echo -e "$color_fg_grn>>>$color_rst Switching to init shell run level $color_fg_blu$1$color_rst" 47 | level=$1 48 | 49 | local _f 50 | for _f in $(ls $libdir/${1}-* 2>$NULL); do 51 | dohook "$_f" 52 | done 53 | case "$level" in 54 | ("$rescue_shell") debug die;; 55 | esac 56 | return 0 57 | } 58 | 59 | # @FUNCTION: Splash daemon helper 60 | splashd() { 61 | $CHECK_ENV && debug -d bck fbcondecor_helper splash_util 62 | local IFS="${IFS}," _opt _opts cachedir event mode theme 63 | 64 | event="$(grep -Hsi keyboard /sys/class/input/input*/name | \ 65 | sed -e 's#.*input\([0-9]*\)/name.*#event\1#')" 66 | : ${cachedir:=/run/splash/cache} 67 | : ${BOOT_MSG:="Booting the system (\$progress%)... Press F2 for verbose mode."} 68 | : ${splash_fifo=$cachedir/.splash} 69 | 70 | for _opt in $splash; do 71 | case "${_opt%:*}" in 72 | (fad*) _opts="set effects $_opt";; 73 | (silent|verbose) mode="$_opt" ;; 74 | (tty) CONSOLE=/dev/"${_opt/:/}" ;; 75 | (theme) theme="${_opt#*:}" ;; 76 | esac 77 | done 78 | 79 | [ -d "$cachedir" ] || mkdir -p $cachedir 80 | debug mkfifo $splash_fifo 81 | debug splash_util -d -ms -t $theme && splashd=true 82 | [ -n "$_opts" ] && debug splashd_cmd $_opts 83 | debug splashd_cmd "set ${mode:-verbose}" 84 | debug splashd_cmd "set event dev /dev/input/$event" 85 | debug splashd_cmd "set autoverbose 0" 86 | } 87 | 88 | # @FUNCTION: Resume helper (support SwSusp/TuxOnIce) 89 | # @ARG: <[type:]dev[:signature]> 90 | resume() { 91 | local _asw _dev=$1 _img_sz _hpr 92 | grep -q $mntdir /proc/mounts && debug -d umount -l $mntdir 93 | 94 | if [ -d /sys/power/tuxonice ]; then 95 | if $splashd; then 96 | [ -n "$theme" ] && 97 | debug ln -sf "/etc/splash/$theme" /etc/splash/tuxonice 98 | _hpr=tuxoniceui_fbsplash 99 | else 100 | _hpr=tuxoniceui_text 101 | fi 102 | $CHECK_ENV && debug -d check_bin $_hpr && _hpr="$(type -p $_hpr)" 103 | 104 | debug MODPROBE tuxonice 105 | echo $_hpr >/sys/power/tuxonice/user_interface/program 106 | echo $_dev >/sys/power/tuxonice/resume 107 | 108 | read _img /sys/power/tuxonice/image_exists 111 | else 112 | echo >/sys/power/tuxonice/do_resume 113 | fi 114 | elif [ -f /sys/power/resume ]; then 115 | debug MODPROBE swsusp 116 | echo platform >/sys/power/disk # or 'shutdown' if ACPI does not work 117 | echo disk >/sys/power/state 118 | 119 | local _node=${_dev#*:} 120 | [ -h "$_node" ] && _node=$(readlink $_node) 121 | read _node /sys/power/resume 123 | 124 | read _img_sz /sys/power/resume 127 | else 128 | echo 0 >/sys/power/image_size 129 | fi 130 | fi 131 | } 132 | 133 | # -*- Initialisation -*- 134 | 135 | debug umask 0077 136 | debug mkdir -p dev/pts proc run sys $newroot $mntdir 137 | 138 | debug mount -t proc proc /proc 139 | debug mount -t sysfs sysfs /sys 140 | if grep -q devtmpfs /proc/filesystems; then 141 | debug mount -t devtmpfs devtmpfs /dev 142 | else 143 | debug mount -t tmpfs -o exec,mode=755 tmpfs /dev 144 | fi 145 | echo >/dev/mdev.seq 146 | [ -x /sbin/mdev ] && mdev=/sbin/mdev || mdev="/bin/busybox mdev" 147 | debug -d $mdev -s 148 | echo $mdev >/proc/sys/kernel/hotplug 149 | 150 | debug mount -t tmpfs -o mode=755,size=1% tmpfs /run 151 | 152 | CMDLINE="$(cat /proc/cmdline)" 153 | for arg in $CMDLINE; do 154 | case "$arg" in 155 | ([Rr][Ee][Ss][Cc][Uu][Ee]*|[Rr][Ss][Hh]*) rescue_shell=1;; 156 | (ro|rw) rootflags="${rootflags:+$rootflags,}$arg";; 157 | ([Cbcdefhiklmnrsvz]*=*) eval "$arg" ;; 158 | esac 159 | done 160 | : ${rootfstype:=$rootfs} 161 | 162 | if [ -n "$level" ]; then 163 | rescue_shell="${level%:*}" 164 | fi 165 | 166 | case "$env" in 167 | (""|*:*) ENV=true;; 168 | (*) 169 | yesno "${env:-YES}" 170 | case "$?" in 171 | (0) ENV=true ;; 172 | (*) ENV=false;; 173 | esac 174 | ;; 175 | esac 176 | $ENV && [ -f $confdir/env ] && 177 | while read _line; do 178 | case "$_line" in 179 | (confdir=*|libdir=*|HOME=*|keymode=*|logfile=*|mntdir=*|newroot=*) ;; 180 | (PATH=*|rescue_shell=*|NULL=*|splashd=*|SHELL=*|name=*) ;; 181 | ([A-Za-z]*=*) 182 | case "$env" in 183 | (*:${_line%%=*}:*) ;; 184 | (*) eval "$_line" ;; 185 | esac;; 186 | esac 187 | done < $confdir/env 188 | $CHECK_ENV && debug check_applet 189 | 190 | CUT "dmesg" "$debug" ":" "2" "-s" 191 | debug="${debug%:*}" 192 | case "$debug" in 193 | (*l*) 194 | keeplog=true debug="${debug/l/}" 195 | exec 2>&3 196 | ;; 197 | esac 198 | [ -n "$debug" ] && set -${debug/e/} 199 | [ -n "$dmesg" ] && debug dmesg -n $dmesg 200 | dmesg= 201 | 202 | [ -f $confdir/module-boot ] && 203 | for _m in $(cat $confdir/module-boot); do 204 | debug MODPROBE $_m 205 | done 206 | for _m in $(echo "$module" | sed 's/[:,]/ /g'); do 207 | debug MODPROBE $_m 208 | done 209 | 210 | [ -h /dev/fd ] || debug ln -fns /proc/self/fd /dev/fd 211 | [ -h /dev/stderr ] || debug ln -fns fd/2 /dev/stderr 212 | [ -h /dev/stdin ] || debug ln -fns fd/0 /dev/stdin 213 | [ -h /dev/stdout ] || debug ln -fns fd/1 /dev/stdout 214 | 215 | : ${CONSOLE:=${console:-/dev/console}} 216 | [ "${CONSOLE/dev}" != "$CONSOLE" ] || CONSOLE="/dev/$CONSOLE" 217 | [ -c $CONSOLE ] || CONSOLE=/dev/console 218 | exec 0<$CONSOLE 1>$CONSOLE 2>&1 219 | eval_colors 220 | set >/environ 221 | 222 | if [ -n "$video" ]; then 223 | debug dohook "$libdir/fb-video" 224 | fi 225 | if [ -n "$splash" ]; then 226 | begin "Starting Splash" 227 | splashd 228 | end "$?" 229 | fi 230 | 231 | # -*- Font and keymap -*- 232 | 233 | if [ -n "$keymap" ]; then 234 | CUT "font" "$keymap" "2" ":" "-s" 235 | kmap="${keymap%:*}" 236 | fi 237 | [ -z "$font" ] && [ -f "$confdir/font" ] && font=$(cat $confdir/font) 238 | [ -z "$kmap" ] && [ -f "$confdir/kmap" ] && kmap=$(cat $confdir/kmap) 239 | 240 | [ -n "$font" ] && 241 | for file in /usr/share/consolefonts/$font*; do 242 | [ -f "$file" ] && debug loadfont < $file && break 243 | done 244 | [ -n "$kmap" ] && 245 | for file in /usr/share/keymaps/$kmap*; do 246 | [ -f "$file" ] && debug loadkmap < $file && break 247 | done 248 | unset file font kmap 249 | 250 | # -*- Logo and or boot message -*- 251 | level 1 252 | [ -f /etc/issue.logo ] && cat /etc/issue.logo 253 | if debug test -f /etc/issue; then 254 | clear 255 | while read _line; do 256 | msg -i "$_line" 257 | done /proc/sys/kernel/hotplug 361 | for _dir in /run /sys /dev /proc; do 362 | if [ "${SYSFS/${_dir#/}}" != "$SYSFS" ]; then 363 | begin "Moving $_dir to $newroot" 364 | mkdir -p $newroot$_dir 365 | mount -o move $_dir $newroot$_dir >$NULL 2>&1 366 | else 367 | begin "Unmounting $_dir" 368 | umount -l $_dir >$NULL >&1 369 | fi 370 | end "$?" 371 | done 372 | 373 | level 4s 374 | set >/environ 375 | echo -e "$color_fg_grn>>>$color_rst Switching Root" 376 | exec 3>&- 377 | while read _env; do 378 | case "$_env" in 379 | init=*) : ;; 380 | [Cbcdefhiklmnrsz]*=*) unset "${_env%%=*}" ;; 381 | esac 382 | done >>$color_rst Failed to switch root!" 386 | exec >${SHELL:-/bin/sh} -lim 387 | 388 | # 389 | # vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4: 390 | # 391 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Header: mkinitramfs-ll/ChangeLog, 2016/01/10 2 | 3 | 0.22.12: 4 | 5 | Added a new framebuffer hook to take care buggy firmare. 6 | 7 | 0.22.11: 8 | 9 | Minor fixes from LUKS regular keyfile to ZFS device search path. 10 | 11 | 0.22.10: 12 | 13 | Cleaned up environment, so init--PID 1--will not carry all the colors et al. 14 | environment variables; export only a few variables to avoid poluting init 15 | environment. 16 | 17 | 0.22.8: 18 | 19 | Tiny fixes all over the place (GnuPG decrypt and busybox related tiny fixes) 20 | thanks to szorfein. 21 | 22 | 0.22.7: 23 | 24 | Minor fixes all over the place in {busybox,gnupg}.sh, zfs hook, and dmopen() 25 | when using GnuPG key thanks to szorfein. 26 | 27 | 0.22.6: 28 | 29 | Important typo fixes for svc/{zram,squashdir}.initd; and a stop_pre() fix for 30 | svc/squashdir.initd. 31 | 32 | 0.22.5: 33 | 34 | Version bump the ChangeLog for previous release. 35 | 36 | 0.22.4: 37 | 38 | Important installation path fix for {ba,z}sh scripts. 39 | 40 | 0.22.3: 41 | 42 | Bug fix: append to fd-3 instead of truncating; print helpers clean up. 43 | 44 | 0.22.2: 45 | 46 | Bug fix: create file descriptor 3 for logfile; zram.initd major clean up. 47 | 48 | 0.22.1: 49 | 50 | Support SOFTWARE RAID on top of DM-CRYPT LUKS; 51 | Set up the environment properly for hooks (inherit init's environment); 52 | And there is no need to source {functions,helpers} manualy anymore (in hooks); 53 | Added support to fsmount=all or fstab=all to mount everything (filesystems); 54 | Miscellaneous changes, updates and fixes. 55 | 56 | 0.22.0: 57 | 58 | Added *l* option to *debug* cmdline argument to duplicate stderr 59 | to $LOGFILE/file descriptor 3 for easy debugging. 60 | 61 | 0.21.4: 62 | 63 | Tiny USRDIR installtion setup and update. 64 | 65 | 0.21.3: 66 | 67 | Export NULL and CHECK_ENV environment variables (tiny fix); 68 | and install documentation properly. 69 | 70 | 0.21.2: 71 | 72 | Fixed USRDIR set up in a standard installation (Makefile); 73 | and plain (uncrypted) btrfs support. 74 | 75 | 0.21.1: 76 | 77 | IMPORTANT FIX: Tiny dm-crypt LUKS detached header fix. 78 | 79 | 0.21.0: 80 | 81 | Added POSIX scripts {mkinitramfs-ll,sdr,busybox,gnupg}.sh; and 82 | removed {busybox,gnupg}.{ba,z}sh. {mkinitramfs-ll,sdr}.{ba,z}sh 83 | will be removed later, so running `make install-{ba,z,}sh-scripts' 84 | would install the right building scripts. 85 | 86 | WARNING: sh build script cannot be installed in parallele with 87 | {ba,z}sh scripts because of configuration file conflict! A symlink 88 | was added to the source directory to be able to select one and run 89 | any in place like before. 90 | 91 | Nothing really changed but the configuration file! Could not keep 92 | associative arrays with POSIX shell obviously. So variables have 93 | new names which have more clarity than the previous ones, e.g. 94 | module group are named `module_', binary group `bin_' 95 | and used groups are kept in `module_group' variables. 96 | 97 | Incindently, the old/legacy configuration file was cleaned to reflect 98 | this new clarity ('-m'=>'-module-'/'-b'=>'-bin-'.) 99 | Chekout the new configuration file!!! 100 | 101 | Another noticeable change is the removal of -d|--squash-dir cmdline 102 | switch to sdr scripts (which was really useless) and support space 103 | as a separator (along with colon.) 104 | 105 | Two new cmdline switches {-m|--mount,-M|--unmount} were added so that 106 | sdr scripts can be used as a standalone union-mount utility without 107 | an extra init script service. 108 | 109 | Last noticeable change is the addition of OverlayFS support to init 110 | (functions: squashd()), squashdir init script service and sdr.$SHELL. 111 | 112 | 0.20.0: 113 | 114 | Refactorized init (initialization/splash), functions (helpers), 115 | and init script services. Some helpers/env-variables were renamed 116 | for clarity; and tiny fixes all over the place. 117 | 118 | 0.19.0: 119 | 120 | Eye-candy release! init,function clean up (splash/comments), 121 | added proper color support (+COLOR env var) & fixed init cmdline. 122 | 123 | 0.18.1: 124 | 125 | * minor update (default config) & fix (handle firmware symlink); 126 | 127 | 0.18.0: 128 | 129 | Major clean up/overhaul of cmdline name!!! read the man(1) page; 130 | 131 | 0.16.4: 132 | 133 | * minor update (man page)/clean up (config file)/fix (zram/functions); 134 | 135 | 0.16.3: 136 | 137 | * UUID/LABEL support fix (btrfs/bcache); minor man(1)/INSTALL update; 138 | 139 | 0.16.2: 140 | 141 | * added yesno helper (init/functions clean up); & btrfs support; 142 | 143 | 0.16.1: 144 | 145 | * renamed squashdir-mount to squashdir for clarity; & README.md update; 146 | 147 | 0.16.0: 148 | 149 | * added firmware regex support to ease firmware copy; 150 | * zram{,dir} init script further clean up; 151 | documention major clean up (added man pages & removed *.textile); 152 | build scripts help (major) clean up; 153 | * renamed zramdir to tmpdir with optional zram backed device; 154 | 155 | 0.15.1: 156 | 157 | * added ability to chose what file system to keep around; 158 | * minor clean up & fixes (build/init scripts, functions); 159 | * major license clean up: BSD-2 (2-clause/new/simplified); 160 | 161 | License Note: (Update: removed GPL and CC by SA choices) 162 | 163 | options.skel (GnuPG) and ide_links (BusyBox) are licensed as GPL-2; 164 | and are solely provided for _convenience_ for the end user; 165 | so feel free to remove them to have BSD-2 only code. 166 | 167 | 0.15.0: 168 | 169 | * added ability to keep {proc,sys,dev} mounted; minor clean up; 170 | 171 | 0.14.9: 172 | 173 | * minor bug fix (installed zsh scripts); README clean up; 174 | 175 | 0.14.8: 176 | 177 | * minor installtion fix (sed); 178 | 179 | 0.14.7: 180 | 181 | * complete re-write of the Makefile (cleaner/shorter/effient); 182 | * added hooks/mkswap-zfs and scripts/suspend (hibernation script); 183 | * documented swsusp (module group); and fixed resume (swsusp); 184 | resume clean up (continue booting instead dying for nothing). 185 | 186 | 0.14.6: 187 | 188 | * minor fix/clean up (dm_link/building script). 189 | 190 | 0.14.5: 191 | 192 | * bcache trivial fix; and added ibcache support to init; 193 | * added a minimal /etc/group so groups can be refered by names; 194 | * removed mdev buggy scripts ({dvbdev,usb*}); cleaned ide_links; 195 | and added dm_link to take care of device-mapper symlink. 196 | 197 | 0.14.4: 198 | 199 | * added a 4th zram device for /dev/shm + /etc/modprobe.d/zfs.conf; 200 | * fix lvm breakage since 0.14.0 (commit be0f3a3d) with the 201 | new block stack position (before or after luks); 202 | * fix lvm dependency to udev in early sysinit; 203 | * removing closing after lvm/rootfs mount failure; 204 | * fix -k|--kv switch (was still broken after fixing them); 205 | and -c|--compressor, -u|--usr switches; 206 | * fix setiing installation configuration file. 207 | 208 | 0.14.3: 209 | 210 | * Fix the annoying prefix slash '/' in squash dir related script 211 | (the previous measure in 0.14.2 was not enough); 212 | * Fix setting mode (if present in zram init script). 213 | 214 | 0.14.2: 215 | 216 | * zfs version bump that require only *izfs* cmdline argument, 217 | this hook as result will be executed if only if izfs is defined; 218 | * allow only case insensitive +s|+sys|+system and +l|+local (short/long 219 | options) to squashd(); 220 | * improved dmopen() to be sure to boot with variations of iraid; 221 | * added an environment profile to be able to boot with an empty kernel cmdline. 222 | 223 | 0.14.1: 224 | 225 | * fixed broken -F switch and removed redundant firmware bits; 226 | * a bunch of usefull fixes and update, read the configure file and commits; 227 | * added case insensitive rescue|rsh support in kernel command line; 228 | * added kernel module group support in boot (imod already support that), 229 | so one can make default module groups and add theme to boot group 230 | (and then no need to append imod=something if not needed!); 231 | * inproved shread(), now support case insensitive [r]sh|shell|rescue; 232 | * fix issue when ro|rw and imopt= are appended on cmdline; 233 | * ability to copy kernel module dependencies for building scripts; 234 | * cleaned up squashd() to have a nice and user friendly api, see README; 235 | * added default font/keymap to building scripts, so init script can pick up 236 | a font/keymap pair if *ikmap* kernel cmdline argument is not present. 237 | 238 | 0.14.0: 239 | 240 | * clean up bcache hooks, now provide a simple and functional hooks; 241 | * renamed (internal) module to hook which is more appropriate; 242 | * fix mkinitramfs-ll.bash kernel module dealing (with *globbing everywhere*); 243 | * file system position change for *iroot* (see README); 244 | * version bumped zram hook/module (almost feature complete); 245 | * version bumped functions to use fewer arg() calls (+efficiency); 246 | * bumped version for init script that now use start|stop_pre() instead of 247 | stuffing start() and stop(); 248 | * refined zram.initd which is now feature comple; 249 | * fixed mkinitramfs-ll.{ba,z}sh (new) commands line switches (parsing). 250 | 251 | 0.13.7: 252 | 253 | * added svc/zramdir.{conf,init}d, a service to take extra zram backed device 254 | stuff to not stuff zram service script with numerous devices; 255 | * clean up svc/* scripts and removed bashisms from service scripts; 256 | * cmdline clean for bash/zsh scripts (there were many left overs...); 257 | * now mkinitramfs-ll.bash will pick up opts[-] options found 258 | in mkinitramfs-ll.conf (zsh variant always honored it); 259 | * removed openrc and splash specific bits from sdr.$shell, new openrc has 260 | runtime temporary files in /run, it think splash-utils is unmaintained...; 261 | * now zsh scripts use getopt(1) to parse optional arguments, (zsh/zutil) 262 | zparseopts is awfull for long options; 263 | * mkinitramfs-ll.zsh: fix parsing -b|-bin,-F|-firmware,-y|-keymap, so next 264 | occurences will rightly append options; 265 | * fix help formating for bash scripts regarding white space issue (getopt(1)). 266 | 267 | 0.13.6: 268 | 269 | * fix copying binaries which have busybox applets that end up by 270 | corrupting/overriding busybox binary; 271 | * synced to current mdev files (conf/lib); 272 | * fix root mount option (broken with an old variable rename); 273 | * fix busybox applets list generating with a dynamic binary; 274 | * clean up: init/mkinitramfs-ll.zsh; 275 | * now warning will be printed to stderr instead of stdout, so one can 276 | easily get access to no fatal warnings with something like `2>err'; 277 | * added kernel compressor check and iterration loop to get a supported 278 | compressed initramfs, so now one can build an uncompressed initramfs 279 | as result when building with -c'none' switch; 280 | * rewritten adn() to donod(), zsh has a fix with this; 281 | * moved domod() from init lib/functions to make the function public; 282 | * mkinitramfs-ll.$shell won't enforce a static busybox binary anymore, 283 | only a warning will be displayed if a dynamic binary is found. 284 | 285 | 0.13.5: 286 | 287 | * fix splash deamon initialization (broken because of helper renames, sigh); 288 | * fix parsing zfs argument for sawap and resume along with the returned device. 289 | 290 | 0.13.4: 291 | 292 | * fix key mode for zfs module; 293 | * fix kernel cmdline argument parsing for zfs. 294 | 295 | 0.13.3: 296 | 297 | * documented *imodule* kernel cmdline; 298 | * cleaned usr/README; 299 | * finished reverting commit dd17c24. 300 | 301 | 0.13.2: 302 | 303 | * revert commit dd17c24 7a9d1fe b601b48 dd17c24 that introduced function name() 304 | definition to sh scripts; 305 | * added user_xattr to zram.initd; 306 | * updated {,svc/}README busybox related bits; 307 | * minor fix for init (umount proc at the end, not at the begining). 308 | 309 | 0.13.1: 310 | 311 | * fix copying binaries and libraries: binaries and libraries are no longer 312 | duplicated, symlinks are copied instead with the libraries; 313 | * renamed sqfsd to squashd in init,usr/lib/mkinitramfs-ll/functions, 314 | mkinitramfs-ll.{conf,{ba,z}sh}; 315 | * init/sdr.$shell/squashdir-mount.initd use standard .squashfs file extension; 316 | * added initialization code for sdr.$shell and squashdir-mount; 317 | * renamed clumsy sqfsdmount name to a more clear squashdir-mount; 318 | * clean up sdr.$shell and squashdir-mount with more clear/understandable names 319 | for functions/variables; 320 | * sdr.$shell use `lzo -Xcompression-level 1' as default compressor for speed 321 | and efficiency; hdd or ssd space is cheap nowadays; 322 | * updated squashdir/SQUASHDIR=/aufs (default squash-ed root location); 323 | * update help message because option should append just after option string 324 | * added -F|[-]-firmware switch to mikinitramfs-ll 325 | 326 | 0.13.0: 327 | 328 | * added *imdodule* kernel cmdline argument to be able to execute scripts 329 | or mmodule whenever one want to do so, previous implementation ran the 330 | script or module on every single boot up: now append e.g *imodule=zram* 331 | is enough! And do not prefix scripts/module with LVL init run level which 332 | brings the old behavious. See zram and zfs for pratical exemples. 333 | Actualy nobody would want to append zram to *imodule* because zram module 334 | will be executed if *izram* kernel cmdline is appended. 335 | * added resume/swap support for zfs. 336 | * now append *-Mzfs* is enough to include kernel modules/module/binaries. 337 | 338 | 0.12.8: 339 | 340 | * added zram support, now one can get zram devices as early as possible. 341 | * support kernel module group loading, meaning: 342 | one can append a group name instead of a module name like *imod=kms*; 343 | * user script changed previous sufix *.$level* to prefix *$level-*! 344 | See user script section. 345 | * renamed clumsy ishrl to irsh kernel cmdline argument. 346 | * now one can type SH|SHELL|RSH on each read as well! 347 | * autogen.{ba,z}sh: deleted useless files. 348 | * removed -W|-workdir useless switch from scripts, now initramfs 349 | will be build from TMPDIR:-/tmp. 350 | * now bash scripts accept -? switch for help; 351 | * rename -u|[-]-usage for standard -h|[-]-help switch. 352 | * removed useless -v|[-]-version switch, version string is printed 353 | with -h|[-]-help. 354 | * now squashed dir works with full path e.g. /var/lib/layman:/var/portage or 355 | with var/lib/layman:var/portage which was previously required before 0.12.8. 356 | 357 | 0.12.0: 358 | 359 | * since this version: require the associated usr directory. 360 | There's no support building at hand without the associated generating scripts! 361 | 362 | * allow to be dropped in rescue shell on each read() (infinite loop): 363 | just type @sh@ or @shell@ and then hit Enter. 364 | 365 | 0.8.2: 366 | 367 | * now one can *exit* the rescue shell after beiing dropped there, 368 | or simply after a @rescue[shell]/RSH[ELL]@ or @irsh=@ on kernel 369 | cmdline and the init will resume booting from there. 370 | 371 | -------------------------------------------------------------------------------- /mkinitramfs-ll.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $Header: mkinitramfs-ll/mkinitramfs-ll.sh Exp $ 4 | # $Author: (c) 2011-6 tokiclover Exp $ 5 | # $License: 2-clause/new/simplified BSD Exp $ 6 | # $Version: 0.22.0 2016/10/31 12:33:03 Exp $ 7 | # 8 | 9 | name=mkinitramfs-ll 10 | package=${name} 11 | shell=sh 12 | version=0.22.0 13 | null=/dev/null 14 | 15 | # @FUNCTION: Print help message 16 | usage() { 17 | cat <<-EOH 18 | ${package}.${shell} version ${version} 19 | Usage: ${0##*/} [-a|-all] [OPTIONS] 20 | 21 | -a, --all Short variant of "-lLgtq -H'btrfs zfs zram'" 22 | -e, --extension=cpio.img Extension to use (default to cpio.\$compressor) 23 | -f, --font=ter-v14n Fonts to include in the initramfs 24 | -F, --firmware=name Firmware file/directory to include 25 | -k, --kernel-version=KV Build an initramfs for kernel version VERSION 26 | -c, --compressor='gzip -9' Use 'gzip -9' compressor instead of default 27 | -L, --luks Enable LUKS support (require cryptsetup binary) 28 | -l, --lvm Enable LVM2 support (require lvm2 binary) 29 | -b, --bin= Binar-y-ies to include if available 30 | -d, --usrdir=DIRECTORY Use DIRECTORY as USRDIR instead of the default 31 | -g, --gpg Enable GnuPG support (require gnupg-1.4.x) 32 | -p, --prefix=initrd- Use 'initrd-' prefix instead of default ['initramfs-'] 33 | -H, --hook= Include hook or script if available 34 | -m, --module= Include kernel modules if available 35 | --module-tuxonice=mod Append kernel modules to tuxonice group 36 | --module-remdev=mod Append kernel modules to remdev group 37 | --module-squashd=mod Append kernel modules to squashd group 38 | --module-gpg=mod Append kernel modules to gpg group 39 | --module-boot=mod Append kernel modules to boot group 40 | -s, --splash= Include splash themes if available 41 | -t, --toi Enable TuxOnIce support (require tuxoniceui-userui) 42 | -q, --squashd Enable UnionFS+SquashFS support (AUFS/OverlayFS) 43 | -r, --rebuild Re-Build an initramfs from an old directory 44 | -y, --keymap=fr-latin1 Keymaps to include the initramfs 45 | -K, --keep-tmpdir Keep the temporary build directory 46 | -h, --help, -? Print this help or usage message 47 | EOH 48 | exit $? 49 | } 50 | 51 | # @FUNCTION: Print error message to stderr & exit 52 | die() 53 | { 54 | local ret=${?}; error "${@}"; exit ${ret} 55 | } 56 | 57 | # @FUNCTION: (static/dynamic) Binary copy helper 58 | # @ARG: 59 | dobin() { 60 | local bin="${1}" lib 61 | docp ${bin} || return 62 | ldd ${bin} >${null} 2>&1 || return 0 63 | 64 | for lib in $(ldd ${bin} | sed -nre 's,.* (/.*lib.*/.*.so.*) .*,\1,p' \ 65 | -e 's,.*(/lib.*/ld.*.so.*) .*,\1,p'); do 66 | mkdir -p .${lib%/*} && docp ${lib} || die 67 | done 68 | } 69 | 70 | # @FUNCTION: File copy helper (handle symlinks) 71 | # @ARG: 72 | docp() { 73 | local link=${1} prefix 74 | [ -n "${1}" -a -e "${1}" ] || return 75 | mkdir -p .${1%/*} 76 | rm -f .${1} && cp -a ${1} .${1} || die 77 | 78 | [ -h ${link} ] && 79 | while true; do 80 | prefix=${link%/*} 81 | link=$(readlink ${link}) 82 | [ ${link%/*} = ${link} ] && link=${prefix}/${link} 83 | rm -f .${link} && cp -a ${link} .${link} || die 84 | [ -h ${link} ] || break 85 | done 86 | return 0 87 | } 88 | 89 | # @FUNCTION: CPIO image builder 90 | docpio() { 91 | local ext=cpio file=${1:-/boot/$initramfs} 92 | local cmd="find . -print0 | cpio -0 -ov -Hnewc" 93 | 94 | case "${compressor%% *}" in 95 | (bzip2) ext=${ext}.bz2;; 96 | (gzip) ext=${ext}.gz ;; 97 | (xz) ext=${ext}.xz ;; 98 | (lzma) ext=${ext}.lzma;; 99 | (lzip) ext=${ext}.lz ;; 100 | (lzop) ext=${ext}.lzo;; 101 | (lz4) ext=${ext}.lz4;; 102 | (*) compressor=; warn "Initramfs will not be compressed";; 103 | esac 104 | : ${extension:=${ext}} 105 | if [ -f ${file}.${extension} ]; then 106 | mv ${file}.${extension} ${file}.${extension}.old 107 | fi 108 | if [ -n "${ext#.cpio}" ]; then 109 | cmd+=" | ${compressor} -c" 110 | fi 111 | eval ${cmd} >/${file}.${extension} || 112 | die "Failed to build ${file}.${extension} initramfs" 113 | } 114 | 115 | # @FUNCTION: Kernel module copy helper 116 | # @ARG: [-v|--verbose] 117 | domod() { 118 | case "${1}" in 119 | (-v|--verbose) 120 | local verbose="${2}" 121 | shift 2;; 122 | esac 123 | local m mod ret n p=/lib/modules/${kv}/ 124 | 125 | for mod; do 126 | modules="$(sed -nre "s/(${mod}(|[_-]).*$)/\1/p" .${p}modules.dep)" 127 | if [ -n "${modules}" ]; then 128 | for m in ${modules}; do 129 | case "${m}" in 130 | (*:) 131 | m="${m%:}" 132 | if [ "${verbose}" ]; then 133 | n="${m##*/}" 134 | echo "${n/.ko}" >>${verbose} || die 135 | fi 136 | ;; 137 | esac 138 | mkdir -p .${p}${m%/*} && cp -ar ${p}${m} .${p}${m} || 139 | die "Failed to copy ${m} kernel module" 140 | done 141 | else 142 | warn "${mod} kernel module not found" 143 | ret=$((${ret}+1)) 144 | fi 145 | done 146 | return ${ret} 147 | } 148 | 149 | # @FUNCTION: Device nodes (helper) 150 | donod() { 151 | pushd dev || die 152 | [ -c console ] || mknod -m 600 console c 5 1 || die 153 | [ -c urandom ] || mknod -m 666 urandom c 1 9 || die 154 | [ -c random ] || mknod -m 666 random c 1 8 || die 155 | [ -c mem ] || mknod -m 640 mem c 1 1 && chmod 0:9 mem || die 156 | [ -c null ] || mknod -m 666 null c 1 3 || die 157 | [ -c tty ] || mknod -m 666 tty c 5 0 || die 158 | [ -c zero ] || mknod -m 666 zero c 1 5 || die 159 | 160 | local i 161 | for i in 0 1 2 3 4 5 6 7; do 162 | [ -c tty${i} ] || mknod -m 600 tty${i} c 4 ${i} || die 163 | done 164 | popd || die 165 | } 166 | 167 | # @FUNCTION: Temporary dir/file helper 168 | mktmp() { 169 | local tmp="${TMPDIR:-/tmp}/${1}-XXXXXX" 170 | mkdir -p "${tmp}" || die "Failed to make ${tmp}" 171 | echo "${tmp}" 172 | } 173 | 174 | [ -f ./${package}.conf ] && source ./${package}.conf || 175 | die "No ${package}.conf configuration file found" 176 | 177 | opt="$(getopt \ 178 | -o ab:c:e:f:F:gk:lH:KLm:p:qrs:thu:y:\? \ 179 | -l all,bin:,compressor:,extension:,firmware:,font:,gpg,help \ 180 | -l hook:,luks,lvm,keep-tmpdir,module:,keymap:,kernel-version: \ 181 | -l module-boot:,module-gpg:,module-remdev:,module-squashd:,module-tuxonice: \ 182 | -l prefix:,rebuild,splash:,squashd,toi,usrdir: \ 183 | -n ${name} -s sh -- "${@}" || usage)" 184 | eval set -- ${opt} 185 | 186 | while true; do 187 | case "${1}" in 188 | (--) shift; break;; 189 | (-a|--all) option_all=':';; 190 | (-l|--lvm) option_lvm=':';; 191 | (-t|--toi) option_toi=':';; 192 | (-g|--gpg) option_gpg=':';; 193 | (-L|--luks) option_luks=':';; 194 | (-q|--squashd) option_squashd=':';; 195 | (-r|--rebuild) option_rebuild=':';; 196 | (-K|--keep-tmpdir) option_tmpdir=':';; 197 | (-b|--bin) shift; bins="${bins} ${1}";; 198 | (-k|--kernel-version) shift; kv="${1}";; 199 | (-e|--extension) shift; extension="${1}";; 200 | (-f|--font) shift; fonts="${1} ${fonts}";; 201 | (-c|--compressor) shift; compressor="${1}";; 202 | (-y|--keymap) shift; keymaps="${1} ${keymaps}";; 203 | (-m|--module) shift; modules="${modules} ${1}";; 204 | (-f|--firmware) shift; firmwares="${firmware} ${1}";; 205 | (--module-*) eval ${1/-/_}="\$${1/-/_} ${2}"; shift;; 206 | (-s|--splash) shift; splash="${splash} ${1}";; 207 | (-H|--hook) shift; hooks="${hooks} ${1}";; 208 | (-d|--usrdir) shift; usrdir="${1}";; 209 | (-p|--prefix) shift; prefix="${1}";; 210 | (-?|-h|--help|*) usage;; 211 | esac 212 | shift 213 | done 214 | 215 | # @VARIABLE: Kernel version 216 | : ${kv:=$(uname -r)} 217 | # @VARIABLE: Initramfs prefx 218 | : ${prefix:=initramfs-} 219 | # @VARIABLE: USRDIR path to use 220 | : ${usrdir:=${PWD}/usr} 221 | # @VARIABLE: Full path to initramfs image 222 | : ${initramfs=${prefix}${kv}} 223 | : ${compressor:=xz -9 --check=crc32} 224 | # @VARIABLE: Kernel ARCHitecture 225 | : ${ARCH:=$(uname -m)} 226 | # @VARIABLE: Kernel bit lenght 227 | : ${LONG_BIT:=$(getconf LONG_BIT)} 228 | # @VARIABLE: (initramfs) Tmporary directory 229 | tmpdir="$(mktmp ${initramfs})" 230 | # @DESCRIPTION: (initramfs) Configuration directory 231 | confdir="etc/${package}" 232 | source "${usrdir}"/lib/${package}/functions || exit 1 233 | eval_colors 234 | 235 | if [ -n "${option_all}" ]; then 236 | fonts="${fonts:-:}" keymaps="${keymaps:-:}" hooks="${hooks} btrfs zfs zram" 237 | option_gpg=true option_lvm=true option_squashd=true option_toi=true option_luks=true 238 | fi 239 | if [ -n "${fonts}" -a "${fonts}" = ":" -a -e /etc/conf.d/consolefont ]; then 240 | fonts="${fonts} $(sed -nre 's,^consolefont="([a-zA-Z].*)",\1,p' \ 241 | /etc/conf.d/consolefont)" 242 | fi 243 | if [ -n "${keymaps}" -a "${keymaps}" = ":" -a -e /etc/conf.d/keymaps ]; then 244 | keymaps="${keymaps} $(sed -nre 's,^keymap="([a-zA-Z].*)",\1,p' \ 245 | /etc/conf.d/keymaps)" 246 | fi 247 | 248 | case "${compressor}" in 249 | (none) ;; 250 | ([a-z]*) 251 | if [ -e /usr/src/linux-${kv}/.config ]; then 252 | config=/usr/src/linux-${kv}/.config 253 | xgrep=$(type -p grep 2>${null}) 254 | elif [ -e /proc/config.gz ]; then 255 | config=/proc/config.gz 256 | xgrep=$(type -p zgrep 2>${null}) 257 | else 258 | warn "No kernel config file found" 259 | fi 260 | esac 261 | if [ -f "${config}" ]; then 262 | comp="${compressor%% *}" 263 | CONFIG=CONFIG_RD_$(echo "${comp}" | tr '[a-z]' '[A-Z]') 264 | if ! ${xgrep} -q "^${CONFIG}=y" ${config} >${null} 2>&1; then 265 | warn "${comp} compressor is not supported by kernel-${kv}" 266 | for comp in bzip2 gzip lzip lzop lz4 xz; do 267 | CONFIG=CONFIG_RD_$(echo "${comp}" | tr '[a-z]' '[A-Z]') 268 | if ${xgrep} -q "^${CONFIG}=y" ${config}; then 269 | compressor="${comp} -9" 270 | info "Setting up compressor to ${comp}" 271 | break 272 | elif [ "${comp}" = "xz" ]; then 273 | warn "No suitable compressor support found in kernel-${kv}" 274 | compressor= 275 | fi 276 | done 277 | fi 278 | unset config xgrep CONFIG comp 279 | fi 280 | 281 | echo -e "${COLOR_BLU}>>>${COLOR_RST} Building ${initramfs}..." 282 | cd "${tmpdir}" || die "${tmpdir} not found" 283 | 284 | if [ -n "${rebuild}" ]; then 285 | cp -af "${usrdir}"/lib/${package}/functions lib/${package} && 286 | cp -af "${usrdir}"/../init . && chmod 775 init || die 287 | docpio 288 | echo -e "${COLOR_BLU}>>>${COLOR_RST} Regenerated ${initramfs}" 289 | exit 290 | else 291 | rm -fr * 292 | fi 293 | 294 | # Set up the initramfs 295 | if [ -d "${usrdir}" ]; then 296 | cp -ar "${usrdir}" . && 297 | mv -f usr/root usr/etc . && 298 | mv -f usr/lib lib${LONG_BIT} || die 299 | else 300 | die "${usrdir} usrdir not found" 301 | fi 302 | mkdir -p usr/share/consolefonts usr/share/keymaps usr/lib${LONG_BIT} \ 303 | usr/bin usr/sbin sbin bin dev proc sys newroot mnt/tok etc/${package} \ 304 | etc/splash run lib${LONG_BIT}/modules/${kv} lib${LONG_BIT}/${package} || die 305 | for dir in lib usr/lib; do 306 | ln -s lib${LONG_BIT} ${dir} 307 | done 308 | 309 | { 310 | for key in name shell version; do 311 | eval echo "${key}=\${$key}" 312 | done 313 | echo "build=$(date +%Y-%m-%d-%H-%M-%S)" 314 | } >${confdir}/id 315 | touch etc/fstab etc/mtab 316 | 317 | cp -a /dev/console /dev/random /dev/urandom /dev/mem /dev/null /dev/tty \ 318 | /dev/tty[0-6] /dev/zero dev/ || donod 319 | major="${kv%%.*}" minor="${kv#*.}" 320 | minor="${minor%%.*}" 321 | if [ "${major}" -eq 3 -a "${minor}" -ge 1 ]; then 322 | cp -a /dev/loop-control dev/ >$null 2>&1 || 323 | mknod -m 600 dev/loop-control c 10 237 || die 324 | fi 325 | unset major minor 326 | 327 | cp -a "${usrdir}"/../init . && chmod 775 init || die 328 | [ -d root ] && chmod 0700 root || mkdir -m 0700 root || die 329 | cp -af /lib/modules/${kv}/modules.dep lib/modules/${kv} || 330 | die "Failed to copy modules.dep" 331 | 332 | # Set up (requested) firmware 333 | if [ -n "${firmwares}" ]; then 334 | case "${firmwares}" in 335 | (:) 336 | warn "Adding the whole firmware directory" 337 | cp -a /lib/firmware lib 338 | ;; 339 | (*) 340 | mkdir -p lib/firmware 341 | for fw in ${firmwares}; do 342 | [ -e ${fw} ] && cp -a ${fw} lib/firmware || 343 | for fw in /lib/firmware/*${fw}*; do 344 | docp ${fw} 345 | done 346 | done 347 | ;; 348 | esac 349 | fi 350 | 351 | # Set up RAID option 352 | for bin in dmraid mdadm zfs; do 353 | case "${bins}" in 354 | (*${bin}*) module_group="${module_group} ${bin}";; 355 | esac 356 | done 357 | module_group="${module_group/mdadm/raid}" 358 | 359 | # Set up (requested) hook 360 | for hook in ${hooks}; do 361 | for file in "${usrdir}"/../hooks/*${hook}*; do 362 | cp -a "${file}" lib/${package}/ 363 | done 364 | if [ ${?} != 0 ]; then 365 | warn "No $hook hook/script does not exist" 366 | continue 367 | fi 368 | eval bins="\"${bins} \${bin_$hook}\"" 369 | module_group="${module_group} ${hook}" 370 | done 371 | 372 | [ -f /etc/issue.logo ] && cp /etc/issue.logo etc/ 373 | 374 | # Handle & copy BusyBox binary 375 | if [ -x usr/bin/busybox ]; then 376 | mv -f usr/bin/busybox bin/ 377 | elif type -p busybox >${null} 2>&1; then 378 | bb=$(type -p busybox 2>${null}) 379 | if ldd ${bb} >${null} 2>&1; then 380 | busybox --list-full >${confdir}/busybox.applets 381 | bins="${bb} ${bins}" 382 | warn "busybox is not a static binary" 383 | fi 384 | cp -a ${bb} bin/ 385 | unset bb 386 | else 387 | die "No busybox binary found" 388 | fi 389 | if [ ! -f ${confdir}/busybox.applets ]; then 390 | bin/busybox --list-full >${confdir}/busybox.applets || die 391 | fi 392 | while read bin; do 393 | grep -qsw ${bin} ${confdir}/busybox.applets || 394 | die "${bin} applet not found, no suitable busybox found" 395 | done <"${usrdir}"/../scripts/minimal.applets 396 | for bin in $(grep '^bin/' ${confdir}/busybox.applets); do 397 | ln -s busybox ${bin} 398 | done 399 | for bin in $(grep '^sbin/' ${confdir}/busybox.applets); do 400 | ln -s ../bin/busybox ${bin} 401 | done 402 | 403 | # Set up a few options 404 | if [ -n "${option_luks}" ]; then 405 | bins="${bins} cryptsetup" module_group="${module_group} dm-crypt" 406 | fi 407 | if [ -n "${opts_squashd}" ]; then 408 | bins="${bins} umount.aufs mount.aufs" module_group="${module_group} squashd" 409 | fi 410 | if [ -n "${opts_gpg}" ]; then 411 | if [ -x usr/bin/gpg ]; then :; 412 | elif [ "$(gpg --version | sed -nre '/^gpg/s/.* ([0-9]{1})\..*$/\1/p')" -eq 1 ]; then 413 | bins="${bins} $(type -p gpg 2>${null})" 414 | else 415 | die "No usable gpg/gnupg-1.4.x binary found" 416 | fi 417 | fi 418 | if [ -n "${option_lvm}" ]; then 419 | bins="${bins} lvm" module_group="${module_group} device-mapper" 420 | fi 421 | 422 | # Handle & copy keymap/consolefont 423 | for keymap in ${keymaps}; do 424 | if [ -f usr/share/keymaps/${keymap}-${ARCH}.bin ]; then 425 | :; 426 | elif [ -f "${keymap}" ]; then 427 | cp -a "${keymap}" usr/share/keymaps/ 428 | else 429 | loadkeys -b -u ${keymap} >usr/share/keymaps/${keymap}-${ARCH}.bin || 430 | die "Failed to build ${keymap} keymap" 431 | fi 432 | [ "${?}" = 0 ] && KEYMAPS="${KEYMAPS} ${keymap}-${ARCH}.bin" 433 | done 434 | for keymap in ${KEYMAPS}; do 435 | echo "${keymap}" >${confdir}/kmap 436 | break 437 | done 438 | 439 | for font in ${fonts}; do 440 | if [ -f usr/share/consolefonts/${font} ]; then :; 441 | elif [ -f ${font} ]; then 442 | cp -a ${font} usr/share/consolefonts/ 443 | else 444 | for file in /usr/share/consolefonts/${font}*.gz; do 445 | if [ -f ${file} ]; then 446 | cp ${file} . 447 | gzip -d ${file##*/} 448 | fi 449 | done 450 | mv ${font}* usr/share/consolefonts/ 451 | fi 452 | [ ${?} = 0 ] && FONTS="${FONTS} ${font}" 453 | done 454 | for font in ${FONTS}; do 455 | echo "${font}" >${confdir}/font 456 | break 457 | done 458 | unset FONTS font KEYMAPS keymap 459 | 460 | # Handle & copy splash themes 461 | if [ -n "${splash}" ]; then 462 | bins="${bins} splash_util.static fbcondecor_helper" 463 | 464 | if [ -n "${option_toi}" ]; then 465 | bins="${bins} tuxoniceui_text" && module_group="${module_group} tuxonice" 466 | fi 467 | for theme in ${splash}; do 468 | if [ -d etc/splash/${theme} ]; then :; 469 | elif [ -d /etc/splash/${theme} ]; then 470 | cp -r /etc/splash/${theme} etc/splash/ 471 | elif [ -d ${theme} ]; then 472 | cp -ar ${theme} etc/splash/ 473 | else 474 | warn "Failed to copy ${theme} theme" 475 | fi 476 | done 477 | fi 478 | 479 | # Handle & copy binaries 480 | for bin in ${bins}; do 481 | for b in usr/*bin/${bin} *bin/${bin}; do 482 | [ -x ${b} -a ! -h ${b} ] && continue 2 483 | done 484 | [ -x ${bin} ] && binary=${bin} || binary=$(type -p ${bin} 2>${null}) 485 | [ -n "${binary}" ] && dobin ${binary} || warn "no ${bin} binary found" 486 | done 487 | unset binary bin b 488 | 489 | # Handle & copy kernel module 490 | domod ${modules} 491 | 492 | for mod in ${module_boot}; do 493 | if eval [ -n \"\${module_$mod}\" ]; then 494 | echo "${mod}" >> ${confdir}/module-boot 495 | else 496 | mboot="${boot} ${mod}" 497 | fi 498 | done 499 | module_boot="${mboot}" 500 | unset mboot mod 501 | 502 | for group in ${module_group}; do 503 | eval domod -v ${confdir}/module-${group/_/-} \${module_${group/-/_}} 504 | done 505 | 506 | # Set up user environment if present 507 | for e in ${env}; do 508 | echo "${e}" >>${confdir}/env 509 | done 510 | unset e env 511 | 512 | # Handle GCC libraries 513 | for dir in $(sed -nre '/^\/.*gcc.*/p'); do 514 | if [ -e ${dir}/libgcc_s.so ]; then 515 | mkdir -p .${dir} 516 | cp ${dir}/libgcc_s.so* .${dir} 517 | fi 518 | done 519 | cp -ar /etc/ld.so.* etc 520 | echo >etc/ld.so.cache 521 | ldconfig -r "${tmpdir}" -f etc/ld.so.conf -C etc/ld.so.cache 522 | 523 | docpio 524 | [ -n "${option_tmpdir}" ] || rm -rf ${tmpdir} 525 | echo -e "${COLOR_GRN}>>>${COLOR_RST} Built ${initramfs} initramfs" 526 | 527 | # 528 | # vim:fenc=utf-8:ci:pi:sts=2:sw=2:ts=2: 529 | # 530 | -------------------------------------------------------------------------------- /usr/lib/mkinitramfs-ll/functions: -------------------------------------------------------------------------------- 1 | # 2 | # $Header: /lib/mkinitramfs-ll/functions Exp $ 3 | # $Author: (c) 2011-6 tokiclover Exp $ 4 | # $License: 2-clause/new/simplified BSD Exp $ 5 | # $Version: 0.22.2 2016/06/06 12:33:03 Exp $ 6 | # 7 | 8 | : ${COLUMNS:=80} 9 | 10 | # @FUNCTION: cut wrapper 11 | # @ARG: 12 | CUT() { 13 | eval "${1:-REPLY}=$(echo "$2" | cut -d$3 -f${4:-:} $5)" 14 | } 15 | 16 | # @FUNCTION: Print begin message to stdout 17 | # @ARG: 18 | begin() { 19 | local _msg="$*" 20 | printf "$print_eol" 21 | print_eol="\n" 22 | print_len=$((${#msg}+8+${#name})) 23 | 24 | local prefix="${name:+$color_fg_mag[$color_fg_blu$name$color_fg_mag]$color_rst}" 25 | printf "$prefix $@" 26 | } 27 | 28 | # @FUNCTION: Print end message to stdout 29 | # @ARG: [] 30 | end() { 31 | local ret="$1" suffix 32 | case "$1" in 33 | (0) suffix="$color_fg_blu[${color_fg_grn}ok$color_fg_blu]$color_rst";; 34 | (*) suffix="$color_fg_ylw[${color_fg_red}no$color_fg_ylw]$color_rst";; 35 | esac 36 | shift 37 | print_len=$(($COLUMNS-$print_len)) 38 | printf "%${print_len}s" "$*" 39 | printf "$suffix\n" 40 | print_eol= 41 | print_len=0 42 | return "$ret" 43 | } 44 | 45 | # @FUNCTION: Colors handler 46 | eval_colors() { 47 | [ -t 1 ] && yesno "${COLOR:-Yes}" || return 48 | 49 | local b='4' e='\e[' f='3' c 50 | for c in 0:blk 1:red 2:grn 3:ylw 4:blu 5:mag 6:cyn 7:wht; do 51 | eval color_bg_${c#*:}="'${e}1;${b}${c%:*}m'" 52 | eval color_fg_${c#*:}="'${e}1;${f}${c%:*}m'" 53 | eval color_bg_${c%:*}="'${e}${b}${c%:*}m'" 54 | eval color_fg_${c%:*}="'${e}${f}${c%:*}m'" 55 | done 56 | color_rst="${e}0m" 57 | color_bld="${e}1m" 58 | color_und="${e}4m" 59 | color_ita="${e}3m" 60 | } 61 | 62 | # @FUNCTION: Print message to stdout 63 | # @ARG: 64 | info() { 65 | local prefix="${name:+$color_fg_mag$name:$color_rst}" 66 | printf "$print_eol${color_fg_blu}INFO: $prefix $@\n" 67 | } 68 | 69 | # @FUNCTION: Print warn message to stdout 70 | # @ARG: 71 | warn() { 72 | local prefix="${name:+$color_fg_red$name:$color_rst}" 73 | printf "$print_eol${color_fg_ylw}WARN: $prefix $@\n" 74 | } 75 | 76 | # @FUNCTION: Print message to stderr 77 | # @ARG: 78 | error() { 79 | local prefix="${name:+$color_fg_ylw$name:$color_rst}" 80 | printf "$print_eol${color_fg_red}ERROR: $prefix $@\n" >&2 81 | } 82 | 83 | # @FUNCTION: Printing message handler 84 | # @ARG: [-e|-i|-c ] 85 | msg() { 86 | local _opt _msg _clr 87 | 88 | while [ $# -ge 1 ]; do 89 | case "$1" in 90 | (-e|-i) _opt="$1";; 91 | (-c) _opt="$1" _clr="$2"; shift;; 92 | (--) ;; 93 | (*) _msg="$*"; break;; 94 | esac 95 | shift 96 | done 97 | case "$_opt" in 98 | (-e) error "${_msg}";; 99 | (-i) info "${_msg}";; 100 | esac 101 | $splashd && debug splashd_cmd "set message $_msg" && debug splashd_cmd "repaint" 102 | } 103 | 104 | # @FUNCTION: Command exec handler 105 | # @ARG: [-d|-e|-i] 106 | debug() { 107 | local _cmd _opt _ret 108 | 109 | while [ $# -ge 1 ]; do 110 | case "$1" in 111 | (-d|-e|-i) _opt="$1";; 112 | (--) ;; 113 | (*) _cmd="$*"; break;; 114 | esac 115 | shift 116 | done 117 | eval "$@" 118 | _ret=$? 119 | echo "[$_ret]: $_cmd" >&3 120 | 121 | if [ ! "$_ret" ]; then 122 | case $_opt in 123 | (-d) die "${_msg:-cmd: $_cmd}";; 124 | (-e|-i) msg $_opt "${_msg:-cmd: $_cmd}";; 125 | esac 126 | fi 127 | return "$_ret" 128 | } 129 | 130 | # @FUNCTON: Rescue SHell helper 131 | rescue_shell() { 132 | if $splashd && [ "${CONSOLE#/dev/tty}" != "$CONSOLE" ]; then 133 | debug openvt -c${CONSOLE#/dev/tty} $SHELL -lim <$CONSOLE >$CONSOLE 2>&1 134 | elif check_bin setsid; then 135 | debug setsid $SHELL -lim <$CONSOLE >$CONSOLE 2>&1 136 | else 137 | debug $SHELL -lim <$CONSOLE >$CONSOLE 2>&1 138 | fi 139 | } 140 | 141 | # @FUNCTION: Yes or No helper 142 | yesno() { 143 | case "${1:-NO}" in 144 | (0|[Dd][Ii][Ss][Aa][Bb][Ll][Ee]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]|[Nn][Oo]) 145 | return 1;; 146 | (1|[Ee][Nn][Aa][Bb][Ll][Ee]|[Oo][Nn]|[Tt][Rr][Uu][Ee]|[Yy][Ee][Ss]) 147 | return 0;; 148 | (*) 149 | return 2;; 150 | esac 151 | } 152 | 153 | # @FUNCTION: Binary ChecK helper 154 | # @ARG: 155 | check_bin() { 156 | local _cmd 157 | for _cmd; do 158 | type -p $_cmd 1>$NULL 2>&1 || return 159 | done 160 | } 161 | 162 | # @FUNCTION: BusyBox Applets ChecK 163 | check_applet() { 164 | local _line _list=$confdir/busybox.applets 165 | [ -f $_list ] || busybox --list-full >$_list 166 | 167 | while read _line; do 168 | type -p ${_line##*/} >$NULL 2>&1 || ln -s /bin/busybox /$_line 169 | done <$_list 170 | } 171 | 172 | # @FUNCTION: Hook/Script execution helper 173 | # @ARG: 174 | dohook() { 175 | local line name="${1##*/}" 176 | set >/environ 177 | begin "exec: $1...\n" 178 | $SHELL -ace ". /environ; 179 | . $libdir/functions; 180 | . $libdir/helpers; 181 | exec 3>>$logfile; 182 | . $1; 183 | exit;" 184 | end "$?" 185 | 186 | if [ -f /run/env ]; then 187 | while read line; do 188 | eval "$line" 189 | done $CONSOLE 2>&1 194 | } 195 | 196 | # @FUNCTION: rmmod wrapper 197 | # @ARG: 198 | RMMOD() { 199 | if [ -f "$confdir/module-$1" ]; then 200 | while read _mod; do 201 | debug rmmod -q $_mod 202 | done <$confdir/module-$1 203 | else 204 | rmmod -q $* 205 | fi 206 | } 207 | 208 | # @FUNCTION: modprobe wrapper 209 | # @ARG: 210 | MODPROBE() { 211 | if [ -f "$confdir/module-$1" ]; then 212 | while read _mod; do 213 | debug modprobe -q $_mod 214 | done <$confdir/module-$1 215 | else 216 | modprobe -q $* 217 | fi 218 | } 219 | 220 | # @FUNCTION: Kernel cmdline handler 221 | # @ARG: 222 | get_cmdline_option() { 223 | local _arg _opt 224 | for _arg in $*; do 225 | for _cmd in $CMDLINE; do 226 | case "$_arg" in 227 | ("$_opt") eval "$_opt=enable"; break;; 228 | ("${_opt%%=*}") eval "$_opt" ; break;; 229 | esac 230 | done 231 | done 232 | } 233 | 234 | # @FUNCTION: Splash commands handler 235 | # @ARG: 236 | splashd_cmd() { 237 | echo "$@" >$splash_fifo 238 | } 239 | 240 | # @FUNCTION: Stop splash 241 | splashd_stop() { 242 | $splashd && splashd=false || return 243 | debug splashd_cmd "exit" 244 | CONSOLE=/dev/console 245 | exec <$CONSOLE >$CONSOLE 2>&1 246 | } 247 | 248 | # @FUNCTION: Read helper with Rescue Shell 249 | # @ARG: 250 | shread() { 251 | local _buffer 252 | 253 | while read _buffer; do 254 | case "$_buffer" in 255 | ([Rr][Ss][Hh]|[Ss][Hh]|[Ss][Hh][Ee][Ll][Ll]|[Rr][Ee][Ss][Cc][Uu][Ee]|[Ss][Hh]) 256 | die;; 257 | (*) eval "${1:-REPLY}='$_buffer'"; break;; 258 | esac 259 | done 260 | } 261 | 262 | # @FUNCTION: BLocK device handler 263 | # @ARG: 264 | blk() { 265 | local _asw _blk 266 | BLK() { 267 | _blk=$(blkid | sed -nre "\|${1#*=}|s|(^/dev/.*):.*$|\1|p") 268 | if [ -z "$_blk" ]; then 269 | if grep -sqw "$1" /proc/partitions; then 270 | _blk="/dev/$1" 271 | fi 272 | fi 273 | } 274 | BLK "$1" 275 | 276 | if ! [ -n "$_blk" -a -b "$_blk" ]; then 277 | msg -i "Insert $1 block device" 278 | sleep 1 279 | BLK "$1" 280 | fi 281 | while ! [ -n "$_blk" -a -b "$_blk" ]; do 282 | msg -i "Type in a valid block device e.g. \ 283 | [ sda5 | (PART)UUID= | (PART)LABEL=