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 type
# change this if you using busybox util-linux
root_type="ext4"
# root mount options
#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 )
devmgr="mdev"
# hostonly mode
hostonly=1
# drivers
# custom drivers
#drivers=""
# binaries
# custom binaries
#binaries=""
# 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"
} || 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
command -v mount >/dev/null 2>&1 && {
mount --version 2>&1 | grep -q "util-linux" || msg warning "util-linux mount version doesn't installed. PARTUUID support will be missing"
} || msg panic "mount doesn't installed"
[ "$use_util_linux" = 1 ] && {
# check mount 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 && {
blkid --version 2>&1 | grep -q "util-linux" || msg warning "util-linux blkid version doesn't installed. PARTUUID support will be missing"
} || msg panic "blkid doesn't installed"
# findfs will be removed soon
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"
} || msg panic "findfs doesn't installed"
# check blkid installed
if command -v blkid >/dev/null 2>&1; then
blkid --version 2>&1 | grep -q "util-linux" || {
msg warning "util-linux blkid version doesn't installed. PARTUUID support will be missing"
use_util_linux=0
}
else
msg panic "blkid doesn't installed"
fi
}
}
# install mandatory binaries
# install requirements
install_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
@ -157,9 +170,12 @@ install_lvm() {
install -Dm644 /etc/lvm/*.conf -t "${tmpdir}/etc/lvm" || msg panic "failed to install LVM config"
else
mkdir "${tmpdir}/etc/lvm"
cat <<EOF > "${tmpdir}/etc/lvm/lvmlocal.conf"
local {
cat <<EOF > "${tmpdir}/etc/lvm/lvm.conf"
devices {
issue_discards = ${lvm_discard:-0}
}
global {
use_lvmetad = 0
}
EOF
@ -356,6 +372,7 @@ EOF
# create and compress cpio archive
create_initramfs() {
msg info "creating initramfs image"
# TODO rewrite this ugly mess | dash doesn't working here
{
( cd "$tmpdir" && {
find . | cpio -oH newc | gzip -9

63
init
View File

@ -3,7 +3,7 @@
# tiny init script
panic() {
printf "panic >> %s\n" "$@" && sh
printf "panic >> %s\n" "$1" && sh
}
# parse_cmdline() {
@ -15,6 +15,7 @@ mnt_pseudofs() {
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
mount -t tmpfs none /tmp
}
# setup mdev
@ -62,11 +63,35 @@ use_udev() {
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() {
# TODO implement POSIX findfs
# 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 )
# unlock luks container
@ -75,7 +100,7 @@ unlock_luks() {
# manually trigger LVM if udev disabled
trigger_lvm() {
lvm vgchange --sysinit -a y
lvm vgchange --quiet --sysinit -a y >/dev/null
}
# mount rootfs to /mnt/root
@ -84,21 +109,36 @@ mnt_rootfs() {
[ -n "$root_args" ] && mount_args="$root_args"
[ -n "$root_type" ] && mount_args="$mount_args -t $root_type"
# find root
root="$(findfs_sh $root)"
# mount rootfs
mount $mount_args "$root" /mnt/root || panic "failed to mount rootfs"
}
# kill and unmount
cleanup() {
# stop mdev
[ "$devmgr" = "mdev" ] && { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
# stop mdevd
[ "$devmgr" = "mdevd" ] && killall mdevd
# stop udev
[ "$devmgr" = "udev" ] && udevadm control --exit
case "$devmgr" in
mdev)
# stop mdev
{ printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
;;
mdevd)
# stop mdevd
killall mdevd
;;
udev)
# stop udev
udevadm control --exit
;;
esac
# TODO re-do
# if debug mode off then restore kernel logging
[ "$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
@ -112,6 +152,7 @@ boot_system() {
# source config
. /config || panic "config doesn't exists"
# TODO re-do
if [ "$debug" = 1 ]; then
# debug shell commands
set -x