finally
This commit is contained in:
parent
574e206ef0
commit
ead666ef0d
2
config
2
config
@ -18,7 +18,7 @@ root="UUID=07729c48-25d8-4096-acaf-ce5322915680"
|
||||
#root_args=""
|
||||
|
||||
# device manager ( mdev,mdevd,udev )
|
||||
devmgr="mdev"
|
||||
devmgr="udev"
|
||||
|
||||
# drivers
|
||||
#drivers=""
|
||||
|
17
generate
17
generate
@ -184,6 +184,7 @@ install_libraries() {
|
||||
}
|
||||
|
||||
install_files() {
|
||||
# FIXME eof broken
|
||||
# initialize config
|
||||
cat <<EOF > "${tmpdir}/config"
|
||||
debug="$debug"
|
||||
@ -191,7 +192,6 @@ root="$root"
|
||||
root_type="$root_type"
|
||||
root_args="$root_args"
|
||||
devmgr="$devmgr"
|
||||
use_mdev="1"
|
||||
#drivers="$drivers"
|
||||
use_lvm="$use_lvm"
|
||||
use_luks="$use_luks"
|
||||
@ -241,25 +241,26 @@ create_initramfs() {
|
||||
[ "$?" = 0 ] || panic "failed to generate initramfs image"
|
||||
}
|
||||
|
||||
# main function :)
|
||||
# TODO cd to script directory
|
||||
|
||||
[ "$(id -u)" = 0 ] || panic "must be run as root"
|
||||
|
||||
# remove tmpdir on exit or unexpected error
|
||||
trap remove_tmpdir EXIT INT
|
||||
|
||||
# handle debug mode
|
||||
[ "$debug" = 1 ] && {
|
||||
set -x
|
||||
trap : EXIT INT
|
||||
}
|
||||
|
||||
# variables
|
||||
tmpdir="$(mktemp -d /tmp/initramfs.XXXXXXXX)" || panic "failed to create working directory"
|
||||
kernel="$(uname -r)"
|
||||
moddir="/lib/modules/"
|
||||
|
||||
check_requirements
|
||||
|
||||
# handle debug mode
|
||||
[ "$debug" = 1 ] && {
|
||||
set -x
|
||||
trap : EXIT INT
|
||||
}
|
||||
|
||||
create_structure
|
||||
create_symlinks
|
||||
#parse_fstab
|
||||
|
37
init
37
init
@ -3,12 +3,7 @@
|
||||
# tiny init script
|
||||
|
||||
panic() {
|
||||
printf "panic >> %s\n" "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
info() {
|
||||
printf "info >> %s\n" "$@"
|
||||
printf "panic >> %s\n" "$@" && sh
|
||||
}
|
||||
|
||||
# parse_cmdline() {
|
||||
@ -43,7 +38,7 @@ use_mdev() {
|
||||
done
|
||||
|
||||
# load drivers
|
||||
find /sys -name 'modalias' -type f -exec cat '{}' + | sort -u | xargs modprobe -ba
|
||||
find /sys -name "modalias" -type f -exec cat "{}" + | sort -u | xargs modprobe -ba
|
||||
}
|
||||
|
||||
use_mdevd() {
|
||||
@ -90,26 +85,17 @@ mnt_rootfs() {
|
||||
|
||||
cleanup() {
|
||||
# clean up
|
||||
[ "$use_mdev" = 1 ] && { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
|
||||
[ "$use_mdevd" = 1 ] && killall mdevd
|
||||
[ "$use_udev" = 1 ] && udevadm control --exit
|
||||
[ "$devmgr" = "mdev" ] && { printf "" >/proc/sys/kernel/hotplug || killall uevent; } >/dev/null 2>&1
|
||||
[ "$devmgr" = "mdevd" ] && killall mdevd
|
||||
[ "$devmgr" = "udev" ] && udevadm control --exit
|
||||
umount /dev /sys /proc
|
||||
}
|
||||
|
||||
boot_system() {
|
||||
# boot system
|
||||
[ "$debug" = 1 ] && info SUCCESS
|
||||
exec switch_root /mnt/root /sbin/init || panic "failed to boot system"
|
||||
}
|
||||
|
||||
if [ "$debug" = 1 ]; then
|
||||
# debug shell commands
|
||||
set -x
|
||||
else
|
||||
# silence is golden
|
||||
printf 0 >/proc/sys/kernel/printk
|
||||
fi
|
||||
|
||||
# install busybox
|
||||
/sbin/busybox --install -s
|
||||
|
||||
@ -120,16 +106,27 @@ else
|
||||
panic "config doesn't exists"
|
||||
fi
|
||||
|
||||
if [ "$debug" = 1 ]; then
|
||||
# debug shell commands
|
||||
set -x
|
||||
else
|
||||
# silence is golden
|
||||
printf 0 >/proc/sys/kernel/printk
|
||||
fi
|
||||
|
||||
#parse_cmdline
|
||||
mnt_pseudofs
|
||||
|
||||
case "$devmgr" in
|
||||
mdev) use_mdev ;;
|
||||
mdevd) use_mdevd ;;
|
||||
udev) use_udev ;;
|
||||
*) panic "devmgr option broken" ;;
|
||||
esac
|
||||
|
||||
# TODO handle situations when LUKS on LVM
|
||||
[ "$use_luks" = 1 ] && unlock_luks
|
||||
[ "$use_lvm" = 1 ] && [ "$use_udev" = 0 ] && trigger_lvm
|
||||
[ "$use_lvm" = 1 ] && [ "$devmgr" != "udev" ] && trigger_lvm
|
||||
mnt_rootfs
|
||||
cleanup
|
||||
boot_system
|
||||
|
Loading…
Reference in New Issue
Block a user