fix bugs, rethink eudev mode, improve code quality
This commit is contained in:
parent
d1631da402
commit
609afb52d9
29
README.md
29
README.md
@ -9,26 +9,25 @@ Features
|
|||||||
- No `local`'s, no bashisms, only POSIX shell
|
- No `local`'s, no bashisms, only POSIX shell
|
||||||
- Easy configuration
|
- Easy configuration
|
||||||
- mdev, mdevd, eudev
|
- mdev, mdevd, eudev
|
||||||
- LUKS
|
- LUKS, LVM
|
||||||
- LVM
|
- LUKS detached header and key embedded into initramfs
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
* POSIX utilities ( find, mkdir, ... )
|
||||||
* POSIX shell
|
* POSIX shell
|
||||||
* POSIX utilities
|
|
||||||
* `switch_root`
|
* `switch_root`
|
||||||
* `readlink`
|
* `readlink`
|
||||||
* `install`
|
* `install`
|
||||||
* `setsid`
|
* `setsid`
|
||||||
* `mount`
|
* `mount`
|
||||||
|
* `blkid`
|
||||||
* `cpio`
|
* `cpio`
|
||||||
* `gzip`
|
|
||||||
- Required by default
|
|
||||||
* `strip`
|
* `strip`
|
||||||
- Optional
|
- Optional
|
||||||
* `blkid`
|
* `gzip`
|
||||||
- Required for mdev/mdevd
|
- Required by default
|
||||||
* `mdev` OR `mdevd` OR `eudev`
|
* `mdev` OR `mdevd` OR `eudev`
|
||||||
- systemd-udevd not tested
|
- systemd-udevd not tested
|
||||||
* `lvm2`
|
* `lvm2`
|
||||||
@ -36,17 +35,19 @@ Dependencies
|
|||||||
* `cryptsetup`
|
* `cryptsetup`
|
||||||
- Required for LUKS support
|
- Required for LUKS support
|
||||||
* `kmod` OR `busybox modutils` with [this patch](https://gist.github.com/illiliti/ef9ee781b5c6bf36d9493d99b4a1ffb6) (already included in KISS Linux)
|
* `kmod` OR `busybox modutils` with [this patch](https://gist.github.com/illiliti/ef9ee781b5c6bf36d9493d99b4a1ffb6) (already included in KISS Linux)
|
||||||
- Not required for monolithic kernel (builtin modules)
|
- Not required for monolithic kernel
|
||||||
|
|
||||||
Notes
|
Notes
|
||||||
-----
|
-----
|
||||||
|
|
||||||
* busybox and toybox blkid doesn't support PARTUUID
|
* busybox modutils doesn't handle soft dependencies (modules.softdep). You must manually include them using `modules` config option
|
||||||
* zsh (in POSIX mode) showing some errors, but working fine
|
* busybox and toybox blkid doesn't support PARTUUID. You must use util-linux blkid
|
||||||
* cp -P is broken in toybox, see [here](https://github.com/landley/toybox/issues/174)
|
* zsh (in POSIX mode) shows some errors in init stage. Just ignore these errors, it's harmless
|
||||||
|
* `cp` in toybox incorrectly handles `-P` flag. You need to apply patch from [this issue](https://github.com/landley/toybox/issues/174) or replace cp with another implementation
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git clone https://github.com/illiliti/tinyramfs
|
git clone https://github.com/illiliti/tinyramfs
|
||||||
cd tinyramfs
|
cd tinyramfs
|
||||||
@ -74,12 +75,12 @@ usage: tinyramfs [option]
|
|||||||
Configuration
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Static via config
|
Statically via config
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
See [config](config)
|
See [config](config)
|
||||||
|
|
||||||
Dynamic via kernel parameters
|
Dynamically via kernel parameters
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
TODO finalize and document kernel command-line parameters
|
TODO finalize and document kernel command-line parameters
|
||||||
@ -87,7 +88,7 @@ TODO finalize and document kernel command-line parameters
|
|||||||
Thanks
|
Thanks
|
||||||
------
|
------
|
||||||
|
|
||||||
[E5ten](https://github.com/E5ten)
|
[E5ten](https://github.com/E5ten)
|
||||||
[dylanaraps](https://github.com/dylanaraps)
|
[dylanaraps](https://github.com/dylanaraps)
|
||||||
|
|
||||||
License
|
License
|
||||||
|
19
config
19
config
@ -4,12 +4,14 @@
|
|||||||
# uncomment and fill settings which you needed
|
# uncomment and fill settings which you needed
|
||||||
|
|
||||||
# debug mode
|
# debug mode
|
||||||
|
# default - 0
|
||||||
#
|
#
|
||||||
#debug=0
|
#debug=0|1
|
||||||
|
|
||||||
# overwrite initramfs
|
# overwrite initramfs
|
||||||
|
# default - 0
|
||||||
#
|
#
|
||||||
#force=0
|
#force=0|1
|
||||||
|
|
||||||
# initramfs output path
|
# initramfs output path
|
||||||
#
|
#
|
||||||
@ -19,9 +21,11 @@
|
|||||||
#output=""
|
#output=""
|
||||||
|
|
||||||
# monolithic kernel
|
# monolithic kernel
|
||||||
|
#
|
||||||
|
# default - 0
|
||||||
# enable this if you have monolithic kernel (builtin modules)
|
# enable this if you have monolithic kernel (builtin modules)
|
||||||
#
|
#
|
||||||
#monolith=0
|
#monolith=0|1
|
||||||
|
|
||||||
# modules directory
|
# modules directory
|
||||||
#
|
#
|
||||||
@ -51,6 +55,7 @@
|
|||||||
# supported - PARTUUID, DEVICE, LABEL, UUID
|
# supported - PARTUUID, DEVICE, LABEL, UUID
|
||||||
# example -
|
# example -
|
||||||
# root="/dev/sda1"
|
# root="/dev/sda1"
|
||||||
|
# root="/dev/dm-0"
|
||||||
# root="PARTUUID=35f923c5-083a-4950-a4da-e611d0778121"
|
# root="PARTUUID=35f923c5-083a-4950-a4da-e611d0778121"
|
||||||
#
|
#
|
||||||
#root=""
|
#root=""
|
||||||
@ -77,7 +82,7 @@
|
|||||||
# dramatically reduce initramfs size
|
# dramatically reduce initramfs size
|
||||||
# useful only for modular kernels
|
# useful only for modular kernels
|
||||||
#
|
#
|
||||||
#hostonly=0
|
#hostonly=0|1
|
||||||
|
|
||||||
# additional modules
|
# additional modules
|
||||||
# example - modules="fat crc32c_generic"
|
# example - modules="fat crc32c_generic"
|
||||||
@ -95,8 +100,9 @@
|
|||||||
#binaries=""
|
#binaries=""
|
||||||
|
|
||||||
# LVM support
|
# LVM support
|
||||||
|
# default - 0
|
||||||
#
|
#
|
||||||
#lvm=0
|
#lvm=0|1
|
||||||
|
|
||||||
# LVM options
|
# LVM options
|
||||||
#
|
#
|
||||||
@ -116,8 +122,9 @@
|
|||||||
#lvm_opts=""
|
#lvm_opts=""
|
||||||
|
|
||||||
# LUKS support
|
# LUKS support
|
||||||
|
# default - 0
|
||||||
#
|
#
|
||||||
#luks=0
|
#luks=0|1
|
||||||
|
|
||||||
# LUKS encrypted root
|
# LUKS encrypted root
|
||||||
#
|
#
|
||||||
|
@ -7,34 +7,39 @@ create_symlink()
|
|||||||
sym="$1"
|
sym="$1"
|
||||||
sym="${sym%\"}"
|
sym="${sym%\"}"
|
||||||
sym="${sym#\"}"
|
sym="${sym#\"}"
|
||||||
sym="${dir}${sym}"
|
sym="${dir}/${sym}"
|
||||||
|
|
||||||
mkdir -p "$dir" 2> /dev/null
|
mkdir -p "$dir"
|
||||||
ln -s "/dev/${MDEV}" "$sym" 2> /dev/null
|
ln -s "/dev/${dev_name}" "$sym"
|
||||||
}
|
}
|
||||||
|
|
||||||
# int main()
|
# int main()
|
||||||
{
|
{
|
||||||
[ "$MDEV" ] || exit 1
|
exec > /dev/null 2>&1
|
||||||
|
|
||||||
for line in $(blkid "$MDEV"); do case "${line%%=*}" in
|
[ "${dev_name=${DEVPATH##*/}}" ] || exit 1
|
||||||
|
|
||||||
|
# avoid race condition
|
||||||
|
while ! blkid "/dev/${dev_name}"; do sleep 1; done
|
||||||
|
|
||||||
|
for line in $(blkid "/dev/${dev_name}"); do case "${line%%=*}" in
|
||||||
UUID)
|
UUID)
|
||||||
dir="/dev/disk/by-uuid/"
|
dir=/dev/disk/by-uuid
|
||||||
create_symlink "${line##*=}"
|
create_symlink "${line##*=}"
|
||||||
;;
|
;;
|
||||||
LABEL)
|
LABEL)
|
||||||
dir="/dev/disk/by-label/"
|
dir=/dev/disk/by-label
|
||||||
create_symlink "${line##*=}"
|
create_symlink "${line##*=}"
|
||||||
;;
|
;;
|
||||||
PARTUUID)
|
PARTUUID)
|
||||||
dir="/dev/disk/by-partuuid/"
|
dir=/dev/disk/by-partuuid
|
||||||
create_symlink "${line##*=}"
|
create_symlink "${line##*=}"
|
||||||
;;
|
;;
|
||||||
esac; done
|
esac; done
|
||||||
|
|
||||||
[ -e "/sys/block/${MDEV}/dm/name" ] && {
|
[ -e "/sys/block/${dev_name}/dm/name" ] && {
|
||||||
mkdir -p /dev/mapper 2> /dev/null
|
mkdir -p /dev/mapper
|
||||||
read -r name < "/sys/block/${MDEV}/dm/name"
|
read -r dm_name < "/sys/block/${dev_name}/dm/name"
|
||||||
ln -s "/dev/${MDEV}" "/dev/mapper/${name}" 2> /dev/null
|
ln -s "/dev/${dev_name}" "/dev/mapper/${dm_name}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
104
init
104
init
@ -10,13 +10,14 @@
|
|||||||
|
|
||||||
print()
|
print()
|
||||||
{
|
{
|
||||||
printf "%b %s\n" "${2:-\033[1;37m>>\033[m}" "$1"
|
printf "%b %s\n" "${2:-"\033[1;37m>>\033[m"}" "$1"
|
||||||
shell
|
|
||||||
}
|
}
|
||||||
|
|
||||||
panic()
|
panic()
|
||||||
{
|
{
|
||||||
print "$1" "\033[1;31m!!\033[m" >&2
|
print "${1:-unexpected error occurred}" \
|
||||||
|
"\033[1;31m!!\033[m" >&2
|
||||||
|
|
||||||
shell
|
shell
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ shell()
|
|||||||
|
|
||||||
findfs()
|
findfs()
|
||||||
{
|
{
|
||||||
value=0; device=
|
count=0; device=
|
||||||
|
|
||||||
case "${1%%=*}" in
|
case "${1%%=*}" in
|
||||||
/dev/*)
|
/dev/*)
|
||||||
@ -47,42 +48,52 @@ findfs()
|
|||||||
|
|
||||||
# avoid race condition
|
# avoid race condition
|
||||||
while [ ! -e "$device" ]; do
|
while [ ! -e "$device" ]; do
|
||||||
[ "$value" = 30 ] && panic "failed to lookup partition"
|
sleep 1; : $(( count += 1 ))
|
||||||
value=$(( value + 1 )); sleep 1
|
|
||||||
done
|
[ "$count" = 30 ] && {
|
||||||
|
panic "failed to lookup partition"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done || :
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_environment()
|
prepare_environment()
|
||||||
{
|
{
|
||||||
. /etc/config
|
. /etc/tinyramfs/config
|
||||||
|
|
||||||
export \
|
export \
|
||||||
SHELL=/bin/sh \
|
LANG=C \
|
||||||
TERM=linux \
|
|
||||||
HOME=/root \
|
|
||||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
|
|
||||||
PS1="# " \
|
PS1="# " \
|
||||||
LC_ALL=C \
|
LC_ALL=C \
|
||||||
LANG=C \
|
TERM=linux \
|
||||||
OLD_IFS="$IFS"
|
HOME=/root \
|
||||||
|
SHELL=/bin/sh \
|
||||||
|
OLD_IFS="$IFS" \
|
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
||||||
|
|
||||||
# fix for ubase mount
|
# fix for ubase mount
|
||||||
:> /etc/fstab
|
: > /etc/fstab
|
||||||
|
|
||||||
mount -t proc -o nosuid,noexec,nodev proc /proc
|
mount -t proc -o nosuid,noexec,nodev proc /proc
|
||||||
mount -t sysfs -o nosuid,noexec,nodev sys /sys
|
mount -t sysfs -o nosuid,noexec,nodev sys /sys
|
||||||
|
mount -t tmpfs -o nosuid,nodev,mode=0755 run /run
|
||||||
mount -t devtmpfs -o nosuid,noexec,mode=0755 dev /dev
|
mount -t devtmpfs -o nosuid,noexec,mode=0755 dev /dev
|
||||||
|
|
||||||
ln -s /proc/self/fd /dev/fd
|
mkdir -p \
|
||||||
ln -s /proc/self/fd/0 /dev/stdin
|
/run/cryptsetup \
|
||||||
ln -s /proc/self/fd/1 /dev/stdout
|
/run/lock \
|
||||||
ln -s /proc/self/fd/2 /dev/stderr
|
/run/lvm
|
||||||
|
|
||||||
trap 'panic "something went wrong"' EXIT
|
ln -s /proc/self/fd /dev/fd
|
||||||
|
ln -s fd/0 /dev/stdin
|
||||||
|
ln -s fd/1 /dev/stdout
|
||||||
|
ln -s fd/2 /dev/stderr
|
||||||
|
|
||||||
# false positive
|
trap panic EXIT
|
||||||
# shellcheck disable=2015
|
|
||||||
[ "$modules" ] && modprobe -a "$modules" 2> /dev/null ||:
|
[ "$modules" ] || return 0
|
||||||
|
|
||||||
|
modprobe -a "$modules"
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_cmdline()
|
parse_cmdline()
|
||||||
@ -107,32 +118,35 @@ parse_cmdline()
|
|||||||
: no operation
|
: no operation
|
||||||
;;
|
;;
|
||||||
*=*)
|
*=*)
|
||||||
export "$line"
|
export "$line" || :
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
export "${line}=1"
|
export "${line}=1" || :
|
||||||
;;
|
;;
|
||||||
esac; done
|
esac; done
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_devmgr()
|
setup_devmgr()
|
||||||
{
|
{
|
||||||
[ "$break" = devmgr ] && print "break before setup device manager"
|
[ "$break" = devmgr ] && { print "break before setup_devmgr()"; shell; }
|
||||||
|
|
||||||
case "$devmgr" in
|
case "$devmgr" in
|
||||||
udev)
|
udev)
|
||||||
udevd -d -N never
|
udevd -dN never
|
||||||
udevadm trigger -c add -t subsystems
|
udevadm trigger -c add -t subsystems
|
||||||
udevadm trigger -c add -t devices
|
udevadm trigger -c add -t devices
|
||||||
udevadm settle
|
udevadm settle
|
||||||
;;
|
;;
|
||||||
mdev)
|
mdev)
|
||||||
mdev -df 2> /dev/null & mdev_pid="$!"
|
mdev -df 2> /dev/null & mdev_pid="$!"
|
||||||
|
mdev -s
|
||||||
|
|
||||||
[ "$monolith" != 1 ] && {
|
[ "$monolith" = 1 ] && return 0
|
||||||
set -- $(find /sys -name modalias -type f -exec sort -u {} +)
|
|
||||||
modprobe -a "$@" 2> /dev/null ||:
|
# TODO maybe replace sort using while-read loop
|
||||||
}
|
# while-read can cause slowdown, so why i'm unsure
|
||||||
|
set -- $(find /sys -name modalias -type f -exec sort -u {} +)
|
||||||
|
modprobe -a "$@" 2> /dev/null || :
|
||||||
;;
|
;;
|
||||||
mdevd)
|
mdevd)
|
||||||
mdevd 2> /dev/null & mdevd_pid="$!"
|
mdevd 2> /dev/null & mdevd_pid="$!"
|
||||||
@ -143,7 +157,7 @@ setup_devmgr()
|
|||||||
|
|
||||||
unlock_luks()
|
unlock_luks()
|
||||||
{
|
{
|
||||||
[ "$break" = luks ] && print "break before unlock LUKS"
|
[ "$break" = luks ] && { print "break before unlock_luks()"; shell; }
|
||||||
|
|
||||||
{ IFS=,; set -- $luks_opts; IFS="$OLD_IFS"; }
|
{ IFS=,; set -- $luks_opts; IFS="$OLD_IFS"; }
|
||||||
|
|
||||||
@ -165,7 +179,6 @@ unlock_luks()
|
|||||||
findfs "$luks_root"
|
findfs "$luks_root"
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"--disable-locks" \
|
|
||||||
"$luks_key" "$luks_header" \
|
"$luks_key" "$luks_header" \
|
||||||
"$luks_discard" "$device" \
|
"$luks_discard" "$device" \
|
||||||
"${luks_name:-luks-${device##*/}}"
|
"${luks_name:-luks-${device##*/}}"
|
||||||
@ -175,7 +188,7 @@ unlock_luks()
|
|||||||
|
|
||||||
trigger_lvm()
|
trigger_lvm()
|
||||||
{
|
{
|
||||||
[ "$break" = lvm ] && print "break before trigger LVM"
|
[ "$break" = lvm ] && { print "break before trigger_lvm()"; shell; }
|
||||||
|
|
||||||
{ IFS=,; set -- $lvm_opts; IFS="$OLD_IFS"; }
|
{ IFS=,; set -- $lvm_opts; IFS="$OLD_IFS"; }
|
||||||
|
|
||||||
@ -184,7 +197,7 @@ trigger_lvm()
|
|||||||
lvm_discard="--config=devices{issue_discards=1}"
|
lvm_discard="--config=devices{issue_discards=1}"
|
||||||
;;
|
;;
|
||||||
config=0)
|
config=0)
|
||||||
:> /etc/lvm/lvm.conf
|
: > /etc/lvm/lvm.conf
|
||||||
;;
|
;;
|
||||||
group=*)
|
group=*)
|
||||||
lvm_group="${opt##*=}"
|
lvm_group="${opt##*=}"
|
||||||
@ -197,22 +210,22 @@ trigger_lvm()
|
|||||||
;;
|
;;
|
||||||
esac; done
|
esac; done
|
||||||
|
|
||||||
set -- "--sysinit" "-qq" "-ay" "$lvm_discard"
|
set -- "--sysinit" "-qq" "-aay" "$lvm_discard"
|
||||||
|
|
||||||
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
|
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
|
||||||
lvchange $@ "${lvm_group}${lvm_name}"
|
lvm lvchange $@ "${lvm_group}${lvm_name}"
|
||||||
elif [ "$lvm_group" ]; then
|
elif [ "$lvm_group" ]; then
|
||||||
vgchange $@ "$lvm_group"
|
lvm vgchange $@ "$lvm_group"
|
||||||
elif [ "$lvm_tag" ]; then
|
elif [ "$lvm_tag" ]; then
|
||||||
lvchange $@ "$lvm_tag"
|
lvm lvchange $@ "$lvm_tag"
|
||||||
else
|
else
|
||||||
vgchange $@
|
lvm vgchange $@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
mount_root()
|
mount_root()
|
||||||
{
|
{
|
||||||
[ "$break" = root ] && print "break before mount root"
|
[ "$break" = root ] && { print "break before mount_root()"; shell; }
|
||||||
|
|
||||||
findfs "$root"
|
findfs "$root"
|
||||||
|
|
||||||
@ -226,7 +239,7 @@ mount_root()
|
|||||||
|
|
||||||
cleanup()
|
cleanup()
|
||||||
{
|
{
|
||||||
[ "$break" = cleanup ] && print "break before cleanup"
|
[ "$break" = cleanup ] && { print "break before cleanup()"; shell; }
|
||||||
|
|
||||||
case "$devmgr" in
|
case "$devmgr" in
|
||||||
udev) udevadm control -e ;;
|
udev) udevadm control -e ;;
|
||||||
@ -236,14 +249,15 @@ cleanup()
|
|||||||
|
|
||||||
# temporary workaround until util-linux release a new version
|
# temporary workaround until util-linux release a new version
|
||||||
# see https://github.com/karelzak/util-linux/issues/997
|
# see https://github.com/karelzak/util-linux/issues/997
|
||||||
for dir in dev sys proc; do
|
for dir in /run /dev /sys /proc; do
|
||||||
mount -o move "$dir" "/mnt/root/${dir}" || mount --move "$dir" "/mnt/root/${dir}"
|
mount -o move "$dir" "/mnt/root/${dir}" ||
|
||||||
|
mount --move "$dir" "/mnt/root/${dir}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_system()
|
boot_system()
|
||||||
{
|
{
|
||||||
[ "$break" = boot ] && print "break before boot system"
|
[ "$break" = boot ] && { print "break before boot_system()"; shell; }
|
||||||
|
|
||||||
set -- "/mnt/root" "${init:-/sbin/init}"
|
set -- "/mnt/root" "${init:-/sbin/init}"
|
||||||
exec switch_root $@ 2> /dev/null || panic "failed to boot system"
|
exec switch_root $@ 2> /dev/null || panic "failed to boot system"
|
||||||
|
418
tinyramfs
418
tinyramfs
@ -7,12 +7,14 @@
|
|||||||
|
|
||||||
print()
|
print()
|
||||||
{
|
{
|
||||||
printf "%b %s\n" "${2:-\033[1;37m>>\033[m}" "$1"
|
printf "%b %s\n" "${2:-"\033[1;37m>>\033[m"}" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
panic()
|
panic()
|
||||||
{
|
{
|
||||||
print "$1" "\033[1;31m!!\033[m" >&2
|
print "${1:-unexpected error occurred}" \
|
||||||
|
"\033[1;31m!!\033[m" >&2
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,13 +22,13 @@ usage()
|
|||||||
{
|
{
|
||||||
cat << EOF
|
cat << EOF
|
||||||
usage: $0 [option]
|
usage: $0 [option]
|
||||||
-o, --output <file> set initramfs output path
|
-o, --output <file> set initramfs output path
|
||||||
-c, --config <file> set config file path
|
-c, --config <file> set config file path
|
||||||
-m, --moddir <dir> set modules directory
|
-m, --moddir <dir> set modules directory
|
||||||
-k, --kernel <ver> set kernel version
|
-k, --kernel <ver> set kernel version
|
||||||
-F, --files <dir> set files directory
|
-F, --files <dir> set files directory
|
||||||
-d, --debug enable debug mode
|
-d, --debug enable debug mode
|
||||||
-f, --force overwrite initramfs image
|
-f, --force overwrite initramfs image
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@ -35,41 +37,33 @@ parse_args()
|
|||||||
{
|
{
|
||||||
while [ "$1" ]; do case "$1" in
|
while [ "$1" ]; do case "$1" in
|
||||||
-o | --output)
|
-o | --output)
|
||||||
_output="${2:?}"
|
_output="${2:?}"; shift 2
|
||||||
shift 2
|
|
||||||
;;
|
;;
|
||||||
-c | --config)
|
-c | --config)
|
||||||
_config="${2:?}"
|
_config="${2:?}"; shift 2
|
||||||
shift 2
|
|
||||||
;;
|
;;
|
||||||
-m | --moddir)
|
-m | --moddir)
|
||||||
_moddir="${2:?}"
|
_moddir="${2:?}"; shift 2
|
||||||
shift 2
|
|
||||||
;;
|
;;
|
||||||
-k | --kernel)
|
-k | --kernel)
|
||||||
_kernel="${2:?}"
|
_kernel="${2:?}"; shift 2
|
||||||
shift 2
|
|
||||||
;;
|
;;
|
||||||
-F | --files)
|
-F | --files)
|
||||||
_filesdir="${2:?}"
|
_filesdir="${2:?}"; shift 2
|
||||||
shift 2
|
|
||||||
;;
|
;;
|
||||||
-d | --debug)
|
-d | --debug)
|
||||||
_debug=1
|
_debug=1; shift 1
|
||||||
shift 1
|
|
||||||
;;
|
;;
|
||||||
-f | --force)
|
-f | --force)
|
||||||
_force=1
|
_force=1; shift 1
|
||||||
shift 1
|
|
||||||
;;
|
;;
|
||||||
-h | --help)
|
-h | --help)
|
||||||
usage
|
usage; exit 0
|
||||||
exit 0
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf "invalid option: %s\n\n" "$1"
|
printf "invalid option: %s\n\n" "$1"
|
||||||
usage
|
|
||||||
exit 1
|
usage; exit 1
|
||||||
;;
|
;;
|
||||||
esac; done
|
esac; done
|
||||||
}
|
}
|
||||||
@ -80,11 +74,11 @@ prepare_environment()
|
|||||||
|
|
||||||
# false positive
|
# false positive
|
||||||
# shellcheck disable=1090
|
# shellcheck disable=1090
|
||||||
for _file in $_config /etc/tinyramfs/config ./config; do
|
for _file in $_config /etc/tinyramfs/config; do
|
||||||
[ -f "$_file" ] && { . "$_file"; break; }
|
[ -f "$_file" ] && { . "$_file"; break; }
|
||||||
done || panic "failed to source config"
|
done || panic "failed to source config"
|
||||||
|
|
||||||
for _dir in $_filesdir /usr/share/tinyramfs .; do
|
for _dir in $_filesdir /usr/share/tinyramfs; do
|
||||||
[ -d "$_dir" ] && { filesdir="$_dir"; break; }
|
[ -d "$_dir" ] && { filesdir="$_dir"; break; }
|
||||||
done || panic "failed to locate required files"
|
done || panic "failed to locate required files"
|
||||||
|
|
||||||
@ -95,8 +89,7 @@ prepare_environment()
|
|||||||
kernel="${_kernel:-${kernel:-$(uname -r)}}"
|
kernel="${_kernel:-${kernel:-$(uname -r)}}"
|
||||||
output="${_output:-${output:-/tmp/initramfs-${kernel}}}"
|
output="${_output:-${output:-/tmp/initramfs-${kernel}}}"
|
||||||
|
|
||||||
mkdir -p "${workdir=${XDG_CACHE_HOME:-${TMPDIR:-/tmp}}/initramfs.$$}" ||
|
mkdir -p "${workdir=${XDG_CACHE_HOME:-${TMPDIR:-/tmp}}/initramfs.$$}"
|
||||||
panic "failed to create working directory"
|
|
||||||
|
|
||||||
# helpers variables
|
# helpers variables
|
||||||
workdirbin="${workdir}/usr/bin/"
|
workdirbin="${workdir}/usr/bin/"
|
||||||
@ -104,48 +97,49 @@ prepare_environment()
|
|||||||
modker="${moddir}/${kernel}"
|
modker="${moddir}/${kernel}"
|
||||||
OLD_IFS="$IFS"
|
OLD_IFS="$IFS"
|
||||||
|
|
||||||
trap trap_helper EXIT INT
|
[ "$debug" = 1 ] && set -x || trap trap_helper EXIT INT
|
||||||
|
|
||||||
# false positive
|
|
||||||
# shellcheck disable=2015
|
|
||||||
[ "$debug" = 1 ] && set -x ||:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trap_helper()
|
trap_helper()
|
||||||
{
|
{
|
||||||
# TODO need cleanup
|
[ "${ret=$?}" = 0 ] ||
|
||||||
ret="$?"
|
print "unexpected error occurred" \
|
||||||
|
"\033[1;31m!!\033[m" >&2
|
||||||
|
|
||||||
trap - EXIT INT
|
print "removing working directory"; rm -rf "$workdir"
|
||||||
|
exit "$ret"
|
||||||
|
}
|
||||||
|
|
||||||
[ "$debug" != 1 ] && {
|
populate_config() {
|
||||||
print "removing working directory"
|
printf "%s\n" "$@" >> "${workdir}/etc/tinyramfs/config"
|
||||||
rm -rf "$workdir"
|
|
||||||
}
|
|
||||||
|
|
||||||
[ "$ret" != 0 ] && panic "something went wrong"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_requirements()
|
install_requirements()
|
||||||
{
|
{
|
||||||
print "installing requirements"
|
print "installing requirements"
|
||||||
|
|
||||||
# install user specified and required binaries
|
# install required binaries
|
||||||
for _binary in \[ sh ln sleep mount printf setsid switch_root $binaries; do
|
for _binary in \[ sh ln mkdir blkid \
|
||||||
|
sleep mount printf setsid \
|
||||||
|
switch_root "${filesdir}/device-helper"
|
||||||
|
do
|
||||||
install_binary "$_binary"
|
install_binary "$_binary"
|
||||||
done
|
done
|
||||||
|
|
||||||
# copy init
|
# install user specified binaries
|
||||||
|
for _binary in $binaries; do
|
||||||
|
install_binary "$_binary"
|
||||||
|
done
|
||||||
|
|
||||||
|
# install init
|
||||||
install -m755 "${filesdir}/init" "${workdir}/init"
|
install -m755 "${filesdir}/init" "${workdir}/init"
|
||||||
|
|
||||||
# copy config
|
populate_config \
|
||||||
printf "%s\n" \
|
"root='$root'" \
|
||||||
root="$root" \
|
"devmgr='$devmgr'" \
|
||||||
root_type="$root_type" \
|
"monolith='$monolith'" \
|
||||||
root_opts="$root_opts" \
|
"root_type='$root_type'" \
|
||||||
devmgr="$devmgr" \
|
"root_opts='$root_opts'"
|
||||||
monolith="$monolith" \
|
|
||||||
>> "${workdir}/etc/config"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create_structure()
|
create_structure()
|
||||||
@ -153,15 +147,17 @@ create_structure()
|
|||||||
print "creating directory structure"
|
print "creating directory structure"
|
||||||
|
|
||||||
mkdir -p \
|
mkdir -p \
|
||||||
"${workdir}/etc" \
|
|
||||||
"${workdir}/dev" \
|
"${workdir}/dev" \
|
||||||
"${workdir}/sys" \
|
"${workdir}/sys" \
|
||||||
"${workdir}/tmp" \
|
"${workdir}/tmp" \
|
||||||
|
"${workdir}/run" \
|
||||||
|
"${workdir}/var" \
|
||||||
"${workdir}/proc" \
|
"${workdir}/proc" \
|
||||||
"${workdir}/root" \
|
"${workdir}/root" \
|
||||||
"${workdir}/usr/lib" \
|
"${workdir}/usr/lib" \
|
||||||
"${workdir}/usr/bin" \
|
"${workdir}/usr/bin" \
|
||||||
"${workdir}/mnt/root"
|
"${workdir}/mnt/root" \
|
||||||
|
"${workdir}/etc/tinyramfs"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_symlinks()
|
create_symlinks()
|
||||||
@ -172,6 +168,8 @@ create_symlinks()
|
|||||||
ln -s usr/lib "${workdir}/lib64"
|
ln -s usr/lib "${workdir}/lib64"
|
||||||
ln -s usr/bin "${workdir}/bin"
|
ln -s usr/bin "${workdir}/bin"
|
||||||
ln -s usr/bin "${workdir}/sbin"
|
ln -s usr/bin "${workdir}/sbin"
|
||||||
|
ln -s ../run "${workdir}/var/run"
|
||||||
|
ln -s ../run/lock "${workdir}/var/lock"
|
||||||
ln -s bin "${workdir}/usr/sbin"
|
ln -s bin "${workdir}/usr/sbin"
|
||||||
ln -s lib "${workdir}/usr/lib64"
|
ln -s lib "${workdir}/usr/lib64"
|
||||||
}
|
}
|
||||||
@ -180,55 +178,57 @@ install_devmgr()
|
|||||||
{
|
{
|
||||||
print "installing device manager"
|
print "installing device manager"
|
||||||
|
|
||||||
install_device_helper()
|
|
||||||
{
|
|
||||||
for _binary in kill mkdir blkid "${filesdir}/device-helper"; do
|
|
||||||
install_binary "$_binary"
|
|
||||||
done
|
|
||||||
|
|
||||||
printf "%s\n" \
|
|
||||||
'SUBSYSTEM=block;.* 0:0 660 @device-helper' \
|
|
||||||
> "${workdir}/etc/mdev.conf"
|
|
||||||
|
|
||||||
# false positive
|
|
||||||
# shellcheck disable=2016
|
|
||||||
[ "$monolith" != 1 ] && printf "%s\n" \
|
|
||||||
'$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \
|
|
||||||
>> "${workdir}/etc/mdev.conf"
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO investigate booting without device manager
|
|
||||||
case "$devmgr" in
|
case "$devmgr" in
|
||||||
|
none)
|
||||||
|
# TODO implement device-manager-less mode using deprecated
|
||||||
|
# /sys/kernel/uevent_helper or /proc/sys/kernel/hotplug
|
||||||
|
;;
|
||||||
|
mdev)
|
||||||
|
for _binary in kill mdev; do
|
||||||
|
install_binary "$_binary"
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "%s\n" \
|
||||||
|
'SUBSYSTEM=block;.* 0:0 660 @device-helper' \
|
||||||
|
> "${workdir}/etc/mdev.conf"
|
||||||
|
|
||||||
|
[ "$monolith" = 1 ] && return 0
|
||||||
|
|
||||||
|
printf "%s\n" \
|
||||||
|
'$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \
|
||||||
|
>> "${workdir}/etc/mdev.conf"
|
||||||
|
;;
|
||||||
|
mdevd)
|
||||||
|
for _binary in kill mdevd mdevd-coldplug; do
|
||||||
|
install_binary "$_binary"
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "%s\n" \
|
||||||
|
'SUBSYSTEM=block;.* 0:0 660 @device-helper' \
|
||||||
|
> "${workdir}/etc/mdev.conf"
|
||||||
|
|
||||||
|
[ "$monolith" = 1 ] && return 0
|
||||||
|
|
||||||
|
printf "%s\n" \
|
||||||
|
'$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \
|
||||||
|
>> "${workdir}/etc/mdev.conf"
|
||||||
|
;;
|
||||||
udev)
|
udev)
|
||||||
for _binary in udevd udevadm; do
|
for _binary in udevd udevadm; do
|
||||||
install_binary "$_binary"
|
install_binary "$_binary"
|
||||||
done
|
done
|
||||||
|
|
||||||
# i hate udev
|
mkdir -p "${workdir}/usr/lib/udev/rules.d"
|
||||||
mkdir -p "${workdir}/run/udev"
|
|
||||||
|
|
||||||
# exclusively handle requirement
|
printf "%s\n" \
|
||||||
[ "$luks" = 1 ] || [ "$lvm" = 1 ] && install_binary dmsetup
|
'SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/device-helper"' \
|
||||||
|
> "${workdir}/usr/lib/udev/rules.d/device-helper.rules"
|
||||||
|
|
||||||
for _binary in /usr/lib/udev/ata_id /usr/lib/udev/scsi_id; do
|
[ "$monolith" = 1 ] && return 0
|
||||||
install -Dm755 "$_binary" "${workdir}${_binary}" || return
|
|
||||||
done
|
|
||||||
|
|
||||||
# TODO we really need all rules?
|
printf "%s\n" \
|
||||||
set +f; for _file in /usr/lib/udev/rules.d/*; do
|
'ENV{MODALIAS}=="?*", ACTION=="add", RUN+="/bin/modprobe %E{MODALIAS}"' \
|
||||||
install -Dm644 "$_file" "${workdir}${_file}" || return
|
>> "${workdir}/usr/lib/udev/rules.d/device-helper.rules"
|
||||||
done; set -f
|
|
||||||
;;
|
|
||||||
mdev)
|
|
||||||
install_binary mdev
|
|
||||||
install_device_helper
|
|
||||||
;;
|
|
||||||
mdevd)
|
|
||||||
for _binary in mdevd mdevd-coldplug; do
|
|
||||||
install_binary "$_binary"
|
|
||||||
done
|
|
||||||
|
|
||||||
install_device_helper
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@ -237,9 +237,7 @@ install_lvm()
|
|||||||
{
|
{
|
||||||
print "installing LVM"
|
print "installing LVM"
|
||||||
|
|
||||||
for _binary in lvchange vgchange; do
|
install_binary lvm
|
||||||
install_binary "$_binary"
|
|
||||||
done
|
|
||||||
|
|
||||||
lvm_config="
|
lvm_config="
|
||||||
devices {
|
devices {
|
||||||
@ -258,21 +256,17 @@ install_lvm()
|
|||||||
{ IFS=,; set -- $lvm_opts; IFS="$OLD_IFS"; }
|
{ IFS=,; set -- $lvm_opts; IFS="$OLD_IFS"; }
|
||||||
|
|
||||||
for opt; do case "$opt" in
|
for opt; do case "$opt" in
|
||||||
config | config=1)
|
config | config=1) embed_lvm_config=1 ;;
|
||||||
embed_lvm_config=1
|
|
||||||
;;
|
|
||||||
esac; done
|
esac; done
|
||||||
|
|
||||||
mkdir -p "${workdir}/etc/lvm"; lvmconfig \
|
mkdir -p "${workdir}/etc/lvm"
|
||||||
|
|
||||||
|
lvm config \
|
||||||
--config "$lvm_config" \
|
--config "$lvm_config" \
|
||||||
${embed_lvm_config:+--mergedconfig} \
|
${embed_lvm_config+--mergedconfig} \
|
||||||
> "${workdir}/etc/lvm/lvm.conf"
|
> "${workdir}/etc/lvm/lvm.conf"
|
||||||
|
|
||||||
# copy config
|
populate_config "lvm='$lvm'" "lvm_opts='$lvm_opts'"
|
||||||
printf "%s\n" \
|
|
||||||
lvm="$lvm" \
|
|
||||||
lvm_opts="$lvm_opts" \
|
|
||||||
>> "${workdir}/etc/config"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_luks()
|
install_luks()
|
||||||
@ -281,31 +275,29 @@ install_luks()
|
|||||||
|
|
||||||
install_binary cryptsetup
|
install_binary cryptsetup
|
||||||
|
|
||||||
# avoid libgcc_s.so.1 missing error
|
# fix libgcc_s.so.1 missing error
|
||||||
# see https://bugs.archlinux.org/task/56771
|
# see https://bugs.archlinux.org/task/56771
|
||||||
[ -e /usr/lib/libgcc_s.so.1 ] && install_library /usr/lib/libgcc_s.so.1
|
[ -e /usr/lib/libgcc_s.so.1 ] &&
|
||||||
|
install_library /usr/lib/libgcc_s.so.1
|
||||||
|
|
||||||
# word splitting is safe by design
|
# word splitting is safe by design
|
||||||
# shellcheck disable=2086
|
# shellcheck disable=2086
|
||||||
{ IFS=,; set -- $luks_opts; IFS="$OLD_IFS"; }
|
{ IFS=,; set -- $luks_opts; IFS="$OLD_IFS"; }
|
||||||
|
|
||||||
for opt; do case "${opt%%=*}" in
|
for opt; do case "${opt%%=*}" in
|
||||||
header)
|
key | header)
|
||||||
install -m400 "${opt##*=}" "${workdir}/root/header" || return
|
install -m400 "${opt##*=}" \
|
||||||
luks_opts=$(printf "%s" "$luks_opts" | sed "s|${opt##*=}|/root/header|")
|
"${workdir}/root/${opt%%=*}" || panic
|
||||||
;;
|
|
||||||
key)
|
luks_opts=$(printf "%s" "$luks_opts" |
|
||||||
install -m400 "${opt##*=}" "${workdir}/root/key" || return
|
sed "s|${opt##*=}|/root/${opt%%=*}|")
|
||||||
luks_opts=$(printf "%s" "$luks_opts" | sed "s|${opt##*=}|/root/key|")
|
|
||||||
;;
|
;;
|
||||||
esac; done
|
esac; done
|
||||||
|
|
||||||
# copy config
|
populate_config \
|
||||||
printf "%s\n" \
|
"luks='$luks'" \
|
||||||
luks="$luks" \
|
"luks_root='$luks_root'" \
|
||||||
luks_root="$luks_root" \
|
"luks_opts='$luks_opts'"
|
||||||
luks_opts="$luks_opts" \
|
|
||||||
>> "${workdir}/etc/config"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_module()
|
install_module()
|
||||||
@ -316,7 +308,7 @@ install_module()
|
|||||||
|
|
||||||
while read -r module || [ "$module" ]; do
|
while read -r module || [ "$module" ]; do
|
||||||
|
|
||||||
# strip unneeded stuff
|
# skip unneeded stuff
|
||||||
for _exclude_module in wmi gpu net sound builtin $modules_exclude; do
|
for _exclude_module in wmi gpu net sound builtin $modules_exclude; do
|
||||||
case "$module" in *"$_exclude_module"*) continue 2 ;; esac
|
case "$module" in *"$_exclude_module"*) continue 2 ;; esac
|
||||||
done
|
done
|
||||||
@ -324,9 +316,10 @@ install_module()
|
|||||||
module="${module#insmod }"
|
module="${module#insmod }"
|
||||||
|
|
||||||
# check if module already installed
|
# check if module already installed
|
||||||
[ -e "$module" ] && [ ! -e "${workdir}${module}" ] &&
|
[ -e "${workdir}${module}" ] && continue
|
||||||
install -Dm644 "$module" "${workdir}${module}" || return
|
|
||||||
done ||:
|
install -Dm644 "$module" "${workdir}${module}" || panic
|
||||||
|
done || :
|
||||||
}
|
}
|
||||||
|
|
||||||
install_hostonly_modules()
|
install_hostonly_modules()
|
||||||
@ -338,30 +331,33 @@ install_hostonly_modules()
|
|||||||
|
|
||||||
while read -r _module || [ "$_module" ]; do
|
while read -r _module || [ "$_module" ]; do
|
||||||
install_module "$_module"
|
install_module "$_module"
|
||||||
done ||:
|
done || :
|
||||||
|
|
||||||
# install LVM modules
|
# install LVM modules
|
||||||
[ "$lvm" = 1 ] &&
|
[ "$lvm" = 1 ] &&
|
||||||
for _module in dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror; do
|
for _module in dm-thin-pool dm-multipath \
|
||||||
|
dm-snapshot dm-cache dm-log dm-mirror
|
||||||
|
do
|
||||||
install_module "$_module"
|
install_module "$_module"
|
||||||
done
|
done
|
||||||
|
|
||||||
# install LUKS modules
|
# install LUKS modules
|
||||||
[ "$luks" = 1 ] &&
|
[ "$luks" = 1 ] &&
|
||||||
for _module in aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent; do
|
for _module in aes dm-crypt sha256 sha512 \
|
||||||
|
wp512 ecb lrw xts twofish serpent
|
||||||
|
do
|
||||||
install_module "$_module"
|
install_module "$_module"
|
||||||
done
|
done
|
||||||
|
|
||||||
# install root partition module
|
# install root filesystem module
|
||||||
if [ "$root_type" ]; then
|
if [ "$root_type" ]; then
|
||||||
install_module "$root_type"
|
install_module "$root_type"
|
||||||
else
|
else
|
||||||
while read -r _ _dir _type _ _ _ || [ "$_dir" ]; do
|
while read -r _ _dir _type _ || [ "$_dir" ]; do
|
||||||
[ "$_dir" = / ] && {
|
[ "$_dir" = / ] || continue
|
||||||
install_module "${root_type=$_type}"
|
|
||||||
break
|
install_module "${root_type=$_type}"; break
|
||||||
}
|
done < /proc/mounts || panic
|
||||||
done < /proc/mounts || panic "failed to install root partition module"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,17 +366,17 @@ install_all_modules()
|
|||||||
print "installing all modules"
|
print "installing all modules"
|
||||||
|
|
||||||
find \
|
find \
|
||||||
"${modker}/kernel/arch" \
|
|
||||||
"${modker}/kernel/crypto" \
|
|
||||||
"${modker}/kernel/fs" \
|
"${modker}/kernel/fs" \
|
||||||
"${modker}/kernel/lib" \
|
"${modker}/kernel/lib" \
|
||||||
"${modker}/kernel/drivers/block" \
|
"${modker}/kernel/arch" \
|
||||||
"${modker}/kernel/drivers/ata" \
|
"${modker}/kernel/crypto" \
|
||||||
"${modker}/kernel/drivers/md" \
|
"${modker}/kernel/drivers/md" \
|
||||||
|
"${modker}/kernel/drivers/ata" \
|
||||||
"${modker}/kernel/drivers/scsi" \
|
"${modker}/kernel/drivers/scsi" \
|
||||||
"${modker}/kernel/drivers/usb/storage" \
|
"${modker}/kernel/drivers/block" \
|
||||||
"${modker}/kernel/drivers/usb/host" \
|
|
||||||
"${modker}/kernel/drivers/virtio" \
|
"${modker}/kernel/drivers/virtio" \
|
||||||
|
"${modker}/kernel/drivers/usb/host" \
|
||||||
|
"${modker}/kernel/drivers/usb/storage" \
|
||||||
-type f 2> /dev/null |
|
-type f 2> /dev/null |
|
||||||
|
|
||||||
while read -r _module || [ "$_module" ]; do
|
while read -r _module || [ "$_module" ]; do
|
||||||
@ -390,7 +386,39 @@ install_all_modules()
|
|||||||
_module="${_module%%.*}"
|
_module="${_module%%.*}"
|
||||||
|
|
||||||
install_module "$_module"
|
install_module "$_module"
|
||||||
done ||:
|
done || :
|
||||||
|
}
|
||||||
|
|
||||||
|
install_modules()
|
||||||
|
{
|
||||||
|
if [ "$hostonly" = 1 ]; then
|
||||||
|
install_hostonly_modules
|
||||||
|
else
|
||||||
|
install_all_modules
|
||||||
|
fi
|
||||||
|
|
||||||
|
# install user specified modules if any
|
||||||
|
[ "$modules" ] && {
|
||||||
|
for _module in $modules; do
|
||||||
|
install_module "$_module"
|
||||||
|
done
|
||||||
|
|
||||||
|
populate_config "modules='$modules'"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "$devmgr" = mdev ] &&
|
||||||
|
for _binary in find sort; do
|
||||||
|
install_binary "$_binary"
|
||||||
|
done
|
||||||
|
|
||||||
|
install_binary modprobe
|
||||||
|
|
||||||
|
install -m644 \
|
||||||
|
"${modker}/modules.builtin" \
|
||||||
|
"${modker}/modules.order" \
|
||||||
|
"${workdir}${modker}"
|
||||||
|
|
||||||
|
depmod -b "$workdir" "$kernel"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_binary()
|
install_binary()
|
||||||
@ -410,44 +438,44 @@ install_binary()
|
|||||||
# shellcheck disable=2086
|
# shellcheck disable=2086
|
||||||
{ IFS=:; set -- $PATH; IFS="$OLD_IFS"; }
|
{ IFS=:; set -- $PATH; IFS="$OLD_IFS"; }
|
||||||
|
|
||||||
|
# try to discover external binary/script by checking PATH
|
||||||
for _dir; do
|
for _dir; do
|
||||||
[ -x "${_dir}/${binary}" ] && {
|
[ -x "${_dir}/${binary}" ] || ! continue
|
||||||
binary="${_dir}/${binary}"
|
|
||||||
break
|
binary="${_dir}/${binary}"; break
|
||||||
}
|
done || panic "couldn't find external $1"
|
||||||
done || panic "couldn't find external $1 binary"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# check if binary already installed
|
# check if binary already installed
|
||||||
[ -e "${workdirbin}${binary##*/}" ] && return
|
[ -e "${workdirbin}${binary##*/}" ] && return 0
|
||||||
|
|
||||||
# iterate throught symlinks and copy them
|
# iterate throught symlinks and copy them
|
||||||
while [ -h "$binary" ]; do
|
while [ -h "$binary" ]; do
|
||||||
cp -P "$binary" "$workdirbin"
|
cp -P "$binary" "$workdirbin" || panic
|
||||||
readlink_binary=$(readlink "$binary")
|
readlink_binary=$(readlink "$binary")
|
||||||
binary="${binary%/*}/${readlink_binary##*/}"
|
binary="${binary%/*}/${readlink_binary##*/}"
|
||||||
done
|
done
|
||||||
|
|
||||||
install -m755 "$binary" "${workdirbin}${binary##*/}" || return
|
install -m755 "$binary" "${workdirbin}${binary##*/}" || panic
|
||||||
strip "${workdirbin}${binary##*/}" > /dev/null 2>&1 ||:
|
strip "${workdirbin}${binary##*/}" > /dev/null 2>&1 || :
|
||||||
|
|
||||||
# check if binary statically linked
|
# skip static binaries/scripts
|
||||||
ldd "$binary" > /dev/null 2>&1 || return 0
|
ldd "$binary" > /dev/null 2>&1 || return 0
|
||||||
|
|
||||||
# exract paths to libraries
|
# parse ldd output to find libraries paths
|
||||||
ldd "$binary" |
|
ldd "$binary" |
|
||||||
|
|
||||||
while read -r _library || [ "$_library" ]; do
|
while read -r _library || [ "$_library" ]; do
|
||||||
|
|
||||||
# strip unneeded stuff
|
# skip unneeded stuff
|
||||||
[ "${_library##*vdso*}" ] || continue
|
[ "${_library##*vdso*}" ] || continue
|
||||||
|
|
||||||
_library="${_library#* => }"
|
_library="${_library#* => }"
|
||||||
_library="${_library% *}"
|
_library="${_library% *}"
|
||||||
|
|
||||||
[ -e "$_library" ] && install_library "$_library"
|
install_library "$_library"
|
||||||
done ||:
|
done || :
|
||||||
}
|
}
|
||||||
|
|
||||||
install_library()
|
install_library()
|
||||||
@ -455,43 +483,40 @@ install_library()
|
|||||||
library="$1"
|
library="$1"
|
||||||
|
|
||||||
# check if library already installed
|
# check if library already installed
|
||||||
[ -e "${workdirlib}${library##*/}" ] && return
|
[ -e "${workdirlib}${library##*/}" ] && return 0
|
||||||
|
|
||||||
# iterate throught symlinks and copy them
|
# iterate throught symlinks and copy them
|
||||||
while [ -h "$library" ]; do
|
while [ -h "$library" ]; do
|
||||||
cp -P "$library" "$workdirlib"
|
cp -P "$library" "$workdirlib" || panic
|
||||||
readlink_library=$(readlink "$library")
|
readlink_library=$(readlink "$library")
|
||||||
library="${library%/*}/${readlink_library##*/}"
|
library="${library%/*}/${readlink_library##*/}"
|
||||||
done
|
done
|
||||||
|
|
||||||
install -m755 "$library" "${workdirlib}${library##*/}" || return
|
install -m755 "$library" "${workdirlib}${library##*/}" || panic
|
||||||
strip "${workdirlib}${library##*/}" > /dev/null 2>&1 ||:
|
strip "${workdirlib}${library##*/}" > /dev/null 2>&1 || :
|
||||||
}
|
}
|
||||||
|
|
||||||
create_initramfs()
|
create_initramfs()
|
||||||
{
|
(
|
||||||
print "creating initramfs image"
|
print "creating initramfs image"
|
||||||
|
|
||||||
# check if image already exist
|
# check if image already exist
|
||||||
[ "$force" != 1 ] && [ -e "$output" ] &&
|
[ "$force" != 1 ] && [ -e "$output" ] &&
|
||||||
panic "initramfs image already exist"
|
panic "initramfs image already exist"
|
||||||
|
|
||||||
(
|
cd "$workdir"; find . |
|
||||||
cd "$workdir"; find . |
|
|
||||||
|
|
||||||
if [ "$compress" = none ]; then
|
if [ "$compress" = none ]; then
|
||||||
cpio -oH newc
|
cpio -oH newc
|
||||||
else
|
else
|
||||||
cpio -oH newc | ${compress:-gzip -9}
|
cpio -oH newc | ${compress:-gzip -9}
|
||||||
fi
|
fi \
|
||||||
|
> "$output" 2> /dev/null ||
|
||||||
) > "$output" 2> /dev/null ||
|
|
||||||
panic "failed to generate initramfs image"
|
panic "failed to generate initramfs image"
|
||||||
}
|
)
|
||||||
|
|
||||||
# int main()
|
# int main()
|
||||||
{
|
{
|
||||||
# check root
|
|
||||||
[ "$(id -u)" = 0 ] || panic "must be run as root"
|
[ "$(id -u)" = 0 ] || panic "must be run as root"
|
||||||
|
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
@ -499,42 +524,9 @@ create_initramfs()
|
|||||||
create_structure
|
create_structure
|
||||||
create_symlinks
|
create_symlinks
|
||||||
|
|
||||||
[ "$lvm" = 1 ] && install_lvm
|
[ "$lvm" = 1 ] && install_lvm
|
||||||
[ "$luks" = 1 ] && install_luks
|
[ "$luks" = 1 ] && install_luks
|
||||||
|
[ "$monolith" = 1 ] || install_modules
|
||||||
# check monolithic kernel
|
|
||||||
[ "$monolith" != 1 ] && [ -d "$moddir" ] && {
|
|
||||||
|
|
||||||
# check hostonly mode
|
|
||||||
if [ "$hostonly" = 1 ]; then
|
|
||||||
install_hostonly_modules
|
|
||||||
else
|
|
||||||
install_all_modules
|
|
||||||
fi
|
|
||||||
|
|
||||||
# install user specified modules if any
|
|
||||||
[ "$modules" ] && {
|
|
||||||
for _module in $modules; do
|
|
||||||
install_module "$_module"
|
|
||||||
done
|
|
||||||
|
|
||||||
# copy config
|
|
||||||
printf "%s\n" \
|
|
||||||
modules="$modules" \
|
|
||||||
>> "${workdir}/etc/config"
|
|
||||||
}
|
|
||||||
|
|
||||||
for _binary in find sort modprobe; do
|
|
||||||
install_binary "$_binary"
|
|
||||||
done
|
|
||||||
|
|
||||||
install -m644 \
|
|
||||||
"${modker}/modules.builtin" \
|
|
||||||
"${modker}/modules.order" \
|
|
||||||
"${workdir}${modker}"
|
|
||||||
|
|
||||||
depmod -b "$workdir" "$kernel"
|
|
||||||
}
|
|
||||||
|
|
||||||
install_devmgr
|
install_devmgr
|
||||||
install_requirements
|
install_requirements
|
||||||
|
Loading…
Reference in New Issue
Block a user