implement parse_cmdline
This commit is contained in:
parent
fc47af17b3
commit
01b30b6633
25
config
25
config
@ -3,7 +3,13 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# debug mode
|
# debug mode
|
||||||
#debug=1
|
shell_debug=1
|
||||||
|
|
||||||
|
# drop into shell after mnt_rootfs
|
||||||
|
#shell_break=0
|
||||||
|
|
||||||
|
# custom init
|
||||||
|
#init=""
|
||||||
|
|
||||||
# custom output name
|
# custom output name
|
||||||
#initramfs=""
|
#initramfs=""
|
||||||
@ -24,8 +30,8 @@ root="UUID=07729c48-25d8-4096-acaf-ce5322915680"
|
|||||||
# change this if you using busybox util-linux
|
# change this if you using busybox util-linux
|
||||||
root_type="ext4"
|
root_type="ext4"
|
||||||
|
|
||||||
# root mount options
|
# root options
|
||||||
#root_args=""
|
#root_opts=""
|
||||||
|
|
||||||
# disable this if you want to get rid of util-linux
|
# disable this if you want to get rid of util-linux
|
||||||
# NOTE busybox util-linux implemetation doesn't have
|
# NOTE busybox util-linux implemetation doesn't have
|
||||||
@ -47,12 +53,21 @@ hostonly=1
|
|||||||
# LVM support
|
# LVM support
|
||||||
lvm=1
|
lvm=1
|
||||||
|
|
||||||
|
# LVM logical volume name
|
||||||
|
#lvm_name=""
|
||||||
|
|
||||||
|
# LVM volume group name
|
||||||
|
#lvm_group=""
|
||||||
|
|
||||||
# LVM include config
|
# LVM include config
|
||||||
#lvm_conf=1
|
#lvm_conf=1
|
||||||
|
|
||||||
# LVM issue_discards
|
# LVM issue_discards
|
||||||
lvm_discard=1
|
lvm_discard=1
|
||||||
|
|
||||||
|
# LVM parameters
|
||||||
|
#lvm_args=""
|
||||||
|
|
||||||
# LUKS support
|
# LUKS support
|
||||||
luks=1
|
luks=1
|
||||||
|
|
||||||
@ -62,7 +77,7 @@ luks=1
|
|||||||
# LUKS encrypted root ( device,partuuid,uuid,label )
|
# LUKS encrypted root ( device,partuuid,uuid,label )
|
||||||
luks_root="PARTUUID=b04395be-f467-458b-8630-9a429b487600"
|
luks_root="PARTUUID=b04395be-f467-458b-8630-9a429b487600"
|
||||||
|
|
||||||
# luks mapper name ( /dev/mapper/<name>)
|
# luks mapper name ( /dev/mapper/<name> )
|
||||||
#luks_name=""
|
#luks_name=""
|
||||||
|
|
||||||
# LUKS detached header
|
# LUKS detached header
|
||||||
@ -74,5 +89,5 @@ luks_root="PARTUUID=b04395be-f467-458b-8630-9a429b487600"
|
|||||||
# LUKS allow_discards
|
# LUKS allow_discards
|
||||||
luks_discard=1
|
luks_discard=1
|
||||||
|
|
||||||
# LUKS unlock options
|
# LUKS parameters
|
||||||
#luks_args=""
|
#luks_args=""
|
||||||
|
28
generate
28
generate
@ -95,7 +95,7 @@ parse_fstab() {
|
|||||||
elif [ "$dir" = / ]; then
|
elif [ "$dir" = / ]; then
|
||||||
root="${root:-$fs}"
|
root="${root:-$fs}"
|
||||||
root_type="${root_type:-$type}"
|
root_type="${root_type:-$type}"
|
||||||
root_args="${root_args:-$opts}"
|
root_opts="${root_opts:-$opts}"
|
||||||
fi
|
fi
|
||||||
done < /etc/fstab
|
done < /etc/fstab
|
||||||
}
|
}
|
||||||
@ -164,9 +164,6 @@ install_luks() {
|
|||||||
# workaround for luks2
|
# workaround for luks2
|
||||||
install -s -m755 /usr/lib/libgcc_s.so.1 -t "${wrkdir}/usr/lib" || msg panic "failed to install LUKS libraries"
|
install -s -m755 /usr/lib/libgcc_s.so.1 -t "${wrkdir}/usr/lib" || msg panic "failed to install LUKS libraries"
|
||||||
|
|
||||||
# block discard support
|
|
||||||
[ "$luks_discard" = 1 ] && luks_args="--allow-discards $luks_args"
|
|
||||||
|
|
||||||
# copy luks header
|
# copy luks header
|
||||||
[ -f "$luks_header" ] && {
|
[ -f "$luks_header" ] && {
|
||||||
install -m400 "$luks_header" "${wrkdir}/root/luks_header" || msg panic "failed to copy LUKS header"
|
install -m400 "$luks_header" "${wrkdir}/root/luks_header" || msg panic "failed to copy LUKS header"
|
||||||
@ -285,20 +282,9 @@ install_library() {
|
|||||||
|
|
||||||
install_files() {
|
install_files() {
|
||||||
msg info "installing files"
|
msg info "installing files"
|
||||||
# FIXME eof broken
|
|
||||||
# initialize config
|
# initialize config
|
||||||
cat << EOF > "${wrkdir}/config"
|
sed -e "/^#/d" -e "/^$/d" ./config > "${wrkdir}/config"
|
||||||
debug="$debug"
|
|
||||||
root="$root"
|
|
||||||
root_type="$root_type"
|
|
||||||
root_args="$root_args"
|
|
||||||
devmgr="$devmgr"
|
|
||||||
#drivers="$drivers"
|
|
||||||
lvm="$lvm"
|
|
||||||
luks="$luks"
|
|
||||||
luks_root="$luks_root"
|
|
||||||
luks_args="$luks_args"
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# needed for devmgr
|
# needed for devmgr
|
||||||
cat << EOF > "${wrkdir}/etc/group"
|
cat << EOF > "${wrkdir}/etc/group"
|
||||||
@ -353,7 +339,7 @@ check_currentdir
|
|||||||
|
|
||||||
. ./config || msg panic "failed to source config"
|
. ./config || msg panic "failed to source config"
|
||||||
|
|
||||||
[ "$debug" = 1 ] && {
|
[ "$shell_debug" = 1 ] && {
|
||||||
# debug shell commands
|
# debug shell commands
|
||||||
set -x
|
set -x
|
||||||
# don't remove anything
|
# don't remove anything
|
||||||
@ -365,7 +351,7 @@ moddir="/lib/modules"
|
|||||||
|
|
||||||
create_structure
|
create_structure
|
||||||
create_symlinks
|
create_symlinks
|
||||||
[ "$fstab" = 1 ] && parse_fstab
|
[ "$fstab" = 1 ] && [ -f /etc/fstab ] && parse_fstab
|
||||||
#parse_crypttab
|
#parse_crypttab
|
||||||
install_requirements
|
install_requirements
|
||||||
|
|
||||||
@ -384,8 +370,8 @@ case "$devmgr" in
|
|||||||
*) msg panic "devmgr option broken" ;;
|
*) msg panic "devmgr option broken" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[ "$luks" = 1 ] && install_luks
|
[ "$luks" = 1 ] && [ -x "$(command -v cryptsetup)" ] && install_luks
|
||||||
[ "$lvm" = 1 ] && install_lvm
|
[ "$lvm" = 1 ] && [ -x "$(command -v lvm)" ] && install_lvm
|
||||||
|
|
||||||
install_files
|
install_files
|
||||||
create_initramfs
|
create_initramfs
|
||||||
|
71
init
71
init
@ -4,12 +4,43 @@
|
|||||||
|
|
||||||
panic() {
|
panic() {
|
||||||
printf "panic >> %s\n" "$1"
|
printf "panic >> %s\n" "$1"
|
||||||
|
# TODO fix job control
|
||||||
sh -l
|
sh -l
|
||||||
}
|
}
|
||||||
|
|
||||||
# parse_cmdline() {
|
parse_cmdline() {
|
||||||
# TODO parse /proc/cmdline
|
# store cmdline in variable
|
||||||
#}
|
read -r cmdline < /proc/cmdline || panic "failed to parse cmdline"
|
||||||
|
# turn variable into list
|
||||||
|
set -- $cmdline
|
||||||
|
|
||||||
|
# parse line by line
|
||||||
|
for line in "$@"; do
|
||||||
|
# parse options
|
||||||
|
case "${line%%=*}" in
|
||||||
|
init) init="${line##*=}" ;;
|
||||||
|
root) root="${line##*=}" ;;
|
||||||
|
root.type) root_type="${line##*=}" ;;
|
||||||
|
root.opts) root_opts="${line##*=}" ;;
|
||||||
|
lvm) lvm="${line##*=}" ;;
|
||||||
|
lvm.name) lvm_name="${line##*=}" ;;
|
||||||
|
lvm.group) lvm_group="${line##*=}" ;;
|
||||||
|
lvm.args) lvm_args="${line##*=}" ;;
|
||||||
|
luks) luks="${line##*=}" ;;
|
||||||
|
luks.root) luks_root="${line##*=}" ;;
|
||||||
|
luks.name) luks_name="${line##*=}" ;;
|
||||||
|
luks.discard) luks_discard="${line##*=}" ;;
|
||||||
|
luks.args) luks_args="${line##*=}" ;;
|
||||||
|
shell.debug) shell_debug="${line##*=}" ;;
|
||||||
|
shell.break) shell_break="${line##*=}" ;;
|
||||||
|
# TODO implement
|
||||||
|
#lvm.discard) ;;
|
||||||
|
#lvm.conf) ;;
|
||||||
|
#luks_header) ;;
|
||||||
|
#luks_keyfile) ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
mnt_pseudofs() {
|
mnt_pseudofs() {
|
||||||
mount -t proc none /proc
|
mount -t proc none /proc
|
||||||
@ -31,10 +62,8 @@ setup_mdev() {
|
|||||||
|
|
||||||
# trigger uevent for usb devices
|
# trigger uevent for usb devices
|
||||||
for device in /sys/bus/usb/devices/*; do
|
for device in /sys/bus/usb/devices/*; do
|
||||||
case ${device##*/} in
|
case "${device##*/}" in
|
||||||
[0-9]*-[0-9]*)
|
[0-9]*-[0-9]*) printf add > "${device}/uevent" ;;
|
||||||
printf add > "${device}/uevent"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -70,22 +99,29 @@ findfs_sh() {
|
|||||||
sleep 0.5
|
sleep 0.5
|
||||||
[ "$increment" ] || increment=0
|
[ "$increment" ] || increment=0
|
||||||
increment=$(( increment + 1 ))
|
increment=$(( increment + 1 ))
|
||||||
[ "$increment" = 10 ] && panic "failed to lookup rootfs"
|
[ "$increment" = 10 ] && panic "failed to lookup partition"
|
||||||
done
|
done
|
||||||
|
|
||||||
printf "%s\n" "$device"
|
printf "%s\n" "$device"
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock_luks() {
|
unlock_luks() {
|
||||||
|
[ "$luks_discard" = 1 ] && luks_args="--allow-discards $luks_args"
|
||||||
cryptsetup $luks_args luksOpen $(findfs_sh "$luks_root") ${luks_name:-luks_root} || panic "failed to unlock luks container"
|
cryptsetup $luks_args luksOpen $(findfs_sh "$luks_root") ${luks_name:-luks_root} || panic "failed to unlock luks container"
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_lvm() {
|
trigger_lvm() {
|
||||||
lvm vgchange --quiet --sysinit -a y > /dev/null
|
if [ "$lvm_group" ] && [ "$lvm_name" ]; then
|
||||||
|
lvm lvchange $lvm_args --quiet --sysinit -a y "${lvm_group}/${lvm_name}" > /dev/null
|
||||||
|
elif [ "$lvm_group" ]; then
|
||||||
|
lvm vgchange $lvm_args --quiet --sysinit -a y "$lvm_group" > /dev/null
|
||||||
|
else
|
||||||
|
lvm vgchange $lvm_args --quiet --sysinit -a y > /dev/null
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
mnt_rootfs() {
|
mnt_rootfs() {
|
||||||
mount ${root_type:+-t $root_type} ${root_args:+-o $root_args} $(findfs_sh "$root") /mnt/root || panic "failed to mount rootfs"
|
mount ${root_type:+-t $root_type} ${root_opts:+-o $root_opts} $(findfs_sh "$root") /mnt/root || panic "failed to mount rootfs"
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
@ -100,18 +136,18 @@ cleanup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boot_system() {
|
boot_system() {
|
||||||
exec switch_root /mnt/root /sbin/init || panic "failed to boot system"
|
exec switch_root /mnt/root ${init:-/sbin/init} || panic "failed to boot system"
|
||||||
}
|
}
|
||||||
|
|
||||||
/sbin/busybox --install -s
|
/sbin/busybox --install -s
|
||||||
|
|
||||||
. /config || panic "failed to source config"
|
. /config || panic "failed to source config"
|
||||||
|
|
||||||
# debug shell commands
|
|
||||||
[ "$debug" = 1 ] && set -x
|
|
||||||
|
|
||||||
#parse_cmdline
|
|
||||||
mnt_pseudofs
|
mnt_pseudofs
|
||||||
|
parse_cmdline
|
||||||
|
|
||||||
|
# debug mode
|
||||||
|
[ "$shell_debug" = 1 ] && set -x
|
||||||
|
|
||||||
case "$devmgr" in
|
case "$devmgr" in
|
||||||
mdev) setup_mdev ;;
|
mdev) setup_mdev ;;
|
||||||
@ -121,8 +157,9 @@ case "$devmgr" in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
# TODO handle situations when LUKS on LVM
|
# TODO handle situations when LUKS on LVM
|
||||||
[ "$luks" = 1 ] && unlock_luks
|
[ "$luks" = 1 ] && [ -x "$(command -v cryptsetup)" ] && unlock_luks
|
||||||
[ "$lvm" = 1 ] && trigger_lvm
|
[ "$lvm" = 1 ] && [ -x "$(command -v lvm)" ] && trigger_lvm
|
||||||
mnt_rootfs
|
mnt_rootfs
|
||||||
|
[ "$shell_break" = 1 ] && panic "dropping to shell"
|
||||||
cleanup
|
cleanup
|
||||||
boot_system
|
boot_system
|
||||||
|
Loading…
x
Reference in New Issue
Block a user