POSIX findfs, optional util-linux and more

This commit is contained in:
illiliti 2020-02-09 20:45:10 +03:00
parent fd8a9ddb7d
commit eb8b531f1d
3 changed files with 96 additions and 32 deletions

10
config
View File

@ -12,21 +12,27 @@
root="UUID=07729c48-25d8-4096-acaf-ce5322915680" root="UUID=07729c48-25d8-4096-acaf-ce5322915680"
# root type # root type
# change this if you using busybox util-linux
root_type="ext4" root_type="ext4"
# root mount options # root mount options
#root_args="" #root_args=""
# disable this if you want to get rid of util-linux
# NOTE busybox util-linux implemetation doesn't have
# PARTUUID support and proper filesystem type autodetection
use_util_linux=1
# device manager ( mdev,mdevd,udev ) # device manager ( mdev,mdevd,udev )
devmgr="mdev" devmgr="mdev"
# hostonly mode # hostonly mode
hostonly=1 hostonly=1
# drivers # custom drivers
#drivers="" #drivers=""
# binaries # custom binaries
#binaries="" #binaries=""
# LVM support # LVM support

View File

@ -56,29 +56,42 @@ check_requirements() {
modprobe --version 2>&1 | grep -q "kmod" || msg panic "kmod modprobe version doesn't installed" modprobe --version 2>&1 | grep -q "kmod" || msg panic "kmod modprobe version doesn't installed"
} || msg panic "modprobe doesn't installed" } || msg panic "modprobe doesn't installed"
# TODO need rethink
# i can fully get rid of util-linux package, but PARTUUID is
# required to boot LUKS with detached header. so stay as is(yet)
# check util-linux tools # check util-linux tools
command -v mount >/dev/null 2>&1 && { [ "$use_util_linux" = 1 ] && {
mount --version 2>&1 | grep -q "util-linux" || msg warning "util-linux mount version doesn't installed. PARTUUID support will be missing" # check mount installed
} || msg panic "mount doesn't installed" if command -v mount >/dev/null 2>&1; then
mount --version 2>&1 | grep -q "util-linux" || {
msg warning "util-linux mount version doesn't installed. PARTUUID and filesystem type autodetection support will be missing"
use_util_linux=0
}
else
msg panic "mount doesn't installed"
fi
command -v blkid >/dev/null 2>&1 && { # check blkid installed
blkid --version 2>&1 | grep -q "util-linux" || msg warning "util-linux blkid version doesn't installed. PARTUUID support will be missing" if command -v blkid >/dev/null 2>&1; then
} || msg panic "blkid doesn't installed" blkid --version 2>&1 | grep -q "util-linux" || {
msg warning "util-linux blkid version doesn't installed. PARTUUID support will be missing"
# findfs will be removed soon use_util_linux=0
command -v findfs >/dev/null 2>&1 && { }
findfs --version 2>&1 | grep -q "util-linux" || msg warning "util-linux findfs version doesn't installed. PARTUUID support will be missing" else
} || msg panic "findfs doesn't installed" msg panic "blkid doesn't installed"
fi
}
} }
# install mandatory binaries # install requirements
install_requirements() { install_requirements() {
msg info "installing requirements" msg info "installing requirements"
install_binaries busybox modprobe mount blkid findfs
# install user specified binaries
[ -n "$binaries" ] && install_binaries $binaries
# install util-linux binaries
[ "$use_util_linux" = 1 ] && install_binaries mount blkid
# install mandatory binaries
install_binaries busybox modprobe
} }
# create FHS directory structure # create FHS directory structure
@ -157,9 +170,12 @@ install_lvm() {
install -Dm644 /etc/lvm/*.conf -t "${tmpdir}/etc/lvm" || msg panic "failed to install LVM config" install -Dm644 /etc/lvm/*.conf -t "${tmpdir}/etc/lvm" || msg panic "failed to install LVM config"
else else
mkdir "${tmpdir}/etc/lvm" mkdir "${tmpdir}/etc/lvm"
cat <<EOF > "${tmpdir}/etc/lvm/lvmlocal.conf" cat <<EOF > "${tmpdir}/etc/lvm/lvm.conf"
local { devices {
issue_discards = ${lvm_discard:-0} issue_discards = ${lvm_discard:-0}
}
global {
use_lvmetad = 0 use_lvmetad = 0
} }
EOF EOF
@ -356,6 +372,7 @@ EOF
# create and compress cpio archive # create and compress cpio archive
create_initramfs() { create_initramfs() {
msg info "creating initramfs image" msg info "creating initramfs image"
# TODO rewrite this ugly mess | dash doesn't working here
{ {
( cd "$tmpdir" && { ( cd "$tmpdir" && {
find . | cpio -oH newc | gzip -9 find . | cpio -oH newc | gzip -9

63
init
View File

@ -3,7 +3,7 @@
# tiny init script # tiny init script
panic() { panic() {
printf "panic >> %s\n" "$@" && sh printf "panic >> %s\n" "$1" && sh
} }
# parse_cmdline() { # parse_cmdline() {
@ -15,6 +15,7 @@ mnt_pseudofs() {
mount -t proc none /proc mount -t proc none /proc
mount -t sysfs none /sys mount -t sysfs none /sys
mount -t devtmpfs none /dev mount -t devtmpfs none /dev
mount -t tmpfs none /tmp
} }
# setup mdev # setup mdev
@ -62,11 +63,35 @@ use_udev() {
udevadm settle udevadm settle
} }
# shell findfs
findfs_sh() {
case "${1%%=*}" in
LABEL)
printf "/dev/disk/by-label/%s\n" "${1##*=}"
;;
UUID)
printf "/dev/disk/by-uuid/%s\n" "${1##*=}"
;;
PARTUUID)
printf "/dev/disk/by-partuuid/%s\n" "${1##*=}"
;;
/dev/*)
printf "%s\n" "$1"
;;
*)
panic "findfs option broken"
;;
esac
}
# unlock LUKS container # unlock LUKS container
unlock_luks() { unlock_luks() {
# TODO implement POSIX findfs
# find device of luks root # find device of luks root
luks_root="$(findfs $luks_root)" luks_root="$(findfs_sh $luks_root)"
# TODO investigate this
# avoid race condition
[ "$devmgr" != "udev" ] && sleep 1.5
# TODO improve mapper name ( crypttab or config option ) # TODO improve mapper name ( crypttab or config option )
# unlock luks container # unlock luks container
@ -75,7 +100,7 @@ unlock_luks() {
# manually trigger LVM if udev disabled # manually trigger LVM if udev disabled
trigger_lvm() { trigger_lvm() {
lvm vgchange --sysinit -a y lvm vgchange --quiet --sysinit -a y >/dev/null
} }
# mount rootfs to /mnt/root # mount rootfs to /mnt/root
@ -84,21 +109,36 @@ mnt_rootfs() {
[ -n "$root_args" ] && mount_args="$root_args" [ -n "$root_args" ] && mount_args="$root_args"
[ -n "$root_type" ] && mount_args="$mount_args -t $root_type" [ -n "$root_type" ] && mount_args="$mount_args -t $root_type"
# find root
root="$(findfs_sh $root)"
# mount rootfs # mount rootfs
mount $mount_args "$root" /mnt/root || panic "failed to mount rootfs" mount $mount_args "$root" /mnt/root || panic "failed to mount rootfs"
} }
# kill and unmount # kill and unmount
cleanup() { cleanup() {
# stop mdev case "$devmgr" in
[ "$devmgr" = "mdev" ] && { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1 mdev)
# stop mdevd # stop mdev
[ "$devmgr" = "mdevd" ] && killall mdevd { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
# stop udev ;;
[ "$devmgr" = "udev" ] && udevadm control --exit mdevd)
# stop mdevd
killall mdevd
;;
udev)
# stop udev
udevadm control --exit
;;
esac
# TODO re-do
# if debug mode off then restore kernel logging # if debug mode off then restore kernel logging
[ "$debug" = 0 ] && printf 1 >/proc/sys/kernel/printk [ "$debug" = 0 ] && printf 1 >/proc/sys/kernel/printk
umount /dev /sys /proc
# unmount pseudofs's
umount /dev /sys /proc /tmp
} }
# exec /mnt/root/sbin/init # exec /mnt/root/sbin/init
@ -112,6 +152,7 @@ boot_system() {
# source config # source config
. /config || panic "config doesn't exists" . /config || panic "config doesn't exists"
# TODO re-do
if [ "$debug" = 1 ]; then if [ "$debug" = 1 ]; then
# debug shell commands # debug shell commands
set -x set -x