improve hostonly mode

This commit is contained in:
illiliti 2020-02-06 19:21:00 +03:00
parent ce0f46e164
commit 693dc4f519

View File

@ -90,6 +90,16 @@ install_udev() {
# handle lvm # handle lvm
install_lvm() { install_lvm() {
install_binaries lvm install_binaries lvm
# if hostonly mode enabled install only needed drivers
[ "$hostonly" = 1 ] && {
for lvm_driver in dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror; do
for lvm_driver_dep in $(modprobe -D "$lvm_driver" 2>/dev/null | cut -d " " -f 2); do
install -Dm644 "$lvm_driver_dep" "${tmpdir}${lvm_driver_dep}" 2>/dev/null
done
done
}
# FIXME this code doesn't working with udev # FIXME this code doesn't working with udev
#mkdir "$tmpdir/etc/lvm" #mkdir "$tmpdir/etc/lvm"
# use_lvmetad = 0 - avoid lvmetad missing warning message # use_lvmetad = 0 - avoid lvmetad missing warning message
@ -106,6 +116,15 @@ install_lvm() {
install_luks() { install_luks() {
install_binaries cryptsetup install_binaries cryptsetup
# if hostonly mode enabled install only needed drivers
[ "$hostonly" = 1 ] && {
for luks_driver in aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent; do
for luks_driver_dep in $(modprobe -D "$luks_driver" 2>/dev/null | cut -d " " -f 2); do
install -Dm644 "$luks_driver_dep" "${tmpdir}${luks_driver_dep}" 2>/dev/null
done
done
}
# avoid locking directory missing warning message # avoid locking directory missing warning message
mkdir "${tmpdir}/run/cryptsetup" mkdir "${tmpdir}/run/cryptsetup"
@ -118,57 +137,48 @@ install_luks() {
# copy luks header # copy luks header
[ -f "$luks_header" ] && { [ -f "$luks_header" ] && {
install -m600 "$luks_header" "${tmpdir}/root/luks_header" install -m400 "$luks_header" "${tmpdir}/root/luks_header"
luks_args="--header=/root/luks_header $luks_args" luks_args="--header=/root/luks_header $luks_args"
} }
# copy luks keyfile # copy luks keyfile
[ -f "$luks_keyfile" ] && { [ -f "$luks_keyfile" ] && {
install -m600 "$luks_keyfile" "${tmpdir}/root/luks_keyfile" install -m400 "$luks_keyfile" "${tmpdir}/root/luks_keyfile"
luks_args="--key-file=/root/luks_keyfile $luks_args" luks_args="--key-file=/root/luks_keyfile $luks_args"
} }
} }
# install drivers # install drivers
install_drivers() { install_drivers() {
modker="${moddir}${kernel}"
# TODO reimplement using functions
if [ "$hostonly" = 1 ]; then
[ -n "$root_type" ] || panic "hostonly mode required root_type option to be configured" [ -n "$root_type" ] || panic "hostonly mode required root_type option to be configured"
# perform autodetection of drivers via /sys
for driver in $(find /sys/devices -name modalias -exec sort -u "{}" "+"); do for driver in $(find /sys/devices -name modalias -exec sort -u "{}" "+"); do
for driver_dep in $(modprobe -D "$driver" 2>/dev/null | cut -d " " -f 2); do for driver_dep in $(modprobe -D "$driver" 2>/dev/null | cut -d " " -f 2); do
install -Dm644 "$driver_dep" "${tmpdir}${driver_dep}" install -Dm644 "$driver_dep" "${tmpdir}${driver_dep}" 2>/dev/null
done done
done done
# TODO autodetect root fs driver
# TODO separate root type option # TODO separate root type option
# install root fs driver # install root fs driver
for root_driver in $(modprobe -D "$root_type" 2>/dev/null | cut -d " " -f 2); do for root_driver in $(modprobe -D "$root_type" 2>/dev/null | cut -d " " -f 2); do
install -Dm644 "$root_driver" "${tmpdir}${root_driver}" install -Dm644 "$root_driver" "${tmpdir}${root_driver}" 2>/dev/null
done done
# TODO move to install_luks function # install user specified drivers
# install LUKS drivers [ -n "$drivers" ] && {
[ "$use_luks" = 1 ] && { for custom_driver in $(printf "%s\n" "$drivers" | tr " " "\n"); do
for luks_driver in aes dm-crypt sha256 sha512 wp512 ecb lrw xts twofish serpent; do for custom_driver_dep in $(modprobe -D "$custom_driver" 2>/dev/null | cut -d " " -f 2); do
for luks_driver_dep in $(modprobe -D "$luks_driver" 2>/dev/null | cut -d " " -f 2); do install -Dm644 "$custom_driver_dep" "${tmpdir}${custom_driver_dep}" 2>/dev/null
install -Dm644 "$luks_driver_dep" "${tmpdir}${luks_driver_dep}"
done done
done done
} }
# TODO move to install_lvm function
# install LVM drivers
[ "$use_lvm" = 1 ] && {
for lvm_driver in dm-thin-pool dm-multipath dm-snapshot dm-cache dm-log dm-mirror; do
for lvm_driver_dep in $(modprobe -D "$lvm_driver" 2>/dev/null | cut -d " " -f 2); do
install -Dm644 "$lvm_driver_dep" "${tmpdir}${lvm_driver_dep}"
done
done
} }
else
# find and install all drivers
install_all_drivers() {
find \ find \
"${modker}/kernel/drivers/virtio" \
"${modker}/kernel/arch" \ "${modker}/kernel/arch" \
"${modker}/kernel/crypto" \ "${modker}/kernel/crypto" \
"${modker}/kernel/fs" \ "${modker}/kernel/fs" \
@ -179,9 +189,12 @@ install_drivers() {
"${modker}/kernel/drivers/scsi" \ "${modker}/kernel/drivers/scsi" \
"${modker}/kernel/drivers/usb/storage" \ "${modker}/kernel/drivers/usb/storage" \
"${modker}/kernel/drivers/usb/host" \ "${modker}/kernel/drivers/usb/host" \
"${modker}/kernel/drivers/virtio" \
-type f | cpio -pd "$tmpdir" >/dev/null 2>&1 -type f | cpio -pd "$tmpdir" >/dev/null 2>&1
fi }
# generate "modules" files
generate_depmod() {
# install list of drivers # install list of drivers
cp "${modker}/modules.softdep" "${modker}/modules.builtin" "${modker}/modules.order" "${tmpdir}/${modker}" cp "${modker}/modules.softdep" "${modker}/modules.builtin" "${modker}/modules.order" "${tmpdir}/${modker}"
@ -233,6 +246,7 @@ install_libraries() {
done done
} }
# install important files
install_files() { install_files() {
# FIXME eof broken # FIXME eof broken
# initialize config # initialize config
@ -312,6 +326,7 @@ check_currentdir
tmpdir="$(mktemp -d /tmp/initramfs.XXXXXXXX)" || panic "failed to create working directory" tmpdir="$(mktemp -d /tmp/initramfs.XXXXXXXX)" || panic "failed to create working directory"
kernel="$(uname -r)" kernel="$(uname -r)"
moddir="/lib/modules/" moddir="/lib/modules/"
modker="${moddir}${kernel}"
check_requirements check_requirements
@ -320,7 +335,14 @@ create_symlinks
#parse_fstab #parse_fstab
#parse_crypttab #parse_crypttab
install_binaries $binaries install_binaries $binaries
if [ "$hostonly" = 1 ]; then
install_drivers install_drivers
else
install_all_drivers
fi
generate_depmod
# handle device manager # handle device manager
case "$devmgr" in case "$devmgr" in