refactor
This commit is contained in:
parent
de8603e784
commit
b9137bf486
201
README.md
201
README.md
@ -1,48 +1,183 @@
|
|||||||
# initramfs
|
|
||||||
Tiny initramfs for suckless systems
|
|
||||||
|
|
||||||
Features
|
Features
|
||||||
--------
|
========
|
||||||
- POSIX compliance
|
|
||||||
|
- No `local`'s, no bashisms, only POSIX shell
|
||||||
- Easy configuration
|
- Easy configuration
|
||||||
- LUKS
|
- LUKS
|
||||||
- LVM
|
- LVM
|
||||||
- mdev, mdevd, eudev
|
- mdev, mdevd, eudev
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
============
|
||||||
Requirements:
|
|
||||||
* busybox
|
Dependencies
|
||||||
- --install [-s] [DIR]
|
------------
|
||||||
- mdev
|
|
||||||
- switch_root
|
* POSIX shell
|
||||||
- mount
|
* `toybox` OR `busybox` OR `sbase/ubase` OR `coreutils/util-linux`
|
||||||
- umount
|
* `mdev` OR `mdevd` OR `eudev`
|
||||||
- blkid
|
* `kmod`
|
||||||
* kmod
|
- Not required for monolithic kernel (builtin modules)
|
||||||
* cryptsetup - LUKS
|
* `cryptsetup`
|
||||||
* lvm2 - LVM
|
- Required for LUKS support
|
||||||
* util-linux - PARTUUID
|
* `lvm2`
|
||||||
|
- Required for LVM support
|
||||||
|
|
||||||
|
Usage
|
||||||
|
-----
|
||||||
|
|
||||||
Download & Setup:
|
|
||||||
```
|
```
|
||||||
git clone https://github.com/illiliti/initramfs
|
usage: ./tinyramfs [option]
|
||||||
cd initramfs
|
-o, --output <file> set initramfs image name
|
||||||
|
-c, --config <file> set config file path
|
||||||
|
-m, --moddir <dir> set modules directory
|
||||||
|
-k, --kernel <ver> set kernel version
|
||||||
|
-F, --files <dir> set files directory
|
||||||
|
-d, --debug enable debug mode
|
||||||
|
-f, --force overwrite initramfs image
|
||||||
```
|
```
|
||||||
TODO
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
-------------
|
=============
|
||||||
TODO
|
|
||||||
|
```sh
|
||||||
|
# debug mode
|
||||||
|
#
|
||||||
|
debug=0
|
||||||
|
|
||||||
|
# overwrite initramfs
|
||||||
|
#
|
||||||
|
force=0
|
||||||
|
|
||||||
|
# initramfs name
|
||||||
|
#
|
||||||
|
# default - /tmp/initramfs-$kernel
|
||||||
|
# example - output="/tmp/myinitramfs.img.gz"
|
||||||
|
#
|
||||||
|
output=""
|
||||||
|
|
||||||
|
# monolithic kernel
|
||||||
|
#
|
||||||
|
monolith=0
|
||||||
|
|
||||||
|
# modules directory
|
||||||
|
#
|
||||||
|
# default - /lib/modules
|
||||||
|
# example - moddir="/mnt/root/lib/modules"
|
||||||
|
#
|
||||||
|
moddir=""
|
||||||
|
|
||||||
|
# kernel version
|
||||||
|
#
|
||||||
|
# default - $(uname -r)
|
||||||
|
# example - kernel="5.4.18_1"
|
||||||
|
#
|
||||||
|
kernel=""
|
||||||
|
|
||||||
|
# compression program
|
||||||
|
#
|
||||||
|
# default - gzip -9
|
||||||
|
# example - compress="pigz -9"
|
||||||
|
#
|
||||||
|
compress=""
|
||||||
|
|
||||||
|
# root
|
||||||
|
#
|
||||||
|
# supported - PARTUUID, DEVICE, LABEL, PARTUUID
|
||||||
|
# example -
|
||||||
|
# root="/dev/sda1"
|
||||||
|
# root="PARTUUID=35f923c5-083a-4950-a4da-e611d0778121"
|
||||||
|
#
|
||||||
|
root=""
|
||||||
|
|
||||||
|
# root type
|
||||||
|
#
|
||||||
|
# default - autodetected
|
||||||
|
# example - root_type="btrfs"
|
||||||
|
#
|
||||||
|
root_type=""
|
||||||
|
|
||||||
|
# root options
|
||||||
|
# example - see fstab(5)
|
||||||
|
#
|
||||||
|
root_opts=""
|
||||||
|
|
||||||
|
# device manager
|
||||||
|
# supported - udev, mdev, mdevd
|
||||||
|
#
|
||||||
|
devmgr=""
|
||||||
|
|
||||||
|
# hostonly mode
|
||||||
|
#
|
||||||
|
hostonly=0
|
||||||
|
|
||||||
|
# additional modules
|
||||||
|
# example - modules="fat crc32c_generic"
|
||||||
|
#
|
||||||
|
modules=""
|
||||||
|
|
||||||
|
# exclude modules
|
||||||
|
# example - modules_exclude="wmi fuse"
|
||||||
|
#
|
||||||
|
modules_exclude=""
|
||||||
|
|
||||||
|
# additional binaries
|
||||||
|
# example - binaries="ls cat /path/to/mycustomprog"
|
||||||
|
#
|
||||||
|
binaries=""
|
||||||
|
|
||||||
|
# LVM support
|
||||||
|
#
|
||||||
|
lvm=0
|
||||||
|
|
||||||
|
# LVM options
|
||||||
|
#
|
||||||
|
# supported - tag, name, group, config, discard
|
||||||
|
# description -
|
||||||
|
# tag - trigger lvm by tag
|
||||||
|
# name - trigger lvm by logical volume name
|
||||||
|
# group - trigger lvm by volume group name
|
||||||
|
# config - embed host lvm config
|
||||||
|
# discard - enable issue_discards
|
||||||
|
# example -
|
||||||
|
# lvm_opts="tag=lvm-server"
|
||||||
|
# lvm_opts="name=lv1,group=vg1"
|
||||||
|
# lvm_opts="config=1,discard"
|
||||||
|
# lvm_opts="discard=1"
|
||||||
|
#
|
||||||
|
lvm_opts=""
|
||||||
|
|
||||||
|
# LUKS support
|
||||||
|
#
|
||||||
|
luks=0
|
||||||
|
|
||||||
|
# LUKS encrypted root
|
||||||
|
#
|
||||||
|
# supported - PARTUUID, DEVICE, LABEL, PARTUUID
|
||||||
|
# example -
|
||||||
|
# luks_root="/dev/sda1"
|
||||||
|
# luks_root="PARTUUID=35f923c5-083a-4950-a4da-e611d0778121"
|
||||||
|
#
|
||||||
|
luks_root=""
|
||||||
|
|
||||||
|
# LUKS options
|
||||||
|
#
|
||||||
|
# supported - key, name, header, discard
|
||||||
|
# description -
|
||||||
|
# key - embed key
|
||||||
|
# name - device mapper name
|
||||||
|
# header - embed header
|
||||||
|
# discard - enable allow-discards
|
||||||
|
# example -
|
||||||
|
# luks_opts="key=/path/to/keyfile,name=myluksroot,header=/path/to/header,discard"
|
||||||
|
# luks_opts="discard=1"
|
||||||
|
#
|
||||||
|
luks_opts=""
|
||||||
|
```
|
||||||
|
|
||||||
|
TODO document kernel command-line parameters
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
=======
|
||||||
|
|
||||||
Licensed under GPLv3
|
Licensed under GPLv3
|
||||||
|
|
||||||
Exceptions:
|
|
||||||
|
|
||||||
The "mdev.conf" configuration file is modified version from "mdev-like-a-boss" project, Copyright (c) 2012-2020, Piotr Karbowski <piotr.karbowski@gmail.com>.
|
|
||||||
Please consult the license notice in the file for terms and conditions.
|
|
||||||
|
|
||||||
The "storage-device" script is modified version from "mdev-like-a-boss" project, Copyright (c) 2012-2020, Piotr Karbowski <piotr.karbowski@gmail.com>.
|
|
||||||
Please consult the license notice in the file for terms and conditions.
|
|
||||||
|
149
config
149
config
@ -3,91 +3,134 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# debug mode
|
# debug mode
|
||||||
#debug=0
|
#
|
||||||
|
debug=0
|
||||||
|
|
||||||
# overwrite initramfs
|
# overwrite initramfs
|
||||||
#force=0
|
#
|
||||||
|
force=0
|
||||||
# init
|
|
||||||
#init=""
|
|
||||||
|
|
||||||
# initramfs name
|
# initramfs name
|
||||||
#initramfs=""
|
#
|
||||||
|
# default - /tmp/initramfs-$kernel
|
||||||
|
# example - output="/tmp/myinitramfs.img.gz"
|
||||||
|
#
|
||||||
|
output=""
|
||||||
|
|
||||||
# monolithic kernel
|
# monolithic kernel
|
||||||
#monolith=""
|
#
|
||||||
|
monolith=0
|
||||||
|
|
||||||
# drivers directory
|
# modules directory
|
||||||
#moddir=""
|
#
|
||||||
|
# default - /lib/modules
|
||||||
|
# example - moddir="/mnt/root/lib/modules"
|
||||||
|
#
|
||||||
|
moddir=""
|
||||||
|
|
||||||
# kernel version
|
# kernel version
|
||||||
#kernel=""
|
#
|
||||||
|
# default - $(uname -r)
|
||||||
|
# example - kernel="5.4.18_1"
|
||||||
|
#
|
||||||
|
kernel=""
|
||||||
|
|
||||||
# compression program
|
# compression program
|
||||||
#compress=""
|
#
|
||||||
|
# default - gzip -9
|
||||||
|
# example - compress="pigz -9"
|
||||||
|
#
|
||||||
|
compress=""
|
||||||
|
|
||||||
# root
|
# root
|
||||||
#root=""
|
#
|
||||||
|
# supported - PARTUUID, DEVICE, LABEL, PARTUUID
|
||||||
|
# example -
|
||||||
|
# root="/dev/sda1"
|
||||||
|
# root="PARTUUID=35f923c5-083a-4950-a4da-e611d0778121"
|
||||||
|
#
|
||||||
|
root=""
|
||||||
|
|
||||||
# root type
|
# root type
|
||||||
#root_type=""
|
#
|
||||||
|
# default - autodetected
|
||||||
|
# example - root_type="btrfs"
|
||||||
|
#
|
||||||
|
root_type=""
|
||||||
|
|
||||||
# root options
|
# root options
|
||||||
#root_opts=""
|
# example - see fstab(5)
|
||||||
|
#
|
||||||
# util-linux binaries
|
root_opts=""
|
||||||
#util_linux=0
|
|
||||||
|
|
||||||
# device manager
|
# device manager
|
||||||
#devmgr=""
|
# supported - udev, mdev, mdevd
|
||||||
|
#
|
||||||
|
devmgr=""
|
||||||
|
|
||||||
# hostonly mode
|
# hostonly mode
|
||||||
#hostonly=0
|
#
|
||||||
|
hostonly=0
|
||||||
|
|
||||||
# additional drivers
|
# additional modules
|
||||||
#drivers=""
|
# example - modules="fat crc32c_generic"
|
||||||
|
#
|
||||||
|
modules=""
|
||||||
|
|
||||||
# exclude drivers
|
# exclude modules
|
||||||
#drivers_exclude=""
|
# example - modules_exclude="wmi fuse"
|
||||||
|
#
|
||||||
|
modules_exclude=""
|
||||||
|
|
||||||
# additional binaries
|
# additional binaries
|
||||||
#binaries=""
|
# example - binaries="ls cat /path/to/mycustomprog"
|
||||||
|
#
|
||||||
|
binaries=""
|
||||||
|
|
||||||
# LVM support
|
# LVM support
|
||||||
#lvm=0
|
#
|
||||||
|
lvm=0
|
||||||
# LVM logical volume name
|
|
||||||
#lvm_name=""
|
|
||||||
|
|
||||||
# LVM volume group name
|
|
||||||
#lvm_group=""
|
|
||||||
|
|
||||||
# LVM config
|
|
||||||
#lvm_config=0
|
|
||||||
|
|
||||||
# LVM issue_discards
|
|
||||||
#lvm_discard=0
|
|
||||||
|
|
||||||
# LVM options
|
# LVM options
|
||||||
#lvm_args=""
|
#
|
||||||
|
# supported - tag, name, group, config, discard
|
||||||
|
# description -
|
||||||
|
# tag - trigger lvm by tag
|
||||||
|
# name - trigger lvm by logical volume name
|
||||||
|
# group - trigger lvm by volume group name
|
||||||
|
# config - embed host lvm config
|
||||||
|
# discard - enable issue_discards
|
||||||
|
# example -
|
||||||
|
# lvm_opts="tag=lvm-server"
|
||||||
|
# lvm_opts="name=lv1,group=vg1"
|
||||||
|
# lvm_opts="config=1,discard"
|
||||||
|
# lvm_opts="discard=1"
|
||||||
|
#
|
||||||
|
lvm_opts=""
|
||||||
|
|
||||||
# LUKS support
|
# LUKS support
|
||||||
#luks=0
|
#
|
||||||
|
luks=0
|
||||||
|
|
||||||
# LUKS encrypted root
|
# LUKS encrypted root
|
||||||
#luks_root=""
|
#
|
||||||
|
# supported - PARTUUID, DEVICE, LABEL, PARTUUID
|
||||||
# LUKS mapper name
|
# example -
|
||||||
#luks_name=""
|
# luks_root="/dev/sda1"
|
||||||
|
# luks_root="PARTUUID=35f923c5-083a-4950-a4da-e611d0778121"
|
||||||
# LUKS detached header
|
#
|
||||||
#luks_header="/path/to/header"
|
luks_root=""
|
||||||
|
|
||||||
# LUKS keyfile
|
|
||||||
#luks_keyfile="/path/to/keyfile"
|
|
||||||
|
|
||||||
# LUKS allow_discards
|
|
||||||
#luks_discard=0
|
|
||||||
|
|
||||||
# LUKS options
|
# LUKS options
|
||||||
#luks_args=""
|
#
|
||||||
|
# supported - key, name, header, discard
|
||||||
|
# description -
|
||||||
|
# key - embed key
|
||||||
|
# name - device mapper name
|
||||||
|
# header - embed header
|
||||||
|
# discard - enable allow-discards
|
||||||
|
# example -
|
||||||
|
# luks_opts="key=/path/to/keyfile,name=myluksroot,header=/path/to/header,discard"
|
||||||
|
# luks_opts="discard=1"
|
||||||
|
#
|
||||||
|
luks_opts=""
|
||||||
|
592
tinyramfs
592
tinyramfs
@ -1,32 +1,27 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh -ef
|
||||||
#
|
#
|
||||||
# tiny initramfs generation tool
|
# tiny initramfs
|
||||||
|
|
||||||
msg() {
|
msg()
|
||||||
|
{
|
||||||
case "$1" in
|
case "$1" in
|
||||||
info)
|
info)
|
||||||
printf "info >> %s\n" "$2" >&2
|
printf "info >> %s\n" "$2"
|
||||||
;;
|
;;
|
||||||
warn)
|
|
||||||
printf "warning >> %s\n" "$2" \
|
|
||||||
"are you sure you want to continue?" \
|
|
||||||
"press enter to continue or ctrl+c to exit" >&2
|
|
||||||
|
|
||||||
read -r _
|
|
||||||
;;
|
|
||||||
panic)
|
panic)
|
||||||
printf "panic >> %s\n" "$2" >&2
|
printf "panic >> %s\n" "$2" >&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage()
|
||||||
|
{
|
||||||
cat << EOF
|
cat << EOF
|
||||||
usage: $0 [option...]
|
usage: $0 [option]
|
||||||
-o, --output <file> set initramfs image name
|
-o, --output <file> set initramfs image name
|
||||||
-c, --config <file> set config file path
|
-c, --config <file> set config file path
|
||||||
-m, --moddir <dir> set drivers 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
|
||||||
@ -35,181 +30,227 @@ usage: $0 [option...]
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_args() {
|
parse_args()
|
||||||
|
{
|
||||||
while [ "$1" ]; do
|
while [ "$1" ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-o | --output)
|
-o | --output)
|
||||||
_initramfs="${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 "%s\n\n" "invalid option: '$1'"
|
printf "invalid option: %s\n\n" "$1"
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_environment() {
|
prepare_environment()
|
||||||
|
{
|
||||||
|
msg info "preparing environment"
|
||||||
|
|
||||||
for _file in $_config /etc/tinyramfs/config ./config; do
|
for _file in $_config /etc/tinyramfs/config ./config; do
|
||||||
[ -f "$_file" ] && . "$_file" && break
|
[ -f "$_file" ] &&
|
||||||
|
{
|
||||||
|
. "$_file"
|
||||||
|
break
|
||||||
|
}
|
||||||
done || msg panic "failed to source config"
|
done || msg panic "failed to source config"
|
||||||
|
|
||||||
for _dir in $_filesdir /usr/share/tinyramfs ./usr/share/tinyramfs; do
|
for _dir in $_filesdir /usr/share/tinyramfs ./usr/share/tinyramfs; do
|
||||||
[ -d "$_dir" ] && filesdir="$_dir" && break
|
[ -d "$_dir" ] &&
|
||||||
|
{
|
||||||
|
filesdir="$_dir"
|
||||||
|
break
|
||||||
|
}
|
||||||
done || msg panic "failed to locate required files"
|
done || msg panic "failed to locate required files"
|
||||||
|
|
||||||
kernel="${_kernel:-${kernel:-$(uname -r)}}"
|
|
||||||
moddir="${_moddir:-${moddir:-/lib/modules}}"
|
|
||||||
debug="${_debug:-${debug:-0}}"
|
debug="${_debug:-${debug:-0}}"
|
||||||
force="${_force:-${force:-0}}"
|
force="${_force:-${force:-0}}"
|
||||||
initramfs="${_initramfs:-${initramfs:-/tmp/initramfs-${kernel}}}"
|
moddir="${_moddir:-${moddir:-/lib/modules}}"
|
||||||
modker="${moddir}/${kernel}"
|
kernel="${_kernel:-${kernel:-$(uname -r)}}"
|
||||||
}
|
output="${_output:-${output:-/tmp/initramfs-${kernel}}}"
|
||||||
|
|
||||||
create_workdir() {
|
mkdir -p "${workdir=${XDG_CACHE_HOME:-${TMPDIR:-/tmp}}/initramfs.$$}" ||
|
||||||
msg info "creating working directory"
|
|
||||||
|
|
||||||
workdir="${XDG_CACHE_HOME:-${TMPDIR:-/tmp}}/initramfs.$$"
|
|
||||||
mkdir -p "$workdir" ||
|
|
||||||
msg panic "failed to create working directory"
|
msg panic "failed to create working directory"
|
||||||
|
|
||||||
|
workdirbin="${workdir}/usr/bin/"
|
||||||
|
workdirlib="${workdir}/usr/lib/"
|
||||||
|
modker="${moddir}/${kernel}"
|
||||||
|
OLD_IFS="$IFS"
|
||||||
}
|
}
|
||||||
|
|
||||||
remove_workdir() {
|
remove_workdir()
|
||||||
|
{
|
||||||
msg info "removing working directory"
|
msg info "removing working directory"
|
||||||
|
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_requirements() {
|
install_requirements()
|
||||||
|
{
|
||||||
msg info "installing requirements"
|
msg info "installing requirements"
|
||||||
|
|
||||||
# install user specified binaries
|
# install user specified binaries if any
|
||||||
[ "$binaries" ] &&
|
for _binary in $binaries; do
|
||||||
for _binary in $binaries; do
|
|
||||||
install_binary "$_binary"
|
|
||||||
done
|
|
||||||
|
|
||||||
# install util-linux binaries
|
|
||||||
[ "$util_linux" = 1 ] &&
|
|
||||||
for _binary in mount blkid; do
|
|
||||||
install_binary "$_binary"
|
|
||||||
done
|
|
||||||
|
|
||||||
# install required binaries
|
|
||||||
for _binary in busybox modprobe; do
|
|
||||||
install_binary "$_binary"
|
install_binary "$_binary"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# install required binaries
|
||||||
|
for _binary in \[ sh sleep mount printf setsid switch_root; do
|
||||||
|
install_binary "$_binary"
|
||||||
|
done
|
||||||
|
|
||||||
|
# copy init
|
||||||
|
install -m755 "${filesdir}/init" "${workdir}/init"
|
||||||
|
|
||||||
|
# copy config
|
||||||
|
printf "%s\n" \
|
||||||
|
monolith="$monolith" \
|
||||||
|
root="$root" \
|
||||||
|
root_type="$root_type" \
|
||||||
|
root_opts="$root_opts" \
|
||||||
|
devmgr="$devmgr" \
|
||||||
|
lvm="$lvm" \
|
||||||
|
lvm_opts="$lvm_opts" \
|
||||||
|
luks="$luks" \
|
||||||
|
luks_root="$luks_root" \
|
||||||
|
luks_opts="$luks_opts" \
|
||||||
|
> "${workdir}/etc/config"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_structure() {
|
create_structure()
|
||||||
|
{
|
||||||
msg info "creating directory structure"
|
msg info "creating directory structure"
|
||||||
|
|
||||||
for _dir in dev tmp var run etc usr/lib usr/bin mnt/root proc root sys; do
|
for _dir in etc tmp dev sys proc root usr/lib usr/bin mnt/root; do
|
||||||
mkdir -p "${workdir}/${_dir}"
|
mkdir -p "${workdir}/${_dir}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
create_symlinks() {
|
create_symlinks()
|
||||||
|
{
|
||||||
msg info "creating symlinks"
|
msg info "creating symlinks"
|
||||||
|
|
||||||
ln -s usr/lib "${workdir}/lib"
|
ln -s usr/lib "${workdir}/lib"
|
||||||
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 bin "${workdir}/usr/sbin"
|
ln -s bin "${workdir}/usr/sbin"
|
||||||
ln -s lib "${workdir}/usr/lib64"
|
ln -s lib "${workdir}/usr/lib64"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_devmgr() {
|
install_devmgr()
|
||||||
|
{
|
||||||
msg info "installing device manager"
|
msg info "installing device manager"
|
||||||
|
|
||||||
|
# TODO investigate booting without device manager
|
||||||
case "$devmgr" in
|
case "$devmgr" in
|
||||||
udev)
|
udev)
|
||||||
for _binary in udevd udevadm dmsetup; do
|
for _binary in udevd udevadm; do
|
||||||
install_binary "$_binary"
|
install_binary "$_binary"
|
||||||
done
|
done
|
||||||
|
|
||||||
find /usr/lib/udev \
|
# exclusively handle requirement
|
||||||
! -path "*rc_keymaps*" \
|
[ "$luks" = 1 ] || [ "$lvm" = 1 ] &&
|
||||||
! -path "*hwdb.d*" \
|
install_binary dmsetup
|
||||||
-type f |
|
|
||||||
|
|
||||||
cpio -pd "$workdir" > /dev/null 2>&1
|
for _binary in /usr/lib/udev/ata_id /usr/lib/udev/scsi_id; do
|
||||||
;;
|
install -Dm755 "$_binary" "${workdir}${_binary}"
|
||||||
mdev)
|
done
|
||||||
install -m644 "${filesdir}/mdev.conf" "${workdir}/etc/mdev.conf"
|
|
||||||
install -Dm755 "${filesdir}/storage-device" "${workdir}/lib/mdev/storage-device"
|
set +f; for _file in /usr/lib/udev/rules.d/*; do
|
||||||
;;
|
install -Dm644 "$_file" "${workdir}${_file}"
|
||||||
mdevd)
|
done; set -f
|
||||||
for _binary in mdevd mdevd-coldplug; do
|
;;
|
||||||
|
mdev | mdevd)
|
||||||
|
[ "$devmgr" = mdev ] && install_binary mdev
|
||||||
|
[ "$devmgr" = mdevd ] &&
|
||||||
|
for _binary in mdevd mdevd-coldplug; do
|
||||||
|
install_binary "$_binary"
|
||||||
|
done
|
||||||
|
|
||||||
|
for _binary in ln kill mkdir blkid "${filesdir}/device-helper"; do
|
||||||
install_binary "$_binary"
|
install_binary "$_binary"
|
||||||
done
|
done
|
||||||
|
|
||||||
install -m644 "${filesdir}/mdev.conf" "${workdir}/etc/mdev.conf"
|
printf "%s\n" \
|
||||||
install -Dm755 "${filesdir}/storage-device" "${workdir}/lib/mdev/storage-device"
|
'SUBSYSTEM=block;.* 0:0 660 @device-helper' \
|
||||||
;;
|
> "${workdir}/etc/mdev.conf"
|
||||||
|
|
||||||
|
[ "$monolith" != 1 ] && printf "%s\n" \
|
||||||
|
'$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"' \
|
||||||
|
>> "${workdir}/etc/mdev.conf"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
install_lvm() {
|
install_lvm()
|
||||||
|
{
|
||||||
msg info "installing LVM"
|
msg info "installing LVM"
|
||||||
|
|
||||||
install_binary lvm
|
for _binary in lvchange vgchange; do
|
||||||
|
install_binary "$_binary"
|
||||||
|
done
|
||||||
|
|
||||||
# install lvm config
|
{ IFS=,; set -- $lvm_opts; IFS="$OLD_IFS"; }
|
||||||
if [ "$lvm_config" = 1 ]; then
|
|
||||||
mkdir -p "${workdir}/etc/lvm"
|
|
||||||
|
|
||||||
cp /etc/lvm/*.conf "${workdir}/etc/lvm"
|
for opt; do
|
||||||
else
|
case "$opt" in
|
||||||
mkdir -p "${workdir}/etc/lvm"
|
config | config=1)
|
||||||
|
install -Dm644 /etc/lvm/lvm.conf "${workdir}/etc/lvm/lvm.conf"
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
cat << EOF > "${workdir}/etc/lvm/lvm.conf"
|
mkdir -p "${workdir}/etc/lvm"
|
||||||
devices {
|
printf "%s\n" \
|
||||||
# block discard support
|
'devices {' \
|
||||||
issue_discards = ${lvm_discard:-0}
|
'write_cache_state = 0' \
|
||||||
|
'}' \
|
||||||
|
'backup {' \
|
||||||
|
'backup = 0' \
|
||||||
|
'archive = 0' \
|
||||||
|
'}' \
|
||||||
|
'global {' \
|
||||||
|
'use_lvmetad = 0' \
|
||||||
|
'}' \
|
||||||
|
> "${workdir}/etc/lvm/lvm.conf"
|
||||||
}
|
}
|
||||||
|
|
||||||
global {
|
install_luks()
|
||||||
# disable lvmetad
|
{
|
||||||
use_lvmetad = 0
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
install_luks() {
|
|
||||||
msg info "installing LUKS"
|
msg info "installing LUKS"
|
||||||
|
|
||||||
install_binary cryptsetup
|
install_binary cryptsetup
|
||||||
@ -219,61 +260,91 @@ install_luks() {
|
|||||||
[ -e /usr/lib/libgcc_s.so.1 ] &&
|
[ -e /usr/lib/libgcc_s.so.1 ] &&
|
||||||
install_library /usr/lib/libgcc_s.so.1
|
install_library /usr/lib/libgcc_s.so.1
|
||||||
|
|
||||||
# copy luks header
|
{ IFS=,; set -- $luks_opts; IFS="$OLD_IFS"; }
|
||||||
[ -f "$luks_header" ] &&
|
|
||||||
install -m400 "$luks_header" "${workdir}/root/luks_header"
|
|
||||||
|
|
||||||
# copy luks keyfile
|
for opt; do
|
||||||
[ -f "$luks_keyfile" ] &&
|
case "${opt%%=*}" in
|
||||||
install -m400 "$luks_keyfile" "${workdir}/root/luks_keyfile"
|
header)
|
||||||
|
install -m400 "${opt##*=}" "${workdir}/root/header"
|
||||||
|
luks_opts=$(printf "%s" "$luks_opts" | sed "s|${opt##*=}|/root/header|")
|
||||||
|
;;
|
||||||
|
key)
|
||||||
|
install -m400 "${opt##*=}" "${workdir}/root/key"
|
||||||
|
luks_opts=$(printf "%s" "$luks_opts" | sed "s|${opt##*=}|/root/key|")
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
install_driver() {
|
install_module()
|
||||||
driver="$1"
|
{
|
||||||
|
module="$1"
|
||||||
|
|
||||||
modprobe -S "$kernel" -D "$driver" 2> /dev/null |
|
modprobe -S "$kernel" -D "$module" 2> /dev/null |
|
||||||
|
|
||||||
while read -r driver; do
|
while read -r module || [ "$module" ]; do
|
||||||
|
|
||||||
# strip unneeded stuff
|
# strip unneeded stuff
|
||||||
driver="${driver##*builtin*}"
|
module="${module##*builtin*}"
|
||||||
driver="${driver##*net*}"
|
module="${module##*net*}"
|
||||||
driver="${driver#insmod }"
|
module="${module#insmod }"
|
||||||
|
|
||||||
# exclude user specified drivers
|
# exclude user specified modules if any
|
||||||
[ "$drivers_exclude" ] &&
|
for _exclude_module in $modules_exclude; do
|
||||||
for _exclude_driver in $drivers_exclude; do
|
module="${module##*${_exclude_module}*}"
|
||||||
driver="${driver##*${_exclude_driver}*}"
|
done
|
||||||
done
|
|
||||||
|
|
||||||
# check empty
|
# check if module already installed
|
||||||
[ "$driver" ] || continue
|
[ -e "$module" ] && [ ! -e "${workdir}${module}" ] &&
|
||||||
|
install -Dm644 "$module" "${workdir}${module}"
|
||||||
# check if driver already installed
|
done ||:
|
||||||
[ -e "${workdir}${driver}" ] ||
|
|
||||||
install -Dm644 "$driver" "${workdir}${driver}"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_hostonly_drivers() {
|
install_hostonly_modules()
|
||||||
msg info "installing hostonly drivers"
|
{
|
||||||
|
msg info "installing hostonly modules"
|
||||||
|
|
||||||
# perform autodetection of drivers via /sys
|
# perform autodetection of modules via /sys
|
||||||
find /sys -name modalias -exec sort -u {} + |
|
find /sys -name modalias -exec sort -u {} + |
|
||||||
|
|
||||||
while read -r _driver; do
|
while read -r _module || [ "$_module" ]; do
|
||||||
install_driver "$_driver"
|
install_module "$_module"
|
||||||
done
|
done ||:
|
||||||
|
|
||||||
# install user specified drivers
|
# install LVM modules
|
||||||
[ "$drivers" ] &&
|
[ "$lvm" = 1 ] &&
|
||||||
for _driver in $drivers; do
|
for _module in dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror; do
|
||||||
install_driver "$_driver"
|
install_module "$_module"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# install LUKS modules
|
||||||
|
[ "$luks" = 1 ] &&
|
||||||
|
for _module in aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent; do
|
||||||
|
install_module "$_module"
|
||||||
|
done
|
||||||
|
|
||||||
|
# install root partition module
|
||||||
|
if [ "$root_type" ]; then
|
||||||
|
install_module "$root_type"
|
||||||
|
else
|
||||||
|
while read -r _ _dir _type _ _ _; do
|
||||||
|
[ "$_dir" = / ] &&
|
||||||
|
{
|
||||||
|
install_module "$_type"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done < /proc/mounts
|
||||||
|
fi
|
||||||
|
|
||||||
|
# install user specified modules if any
|
||||||
|
for _module in $modules; do
|
||||||
|
install_module "$_module"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
install_all_drivers() {
|
install_all_modules()
|
||||||
msg info "installing all drivers"
|
{
|
||||||
|
msg info "installing all modules"
|
||||||
|
|
||||||
find \
|
find \
|
||||||
"${modker}/kernel/arch" \
|
"${modker}/kernel/arch" \
|
||||||
@ -289,202 +360,153 @@ install_all_drivers() {
|
|||||||
"${modker}/kernel/drivers/virtio" \
|
"${modker}/kernel/drivers/virtio" \
|
||||||
-type f 2> /dev/null |
|
-type f 2> /dev/null |
|
||||||
|
|
||||||
while read -r _driver; do
|
while read -r _module || [ "$_module" ]; do
|
||||||
|
|
||||||
# strip path and extension
|
# strip path and extension
|
||||||
_driver="${_driver##*/}"
|
_module="${_module##*/}"
|
||||||
_driver="${_driver%%.*}"
|
_module="${_module%%.*}"
|
||||||
|
|
||||||
install_driver "$_driver"
|
install_module "$_module"
|
||||||
done
|
done ||:
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_depmod() {
|
install_binary()
|
||||||
msg info "generating drivers list"
|
{
|
||||||
|
|
||||||
cp "${modker}/modules.builtin" \
|
|
||||||
"${modker}/modules.order" \
|
|
||||||
"${workdir}${modker}"
|
|
||||||
|
|
||||||
depmod -b "$workdir" "$kernel"
|
|
||||||
}
|
|
||||||
|
|
||||||
install_binary() {
|
|
||||||
binary=$(command -v "$1")
|
binary=$(command -v "$1")
|
||||||
realbin="$(dirname "$binary")/$(readlink "$binary")"
|
|
||||||
fullbin=$(readlink -f "$binary")
|
|
||||||
workdirbin="${workdir}/usr/bin/"
|
|
||||||
|
|
||||||
# check if binary exists
|
# check if binary exist and builtin
|
||||||
[ "$binary" ] || msg panic "$binary doesn't exists"
|
case "$binary" in
|
||||||
|
*/*)
|
||||||
|
: no operation
|
||||||
|
;;
|
||||||
|
"")
|
||||||
|
msg panic "$1 doesn't exist"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
{ IFS=:; set -- $PATH; IFS="$OLD_IFS"; }
|
||||||
|
|
||||||
|
for _dir; do
|
||||||
|
[ -x "${_dir}/${binary}" ] &&
|
||||||
|
{
|
||||||
|
binary="${_dir}/${binary}"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
done || msg panic "couldn't find external $1 binary"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# check if binary already installed
|
# check if binary already installed
|
||||||
[ -e "${workdirbin}${fullbin##*/}" ] &&
|
[ -e "${workdirbin}${binary##*/}" ] && return
|
||||||
return
|
|
||||||
|
|
||||||
# install symlinks if any
|
# iterate throught symlinks and copy them
|
||||||
[ -h "$binary" ] && {
|
while [ -h "$binary" ]; do
|
||||||
|
cp -P "$binary" "$workdirbin"
|
||||||
|
binary="${binary%/*}/$(readlink "$binary")"
|
||||||
|
done
|
||||||
|
|
||||||
# symlink may link to symlink
|
install -m755 "$binary" "${workdirbin}${binary##*/}"
|
||||||
[ -h "$realbin" ] &&
|
strip "${workdirbin}${binary##*/}" > /dev/null 2>&1 ||:
|
||||||
cp -a "$realbin" "$workdirbin"
|
|
||||||
|
|
||||||
cp -a "$binary" "$workdirbin"
|
# check if binary statically linked
|
||||||
}
|
ldd "$binary" > /dev/null 2>&1 || return 0
|
||||||
|
|
||||||
# install and strip binary
|
|
||||||
install -s -m755 "$fullbin" "${workdirbin}${fullbin##*/}"
|
|
||||||
|
|
||||||
# check static
|
|
||||||
ldd "$binary" > /dev/null 2>&1 || return
|
|
||||||
|
|
||||||
# exract paths to libraries
|
# exract paths to libraries
|
||||||
ldd "$binary" |
|
ldd "$binary" |
|
||||||
|
|
||||||
while read -r _library; do
|
while read -r _library || [ "$_library" ]; do
|
||||||
|
|
||||||
# strip unneeded stuff
|
# strip unneeded stuff
|
||||||
_library="${_library##*vdso*}"
|
_library="${_library##*vdso*}"
|
||||||
_library="${_library#* => }"
|
_library="${_library#* => }"
|
||||||
_library="${_library% *}"
|
_library="${_library% *}"
|
||||||
|
|
||||||
# check empty
|
[ -e "$_library" ] && install_library "$_library"
|
||||||
[ "$_library" ] || continue
|
done ||:
|
||||||
|
|
||||||
install_library "$_library"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_library() {
|
install_library()
|
||||||
|
{
|
||||||
library="$1"
|
library="$1"
|
||||||
reallib="$(dirname "$library")/$(readlink "$library")"
|
|
||||||
fulllib=$(readlink -f "$library")
|
|
||||||
workdirlib="${workdir}/usr/lib/"
|
|
||||||
|
|
||||||
# check if library already installed
|
# check if library already installed
|
||||||
[ -e "${workdirlib}${fulllib##*/}" ] &&
|
[ -e "${workdirlib}${library##*/}" ] && return
|
||||||
return
|
|
||||||
|
|
||||||
# install symlinks if any
|
# iterate throught symlinks and copy them
|
||||||
[ -h "$library" ] && {
|
while [ -h "$library" ]; do
|
||||||
|
cp -P "$library" "$workdirlib"
|
||||||
|
library="${library%/*}/$(readlink "$library")"
|
||||||
|
done
|
||||||
|
|
||||||
# symlink may link to symlink
|
install -m755 "$library" "${workdirlib}${library##*/}"
|
||||||
[ -h "$reallib" ] &&
|
strip "${workdirlib}${library##*/}" > /dev/null 2>&1 ||:
|
||||||
cp -a "$reallib" "$workdirlib"
|
|
||||||
|
|
||||||
cp -a "$library" "$workdirlib"
|
|
||||||
}
|
|
||||||
|
|
||||||
# install library
|
|
||||||
install -s -m755 "$fulllib" "${workdirlib}${fulllib##*/}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_files() {
|
create_initramfs()
|
||||||
msg info "installing files"
|
{
|
||||||
|
|
||||||
cat > "${workdir}/config" << EOF
|
|
||||||
debug="$debug"
|
|
||||||
init="$init"
|
|
||||||
root="$root"
|
|
||||||
root_type="$root_type"
|
|
||||||
root_opts="$root_opts"
|
|
||||||
devmgr="$devmgr"
|
|
||||||
#drivers
|
|
||||||
lvm="$lvm"
|
|
||||||
lvm_name="$lvm_name"
|
|
||||||
lvm_group="$lvm_group"
|
|
||||||
#lvm_discard
|
|
||||||
lvm_args="$lvm_args"
|
|
||||||
luks="$luks"
|
|
||||||
luks_root="$luks_root"
|
|
||||||
luks_name="$luks_name"
|
|
||||||
#luks_header
|
|
||||||
#luks_keyfile
|
|
||||||
luks_discard="$luks_discard"
|
|
||||||
luks_args="$luks_args"
|
|
||||||
EOF
|
|
||||||
|
|
||||||
install -m644 "${filesdir}/passwd" "${workdir}/etc/passwd"
|
|
||||||
install -m644 "${filesdir}/group" "${workdir}/etc/group"
|
|
||||||
install -m755 "${filesdir}/init" "${workdir}/init"
|
|
||||||
}
|
|
||||||
|
|
||||||
create_initramfs() {
|
|
||||||
msg info "creating initramfs image"
|
msg info "creating initramfs image"
|
||||||
|
|
||||||
# TODO add uncompressed option
|
# TODO add uncompressed option
|
||||||
|
|
||||||
# check if image already exist
|
# check if image already exist
|
||||||
[ "$force" = 0 ] && [ -e "$initramfs" ] &&
|
[ "$force" != 1 ] && [ -e "$output" ] &&
|
||||||
msg warn "looks like you already have initramfs image"
|
msg panic "initramfs image already exist"
|
||||||
|
|
||||||
(
|
(
|
||||||
cd "$workdir"
|
cd "$workdir"
|
||||||
find . | cpio -oH newc | ${compress:-gzip -9}
|
find . | cpio -oH newc | ${compress:-gzip -9}
|
||||||
|
|
||||||
) > "$initramfs" 2> /dev/null ||
|
) > "$output" 2> /dev/null ||
|
||||||
msg panic "failed to generate initramfs image"
|
msg panic "failed to generate initramfs image"
|
||||||
}
|
}
|
||||||
|
|
||||||
# check root
|
# int main()
|
||||||
[ "$(id -u)" = 0 ] || msg panic "must be run as root"
|
{
|
||||||
|
# check root
|
||||||
|
[ "$(id -u)" = 0 ] || msg panic "must be run as root"
|
||||||
|
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
prepare_environment
|
prepare_environment
|
||||||
|
|
||||||
# remove workdir on signals
|
[ "$debug" = 1 ] && set -x
|
||||||
# we are doing unset EXIT signal to avoid endless loop
|
|
||||||
# because afterwards we execute exit command.
|
|
||||||
# also some shells (dash,mksh,etc) doesn't exit on INT
|
|
||||||
# signal. as workaround we manually execute exit command.
|
|
||||||
# tested bash,dash,mksh,busybox sh
|
|
||||||
# TODO fix zsh, ref https://www.zsh.org/mla/users/2015/msg00436.html
|
|
||||||
trap "remove_workdir && trap - EXIT && exit" EXIT INT TERM HUP
|
|
||||||
|
|
||||||
[ "$debug" = 1 ] && {
|
# hacky, but compatible with all posix shells
|
||||||
|
trap '
|
||||||
|
ret="$?"
|
||||||
|
trap - EXIT INT
|
||||||
|
[ "$debug" = 1 ] || remove_workdir
|
||||||
|
[ "$ret" = 0 ] || msg panic "something went wrong"
|
||||||
|
' EXIT INT
|
||||||
|
|
||||||
# debug shell commands
|
create_structure
|
||||||
set -x
|
create_symlinks
|
||||||
|
|
||||||
# don't remove anything
|
[ "$lvm" = 1 ] && install_lvm
|
||||||
trap - EXIT INT TERM HUP
|
[ "$luks" = 1 ] && install_luks
|
||||||
|
|
||||||
|
# check monolithic kernel
|
||||||
|
[ "$monolith" != 1 ] && [ -d "$moddir" ] &&
|
||||||
|
{
|
||||||
|
# check hostonly mode
|
||||||
|
if [ "$hostonly" = 1 ]; then
|
||||||
|
install_hostonly_modules
|
||||||
|
else
|
||||||
|
install_all_modules
|
||||||
|
fi
|
||||||
|
|
||||||
|
for _binary in find sort modprobe; do
|
||||||
|
install_binary "$_binary"
|
||||||
|
done
|
||||||
|
|
||||||
|
cp "${modker}/modules.builtin" \
|
||||||
|
"${modker}/modules.order" \
|
||||||
|
"${workdir}${modker}"
|
||||||
|
|
||||||
|
depmod -b "$workdir" "$kernel"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_devmgr
|
||||||
|
install_requirements
|
||||||
|
create_initramfs
|
||||||
|
|
||||||
|
msg info "done! check out - $output"
|
||||||
}
|
}
|
||||||
|
|
||||||
create_workdir
|
|
||||||
create_structure
|
|
||||||
create_symlinks
|
|
||||||
|
|
||||||
[ "$lvm" = 1 ] && install_lvm
|
|
||||||
[ "$luks" = 1 ] && install_luks
|
|
||||||
|
|
||||||
# check monotihic kernel
|
|
||||||
[ "$monolith" != 1 ] && [ -d "$moddir" ] && {
|
|
||||||
|
|
||||||
# check hostonly mode
|
|
||||||
if [ "$hostonly" = 1 ]; then
|
|
||||||
install_hostonly_drivers
|
|
||||||
|
|
||||||
# install lvm drivers
|
|
||||||
[ "$lvm" = 1 ] &&
|
|
||||||
for _driver in dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror; do
|
|
||||||
install_driver "$_driver"
|
|
||||||
done
|
|
||||||
|
|
||||||
# install luks drivers
|
|
||||||
[ "$luks" = 1 ] &&
|
|
||||||
for _driver in aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent; do
|
|
||||||
install_driver "$_driver"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
install_all_drivers
|
|
||||||
fi
|
|
||||||
|
|
||||||
generate_depmod
|
|
||||||
}
|
|
||||||
|
|
||||||
install_devmgr
|
|
||||||
install_files
|
|
||||||
install_requirements
|
|
||||||
create_initramfs
|
|
||||||
|
|
||||||
msg info "done! check out $initramfs"
|
|
||||||
|
@ -1,179 +0,0 @@
|
|||||||
.TH tinyramfs 5 "March 2020" tinyramfs
|
|
||||||
|
|
||||||
.SH NAME
|
|
||||||
tinyramfs \- configuration options
|
|
||||||
|
|
||||||
.SH GENERAL
|
|
||||||
.TP
|
|
||||||
.BR \fBdebug=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable shell debugging
|
|
||||||
|
|
||||||
This option also drop you to shell after root partition being mounted in initramfs
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBforce=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Disable warning about exists initramfs image
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBinit=\fR"\&\fI /path/to/file \fR\&"
|
|
||||||
Specify init program
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBinitramfs=\fR"\&\fI /path/to/file \fR\&"
|
|
||||||
Specify initramfs output name
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBmonolith=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable monolithic kernel support
|
|
||||||
|
|
||||||
This option required if you using monolithic kernel (builtin drivers)
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBmoddir=\fR"\&\fI /path/to/dir \fR\&"
|
|
||||||
Specify directory of drivers
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBkernel=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify kernel version
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBcompress=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify compression program
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBroot=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify root partition [PARTUUID, UUID, LABEL, DEVICE]
|
|
||||||
|
|
||||||
This option is required
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBroot_type=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify root partition type
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBroot_opts=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify root partition mount options (comma separated)
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fButil_linux=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Include util-linux binaries
|
|
||||||
|
|
||||||
This option required if you need PARTUUID support
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBdevmgr=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify device manager [udev, mdev, mdevd]
|
|
||||||
|
|
||||||
This option is required
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBhostonly=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable hostonly mode
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBdrivers=\fR"\&\fI ... \fR\&"
|
|
||||||
Include additional drivers (space separated)
|
|
||||||
|
|
||||||
If host only mode enabled you need to specify your root partition driver
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBdrivers_exclude=\fR"\&\fI ... \fR\&"
|
|
||||||
Exclude specified drivers (space separated)
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBbinaries=\fR"\&\fI ... \fR\&"
|
|
||||||
Include additional binaries (space separated)
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.SH LVM
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable LVM support
|
|
||||||
|
|
||||||
This option required if you need LVM support
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm_name=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify logical volume name
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm_group=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify volume group name
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm_config=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Include config from /etc/lvm
|
|
||||||
|
|
||||||
This option overwrite lvm_discard option
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm_discard=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable TRIM requests
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm_args=\fR"\&\fI ... \fR\&"
|
|
||||||
Pass additional options to lvm
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.SH LUKS
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable LUKS support
|
|
||||||
|
|
||||||
This option required if you need LUKS support
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks_root=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify encrypted root partition [PARTUUID, UUID, LABEL, DEVICE]
|
|
||||||
|
|
||||||
This option required if you need LUKS support
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks_name=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify device mapper name
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks_header=\fR"\&\fI /path/to/file \fR\&"
|
|
||||||
Embed header into initramfs
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks_keyfile=\fR"\&\fI /path/to/file \fR\&"
|
|
||||||
Embed key into initramfs
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks_discard=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable TRIM requests
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks_args=\fR"\&\fI ... \fR\&"
|
|
||||||
Pass additional options to cryptsetup
|
|
||||||
.TP
|
|
@ -1,102 +0,0 @@
|
|||||||
.TH tinyramfs 7 "March 2020" tinyramfs
|
|
||||||
|
|
||||||
.SH NAME
|
|
||||||
tinyramfs \- kernel command line options
|
|
||||||
|
|
||||||
.SH GENERAL
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBdebug=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable shell debugging
|
|
||||||
|
|
||||||
This option also drop you to shell after root partition being mounted
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBinit=\fR"\&\fI /path/to/file \fR\&"
|
|
||||||
Specify init program
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBroot=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify root partition [PARTUUID, UUID, LABEL, DEVICE]
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBroot.type=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify root partition type
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBroot.opts=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify root partition mount options (comma separated)
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.SH LVM
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable LVM support
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm.name=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify logical volume name
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm.group=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify volume group name
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm.config=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Not implemented
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm.discard=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Not implemented
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBlvm.args=\fR"\&\fI ... \fR\&"
|
|
||||||
Pass additional options to lvm
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.SH LUKS
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable LUKS support
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks.root=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify encrypted root partition [PARTUUID, UUID, LABEL, DEVICE]
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks.name=\fR"\&\fI ... \fR\&"
|
|
||||||
Specify device mapper name
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks.header=\fR"\&\fI /path/to/file \fR\&"
|
|
||||||
Not implemented
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks.keyfile=\fR"\&\fI /path/to/file \fR\&"
|
|
||||||
Not implemented
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks.discard=\fR"\&\fI {0|1} \fR\&"
|
|
||||||
Enable TRIM requests
|
|
||||||
.TP
|
|
||||||
|
|
||||||
.TP
|
|
||||||
.BR \fBluks.args=\fR"\&\fI ... \fR\&"
|
|
||||||
Pass additional options to cryptsetup
|
|
||||||
.TP
|
|
43
usr/share/tinyramfs/device-helper
Executable file
43
usr/share/tinyramfs/device-helper
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/sh -f
|
||||||
|
#
|
||||||
|
# create /dev/disk/by-* and /dev/mapper/* symlinks
|
||||||
|
|
||||||
|
create_symlink()
|
||||||
|
{
|
||||||
|
sym="$1"
|
||||||
|
sym="${sym%\"}"
|
||||||
|
sym="${sym#\"}"
|
||||||
|
sym="${dir}${sym}"
|
||||||
|
|
||||||
|
mkdir -p "$dir" 2> /dev/null
|
||||||
|
ln -s "/dev/${MDEV}" "$sym" 2> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# int main()
|
||||||
|
{
|
||||||
|
[ "$MDEV" ] || exit 1
|
||||||
|
|
||||||
|
for line in $(blkid "$MDEV"); do
|
||||||
|
case "${line%%=*}" in
|
||||||
|
UUID)
|
||||||
|
dir="/dev/disk/by-uuid/"
|
||||||
|
create_symlink "${line##*=}"
|
||||||
|
;;
|
||||||
|
LABEL)
|
||||||
|
dir="/dev/disk/by-label/"
|
||||||
|
create_symlink "${line##*=}"
|
||||||
|
;;
|
||||||
|
PARTUUID)
|
||||||
|
dir="/dev/disk/by-partuuid/"
|
||||||
|
create_symlink "${line##*=}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -e "/sys/block/${MDEV}/dm/name" ] &&
|
||||||
|
{
|
||||||
|
mkdir -p /dev/mapper 2> /dev/null
|
||||||
|
read -r name < "/sys/block/${MDEV}/dm/name"
|
||||||
|
ln -s "/dev/${MDEV}" "/dev/mapper/${name}" 2> /dev/null
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
root:x:0:
|
|
||||||
tty:x:5:
|
|
||||||
dialout:x:11:
|
|
||||||
uucp:x:14:
|
|
||||||
kmem:x:3:
|
|
||||||
input:x:25:
|
|
||||||
video:x:13:
|
|
||||||
audio:x:12:
|
|
||||||
lp:x:10:
|
|
||||||
disk:x:9:
|
|
||||||
cdrom:x:16:
|
|
||||||
tape:x:6:
|
|
||||||
kvm:x:24:
|
|
||||||
floppy:x:8:
|
|
282
usr/share/tinyramfs/init
Normal file → Executable file
282
usr/share/tinyramfs/init
Normal file → Executable file
@ -1,168 +1,236 @@
|
|||||||
#!/sbin/busybox sh
|
#!/bin/sh -ef
|
||||||
#
|
#
|
||||||
# tiny init script
|
# tiny init
|
||||||
|
|
||||||
panic() {
|
panic()
|
||||||
|
{
|
||||||
printf "panic >> %s\n" "$1"
|
printf "panic >> %s\n" "$1"
|
||||||
|
|
||||||
# TODO fix job control
|
# see https://busybox.net/FAQ.html#job_control
|
||||||
sh
|
setsid sh -c "exec sh <> /dev/${console:-console} 2>&1" || sh
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_cmdline() {
|
findfs()
|
||||||
read -r cmdline < /proc/cmdline
|
{
|
||||||
set -f && set +f -- $cmdline
|
value=0; device=
|
||||||
|
|
||||||
for line in "$@"; do
|
case "${1%%=*}" in
|
||||||
value="${line##*=}"
|
/dev/*)
|
||||||
|
device="$1"
|
||||||
|
;;
|
||||||
|
UUID)
|
||||||
|
device="/dev/disk/by-uuid/${1##*=}"
|
||||||
|
;;
|
||||||
|
LABEL)
|
||||||
|
device="/dev/disk/by-label/${1##*=}"
|
||||||
|
;;
|
||||||
|
PARTUUID)
|
||||||
|
device="/dev/disk/by-partuuid/${1##*=}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
case "${line%%=*}" in
|
# avoid race condition
|
||||||
debug) debug="$value" ;;
|
while [ ! -e "$device" ]; do
|
||||||
init) init="$value" ;;
|
value=$(( value + 1 ))
|
||||||
root) root="$value" ;;
|
[ "$value" = 15 ] && panic "failed to lookup partition"
|
||||||
root.type) root_type="$value" ;;
|
sleep 1
|
||||||
root.opts) root_opts="$value" ;;
|
|
||||||
lvm) lvm="$value" ;;
|
|
||||||
lvm.name) lvm_name="$value" ;;
|
|
||||||
lvm.group) lvm_group="$value" ;;
|
|
||||||
lvm.args) lvm_args="$value" ;;
|
|
||||||
luks) luks="$value" ;;
|
|
||||||
luks.root) luks_root="$value" ;;
|
|
||||||
luks.name) luks_name="$value" ;;
|
|
||||||
luks.discard) luks_discard="$value" ;;
|
|
||||||
luks.args) luks_args="$value" ;;
|
|
||||||
# TODO implement
|
|
||||||
#lvm.discard) ;;
|
|
||||||
#lvm.config) ;;
|
|
||||||
#luks.header) ;;
|
|
||||||
#luks.keyfile) ;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_environment() {
|
prepare_environment()
|
||||||
/sbin/busybox --install -s
|
{
|
||||||
|
. /etc/config
|
||||||
|
|
||||||
. /config || panic "failed to source config"
|
export \
|
||||||
|
SHELL=/bin/sh \
|
||||||
|
TERM=linux \
|
||||||
|
HOME=/root \
|
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
|
||||||
|
PS1="# " \
|
||||||
|
LC_ALL=C \
|
||||||
|
LANG=C \
|
||||||
|
OLD_IFS="$IFS"
|
||||||
|
|
||||||
|
# fix for ubase mount
|
||||||
|
:> /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 mode=0755,nosuid,nodev run /run
|
mount -t devtmpfs -o nosuid,noexec,mode=0755 dev /dev
|
||||||
mount -t devtmpfs -o mode=0755,noexec,nosuid dev /dev
|
|
||||||
|
|
||||||
mkdir -pm 0755 /run/cryptsetup /run/lvm /dev/pts /dev/shm
|
|
||||||
|
|
||||||
mount -t devpts -o gid=5,mode=620,noexec,nosuid devpts /dev/pts
|
|
||||||
mount -t tmpfs -o mode=1777,noexec,nosuid,nodev shm /dev/shm
|
|
||||||
|
|
||||||
ln -s /proc/self/fd /dev/fd
|
ln -s /proc/self/fd /dev/fd
|
||||||
ln -s /proc/self/fd/0 /dev/stdin
|
ln -s /proc/self/fd/0 /dev/stdin
|
||||||
ln -s /proc/self/fd/1 /dev/stdout
|
ln -s /proc/self/fd/1 /dev/stdout
|
||||||
ln -s /proc/self/fd/2 /dev/stderr
|
ln -s /proc/self/fd/2 /dev/stderr
|
||||||
|
|
||||||
|
trap 'panic "something went wrong"' EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_devmgr() {
|
parse_cmdline()
|
||||||
|
{
|
||||||
|
[ "$break" = cmdline ] && panic "break before parse cmdline"
|
||||||
|
|
||||||
|
read -r cmdline < /proc/cmdline
|
||||||
|
|
||||||
|
for line in $cmdline; do
|
||||||
|
case "$line" in
|
||||||
|
debug | debug=1)
|
||||||
|
set -x
|
||||||
|
;;
|
||||||
|
*.*)
|
||||||
|
# TODO implement backward compatibilty with dracut, mkinitcpio, etc
|
||||||
|
: no operation
|
||||||
|
;;
|
||||||
|
*=*)
|
||||||
|
export "$line"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
export "${line}=1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_devmgr()
|
||||||
|
{
|
||||||
|
[ "$break" = devmgr ] && panic "break before setup device manager"
|
||||||
|
|
||||||
case "$devmgr" in
|
case "$devmgr" in
|
||||||
udev)
|
udev)
|
||||||
udevd -d -N never
|
udevd -d -N 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 &
|
mdev -df 2> /dev/null & mdev_pid="$!"
|
||||||
|
|
||||||
find /sys -name modalias -type f -exec sort -u {} + |
|
[ "$monolith" != 1 ] &&
|
||||||
xargs modprobe -ba
|
{
|
||||||
;;
|
set -- $(find /sys -name modalias -type f -exec sort -u {} +)
|
||||||
|
modprobe -a "$@" 2> /dev/null
|
||||||
|
}
|
||||||
|
;;
|
||||||
mdevd)
|
mdevd)
|
||||||
mdevd &
|
mdevd 2> /dev/null & mdevd_pid="$!"
|
||||||
mdevd-coldplug
|
mdevd-coldplug
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
findfs_sh() {
|
unlock_luks()
|
||||||
value="${1##*=}"
|
{
|
||||||
|
[ "$break" = luks ] && panic "break before unlock LUKS"
|
||||||
|
|
||||||
case "${1%%=*}" in
|
{ IFS=,; set -- $luks_opts; IFS="$OLD_IFS"; }
|
||||||
LABEL) device="/dev/disk/by-label/${value}" ;;
|
|
||||||
UUID) device="/dev/disk/by-uuid/${value}" ;;
|
|
||||||
PARTUUID) device="/dev/disk/by-partuuid/${value}" ;;
|
|
||||||
/dev/*) device="$1" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# avoid race condition
|
for opt; do
|
||||||
while [ ! -e "$device" ]; do
|
case "$opt" in
|
||||||
sleep 0.5
|
discard | discard=1)
|
||||||
[ "$increment" ] || increment=0
|
luks_discard="--allow-discards"
|
||||||
increment=$(( increment + 1 ))
|
;;
|
||||||
[ "$increment" = 10 ] && panic "failed to lookup partition"
|
header=*)
|
||||||
|
luks_header="--${opt}"
|
||||||
|
;;
|
||||||
|
name=*)
|
||||||
|
luks_name="${opt##*=}"
|
||||||
|
;;
|
||||||
|
key=*)
|
||||||
|
luks_key="-d ${opt##*=}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
printf "%s\n" "$device"
|
findfs "$luks_root"
|
||||||
|
|
||||||
|
set -- "--disable-locks" "$luks_key" "$luks_discard" "$luks_header" "$device" "${luks_name:-luks-${device##*/}}"
|
||||||
|
cryptsetup open $@ || panic "failed to unlock LUKS"
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_luks() {
|
trigger_lvm()
|
||||||
[ "$luks_discard" = 1 ] && luks_args="--allow-discards $luks_args"
|
{
|
||||||
[ -f /root/luks_header ] && luks_args="--header=/root/luks_header $luks_args"
|
[ "$break" = lvm ] && panic "break before trigger LVM"
|
||||||
[ -f /root/luks_keyfile ] && luks_args="--key-file=/root/luks_keyfile $luks_args"
|
|
||||||
|
|
||||||
cryptsetup $luks_args \
|
{ IFS=,; set -- $lvm_opts; IFS="$OLD_IFS"; }
|
||||||
luksOpen \
|
|
||||||
$(findfs_sh "$luks_root") \
|
for opt; do
|
||||||
${luks_name:-luks_root} ||
|
case "$opt" in
|
||||||
panic "failed to unlock luks container"
|
discard | discard=1)
|
||||||
}
|
lvm_discard="--config=devices{issue_discards=1}"
|
||||||
|
;;
|
||||||
|
config=0)
|
||||||
|
:> /etc/lvm/lvm.conf
|
||||||
|
;;
|
||||||
|
group=*)
|
||||||
|
lvm_group="${opt##*=}"
|
||||||
|
;;
|
||||||
|
name=*)
|
||||||
|
lvm_name="/${opt##*=}"
|
||||||
|
;;
|
||||||
|
tag=*)
|
||||||
|
lvm_tag="@${opt##*=}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
set -- "--sysinit" "-qq" "-ay" "$lvm_discard"
|
||||||
|
|
||||||
trigger_lvm() {
|
|
||||||
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
|
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
|
||||||
lvm lvchange $lvm_args --sysinit -q -a y "${lvm_group}/${lvm_name}" > /dev/null
|
lvchange $@ "${lvm_group}${lvm_name}"
|
||||||
elif [ "$lvm_group" ]; then
|
elif [ "$lvm_group" ]; then
|
||||||
lvm vgchange $lvm_args --sysinit -q -a y "$lvm_group" > /dev/null
|
vgchange $@ "$lvm_group"
|
||||||
|
elif [ "$lvm_tag" ]; then
|
||||||
|
lvchange $@ "$lvm_tag"
|
||||||
else
|
else
|
||||||
lvm vgchange $lvm_args --sysinit -q -a y > /dev/null
|
vgchange $@
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
mount_rootfs() {
|
mount_root()
|
||||||
mount ${root_type:+-t $root_type} \
|
{
|
||||||
${root_opts:+-o $root_opts} \
|
[ "$break" = root ] && panic "break before mount root"
|
||||||
$(findfs_sh "$root") \
|
|
||||||
/mnt/root ||
|
findfs "$root"
|
||||||
panic "failed to mount rootfs"
|
|
||||||
|
set -- "${root_type:+-t $root_type}" "${root_opts:+-o $root_opts}" "$device" "/mnt/root"
|
||||||
|
mount $@ || panic "failed to mount root"
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup()
|
||||||
|
{
|
||||||
|
[ "$break" = cleanup ] && panic "break before cleanup"
|
||||||
|
|
||||||
case "$devmgr" in
|
case "$devmgr" in
|
||||||
udev) udevadm control -e ;;
|
udev) udevadm control -e ;;
|
||||||
mdev) killall mdev ;;
|
mdev) kill "$mdev_pid" ;;
|
||||||
mdevd) killall mdevd ;;
|
mdevd) kill "$mdevd_pid" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
umount /dev /sys /proc
|
# temporary workaround until util-linux mount implements 'mount -o move'
|
||||||
|
# see https://github.com/karelzak/util-linux/issues/997
|
||||||
|
for dir in dev sys proc; do
|
||||||
|
mount -o move "$dir" "/mnt/root/${dir}" || mount --move "$dir" "/mnt/root/${dir}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_system() {
|
boot_system()
|
||||||
exec switch_root \
|
{
|
||||||
/mnt/root \
|
[ "$break" = boot ] && panic "break before boot system"
|
||||||
${init:-/sbin/init} ||
|
|
||||||
panic "failed to boot system"
|
set -- "/mnt/root" "${init:-/sbin/init}"
|
||||||
|
exec switch_root $@ 2> /dev/null || panic "failed to boot system"
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_environment
|
# int main()
|
||||||
parse_cmdline
|
{
|
||||||
[ "$debug" = 1 ] && set -x
|
prepare_environment
|
||||||
setup_devmgr
|
parse_cmdline
|
||||||
|
setup_devmgr
|
||||||
|
|
||||||
# TODO handle situations when LUKS on LVM
|
[ "$luks" = 1 ] && unlock_luks
|
||||||
[ "$luks" = 1 ] &&
|
[ "$lvm" = 1 ] && trigger_lvm
|
||||||
command -v cryptsetup > /dev/null 2>&1 && unlock_luks
|
|
||||||
|
|
||||||
[ "$lvm" = 1 ] &&
|
mount_root
|
||||||
command -v lvm > /dev/null 2>&1 && trigger_lvm
|
cleanup
|
||||||
|
boot_system
|
||||||
mount_rootfs
|
}
|
||||||
[ "$debug" = 1 ] && panic "dropping to shell"
|
|
||||||
cleanup
|
|
||||||
boot_system
|
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
# Copyright (c) 2012-2019, Piotr Karbowski <piotr.karbowski@gmail.com>
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are
|
|
||||||
# permitted provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list
|
|
||||||
# of conditions and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list
|
|
||||||
# of conditions and the following disclaimer in the documentation and/or other
|
|
||||||
# materials provided with the distribution.
|
|
||||||
# * Neither the name of the Piotr Karbowski nor the names of its contributors may be
|
|
||||||
# used to endorse or promote products derived from this software without specific
|
|
||||||
# prior written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
||||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
||||||
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US
|
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
# mdev-like-a-boss
|
|
||||||
|
|
||||||
# Syntax:
|
|
||||||
# [-]devicename_regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
|
||||||
# [-]$ENVVAR=regex user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
|
||||||
# [-]@maj,min[-min2] user:group mode [=path]|[>path]|[!] [@|$|*cmd args...]
|
|
||||||
#
|
|
||||||
# [-]: do not stop on this match, continue reading mdev.conf
|
|
||||||
# =: move, >: move and create a symlink
|
|
||||||
# !: do not create device node
|
|
||||||
# @|$|*: run cmd if $ACTION=remove, @cmd if $ACTION=add, *cmd in all cases
|
|
||||||
|
|
||||||
# support module loading on hotplug
|
|
||||||
$MODALIAS=.* 0:0 660 @modprobe -b "$MODALIAS"
|
|
||||||
|
|
||||||
# null may already exist; therefore ownership has to be changed with command
|
|
||||||
null 0:0 666 @chmod 666 $MDEV
|
|
||||||
zero 0:0 666
|
|
||||||
full 0:0 666
|
|
||||||
random 0:0 444
|
|
||||||
urandom 0:0 444
|
|
||||||
hwrandom 0:0 444
|
|
||||||
grsec 0:0 660
|
|
||||||
kmem 0:0 640
|
|
||||||
mem 0:0 640
|
|
||||||
port 0:0 640
|
|
||||||
# console may already exist; therefore ownership has to be changed with command
|
|
||||||
console 0:5 600 @chmod 600 $MDEV
|
|
||||||
ptmx 0:5 666
|
|
||||||
pty.* 0:5 660
|
|
||||||
|
|
||||||
# typical devices
|
|
||||||
tty 0:5 666
|
|
||||||
tty[0-9]* 0:5 660
|
|
||||||
vcsa*[0-9]* 0:5 660
|
|
||||||
ttyS[0-9]* 0:14 660
|
|
||||||
|
|
||||||
# block devices
|
|
||||||
ram([0-9]*) 0:9 660 >rd/%1
|
|
||||||
loop([0-9]+) 0:9 660 >loop/%1
|
|
||||||
sr[0-9]* 0:16 660 @ln -sf $MDEV cdrom
|
|
||||||
fd[0-9]* 0:8 660
|
|
||||||
SUBSYSTEM=block;.* 0:9 660 */lib/mdev/storage-device
|
|
||||||
|
|
||||||
# raid controllers
|
|
||||||
cciss!(.*) 0:9 660 =cciss/%1
|
|
||||||
ida!(.*) 0:9 660 =ida/%1
|
|
||||||
rd!(.*) 0:9 660 =rd/%1
|
|
||||||
|
|
||||||
# graphics
|
|
||||||
card[0-9] 0:13 660 =dri/
|
|
||||||
agpgart 0:0 660 >misc/
|
|
||||||
psaux 0:0 660 >misc/
|
|
||||||
rtc 0:0 664 >misc/
|
|
||||||
|
|
||||||
# input stuff
|
|
||||||
SUBSYSTEM=input;.* 0:25 660
|
|
||||||
|
|
||||||
# drm etc
|
|
||||||
dri/.* 0:13 660
|
|
||||||
|
|
||||||
# don't create old usbdev* devices.
|
|
||||||
usbdev[0-9].[0-9]* 0:0 660 !
|
|
||||||
|
|
||||||
# stop creating x:x:x:x which looks like /dev/dm-*
|
|
||||||
[0-9]+\:[0-9]+\:[0-9]+\:[0-9]+ 0:0 660 !
|
|
||||||
|
|
||||||
# /dev/cpu support.
|
|
||||||
microcode 0:0 600 =cpu/
|
|
||||||
cpu([0-9]+) 0:0 600 =cpu/%1/cpuid
|
|
||||||
msr([0-9]+) 0:0 600 =cpu/%1/msr
|
|
@ -1,2 +0,0 @@
|
|||||||
root:x:0:0::/root:/bin/sh
|
|
||||||
nobody:x:99:99::/:/bin/false
|
|
@ -1,133 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Copyright (c) 2012-2019, Piotr Karbowski <piotr.karbowski@gmail.com>
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification, are
|
|
||||||
# permitted provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this list
|
|
||||||
# of conditions and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice, this list
|
|
||||||
# of conditions and the following disclaimer in the documentation and/or other
|
|
||||||
# materials provided with the distribution.
|
|
||||||
# * Neither the name of the Piotr Karbowski nor the names of its contributors may be
|
|
||||||
# used to endorse or promote products derived from this software without specific
|
|
||||||
# prior written permission.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
||||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
||||||
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
||||||
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US
|
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
# This script meant to create /dev/disk/by-* and /dev/mapper/* symlinks.
|
|
||||||
# and remove them after storage device is removed.
|
|
||||||
# the /dev/disk/by-* handling based on the idea and proof of concept from BitJam.
|
|
||||||
|
|
||||||
# debug
|
|
||||||
#exec >> /run/debug-mdev 2>&1
|
|
||||||
#set -x
|
|
||||||
#echo '### ENV:'
|
|
||||||
#env
|
|
||||||
#echo '### CODE:'
|
|
||||||
#
|
|
||||||
|
|
||||||
umask 077
|
|
||||||
|
|
||||||
storage_dir="/tmp/.mdev-like-a-boss"
|
|
||||||
[ -d "$storage_dir" ] || mkdir "$storage_dir"
|
|
||||||
|
|
||||||
[ "$MDEV" ] || exit 2
|
|
||||||
|
|
||||||
create_uuid_label_symlink() {
|
|
||||||
target_dir="/dev/disk/by-${1}"
|
|
||||||
target_symlink="${target_dir}/${2}"
|
|
||||||
[ -e "$target_symlink" ] && return
|
|
||||||
mkdir -p "$target_dir"
|
|
||||||
ln -sf "/dev/${MDEV}" "$target_symlink"
|
|
||||||
printf "%s\n" "$target_symlink" > "${storage_dir}/storage_symlink_${1}_${MDEV}"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_symlinks() {
|
|
||||||
# Skip temp cryptsetup nodes.
|
|
||||||
case "$MDEV" in
|
|
||||||
dm-[0-9]*)
|
|
||||||
case $(cat "/sys/block/${MDEV}/dm/name") in
|
|
||||||
temporary-cryptsetup-[0-9]*)
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if command -v blkid > /dev/null 2>&1; then
|
|
||||||
blkid_output=$(blkid "/dev/${MDEV}")
|
|
||||||
eval "${blkid_output#*: }"
|
|
||||||
|
|
||||||
[ "$UUID" ] && create_uuid_label_symlink uuid "$UUID"
|
|
||||||
[ "$LABEL" ] && create_uuid_label_symlink label "$LABEL"
|
|
||||||
[ "$PARTUUID" ] && create_uuid_label_symlink partuuid "$PARTUUID"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "/sys/block/${MDEV}/dm/name" ]; then
|
|
||||||
[ -d /dev/mapper ] || mkdir /dev/mapper
|
|
||||||
if ! [ -c /dev/mapper/control ]; then
|
|
||||||
while read -r dm; do
|
|
||||||
[ "${dm#* }" = device-mapper ] && {
|
|
||||||
mknod /dev/mapper/control c 10 "${dm% *}" || exit 1
|
|
||||||
break
|
|
||||||
}
|
|
||||||
done < /proc/misc
|
|
||||||
fi
|
|
||||||
|
|
||||||
dmname=$(cat "/sys/block/${MDEV}/dm/name")
|
|
||||||
if [ "$dmname" ]; then
|
|
||||||
target_symlink="/dev/mapper/${dmname}"
|
|
||||||
[ -e "$target_symlink" ] && return
|
|
||||||
ln -sf "/dev/${MDEV}" "$target_symlink"
|
|
||||||
printf "%s\n" "$target_symlink" > "${storage_dir}/storage_symlink_mapper_${MDEV}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
set_readahead() {
|
|
||||||
read_ahead_kb_control="/sys/class/block/${MDEV}/queue/read_ahead_kb"
|
|
||||||
new_read_ahead_kb="2048"
|
|
||||||
|
|
||||||
if [ -f "$read_ahead_kb_control" ]; then
|
|
||||||
read_ahead_kb=$(cat "$read_ahead_kb_control")
|
|
||||||
if [ "$read_ahead_kb" -lt "$new_read_ahead_kb" ]; then
|
|
||||||
logger -t mdev "Changing $MDEV read_ahead_kb from $read_ahead_kb to $new_read_ahead_kb"
|
|
||||||
printf "%s" "$new_read_ahead_kb" > "$read_ahead_kb_control"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
drop_symlinks() {
|
|
||||||
for type in uuid label mapper; do
|
|
||||||
[ -f "${storage_dir}/storage_symlink_${type}_${MDEV}" ] || continue
|
|
||||||
target_symlink=$(cat "${storage_dir}/storage_symlink_${type}_${MDEV}" 2> /dev/null)
|
|
||||||
[ "$target_symlink" ] || continue
|
|
||||||
|
|
||||||
target_symlink_device=$(readlink "$target_symlink")
|
|
||||||
if [ "$target_symlink_device" = "/dev/${MDEV}" ]; then
|
|
||||||
rm "$target_symlink"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm "${storage_dir}/storage_symlink_${type}_${MDEV}"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
case "$ACTION" in
|
|
||||||
add | "")
|
|
||||||
add_symlinks
|
|
||||||
set_readahead
|
|
||||||
;;
|
|
||||||
remove)
|
|
||||||
drop_symlinks
|
|
||||||
;;
|
|
||||||
esac
|
|
Loading…
x
Reference in New Issue
Block a user