diff options
| author | torben | 2015-11-05 15:46:17 +0100 |
|---|---|---|
| committer | torben | 2015-11-05 15:46:17 +0100 |
| commit | 5dec51bd56b86f9f480cfff76a0779eb92d9b3c8 (patch) | |
| tree | af6e5f9008b73e221ca84336cfe8f41910d4582e /builder/dnbd3-rootfs/hooks | |
| parent | Document new simplified approaches. (diff) | |
| download | systemd-init-5dec51bd56b86f9f480cfff76a0779eb92d9b3c8.tar.gz systemd-init-5dec51bd56b86f9f480cfff76a0779eb92d9b3c8.tar.xz systemd-init-5dec51bd56b86f9f480cfff76a0779eb92d9b3c8.zip | |
Rename dracut modules folder.
Diffstat (limited to 'builder/dnbd3-rootfs/hooks')
10 files changed, 247 insertions, 0 deletions
diff --git a/builder/dnbd3-rootfs/hooks/cmdline/enable-sysrq.sh b/builder/dnbd3-rootfs/hooks/cmdline/enable-sysrq.sh new file mode 100755 index 00000000..f779aa7a --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/cmdline/enable-sysrq.sh @@ -0,0 +1,2 @@ +# enables magic sysrq keys +echo 1 > /proc/sys/kernel/sysrq diff --git a/builder/dnbd3-rootfs/hooks/cmdline/prepare-network-kcl-parameter.sh b/builder/dnbd3-rootfs/hooks/cmdline/prepare-network-kcl-parameter.sh new file mode 100755 index 00000000..9f617b09 --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/cmdline/prepare-network-kcl-parameter.sh @@ -0,0 +1,36 @@ +command -v warn >/dev/null || . /lib/dracut-lib.sh + +# fakes the cmdline to fix the ip parsing in darcut's net-lib.sh +[ -d /fake ] || mkdir /fake + +# need to be a tmpfs for the hack to work +mount -t tmpfs tmpfs /fake + +for parameter in $(getargs ip=); do + local temp="$parameter:" + set -- + while [ -n "$temp" ]; do + set -- "$@" "${temp%%:*}" + temp=${temp#*:} + done + + [ -n "$1" ] && ip=$1 + [ -n "$2" ] && server_ip=$2 + [ -n "$3" ] && gateway_ip=$3 + [ -n "$4" ] && net_mask=$4 + + warn "PXE given net configuration: ip: $ip server_ip: $server_ip gateway_ip: $gateway_ip net_mask: $net_mask" + local final_dracut_ip_config="$ip::$gateway_ip:$net_mask:hiwi-test-28:eno1:none" + warn "Final dracut ip config: $final_dracut_ip_config" + sed --regexp-extended "s/ip=[^ ]*/ip=$final_dracut_ip_config/g" /proc/cmdline > /fake/cmdline +done + + +# bind mount it. Can we trust mount return codes here? +# # if so, we should check what we get in $? +mount -o bind /fake/cmdline /proc/cmdline + +# check if it worked +if ! grep 'hiwi-test-28:eno1:none' /proc/cmdline; then + warn 'Haxing cmdline did not work :( sad pandaz...' +fi diff --git a/builder/dnbd3-rootfs/hooks/cmdline/set-dracut-environment-variables.sh b/builder/dnbd3-rootfs/hooks/cmdline/set-dracut-environment-variables.sh new file mode 100755 index 00000000..6deeb78f --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/cmdline/set-dracut-environment-variables.sh @@ -0,0 +1,5 @@ +# set rootok and root as dracut expects them to be set by +# the module preparing the root filesystem. + +rootok=1 +root=block:/dev/devicemapper/root diff --git a/builder/dnbd3-rootfs/hooks/mount/mount-root-device.sh b/builder/dnbd3-rootfs/hooks/mount/mount-root-device.sh new file mode 100755 index 00000000..f0d48174 --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/mount/mount-root-device.sh @@ -0,0 +1 @@ +mount /dev/mapper/root "$NEWROOT" diff --git a/builder/dnbd3-rootfs/hooks/pre-mount/fetch-config.sh b/builder/dnbd3-rootfs/hooks/pre-mount/fetch-config.sh new file mode 100755 index 00000000..a90481c8 --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/pre-mount/fetch-config.sh @@ -0,0 +1,39 @@ +# load dracut functions +command -v getarg >/dev/null || . /lib/dracut-lib.sh + +# read SLX_SERVER and SLX_BASE from the kernel command line +SLX_SERVER=$(getarg slxsrv) +SLX_BASE=$(getarg slxbase) +SLX_CONFIG_DIR="/opt/openslx" +SLX_CONFIG_FILE="/opt/openslx/config" + +if [ -z "$SLX_SERVER" ]; then + warn "No 'slxsrv' parameter found in the kernel command line!" + warn "Skipping OpenSLX configuration..." + return 1 +fi +if [ -z "$SLX_BASE" ]; then + warn "No 'slxbase' parameter found in the kernel command line!" + warn "Skipping OpenSLX configuration..." + return 1 +fi + +info "Getting configuration from OPENSLX-Server..." +WGET="$(busybox which wget)" +if [ -z $WGET ]; then + # do nothing + warn "'wget' not found. Skipping openslx configuration..." + return 1 +fi + +# ok then we are ready to download the config +mkdir -p "${SLX_CONFIG_DIR}" +$WGET -T 5 -q "http://${SLX_SERVER}/${SLX_BASE}/config" -O "${SLX_CONFIG_FILE}" +RET="$?" +if [ $RET -ne 0 ]; then + warn "Downloading OpenSLX configuration from ${SLX_SERVER}/${SLX_BASE} failed: $RET" + emergency_shell -n "$0" + return 1 +else + return 0 +fi diff --git a/builder/dnbd3-rootfs/hooks/pre-mount/mount-qcow.sh b/builder/dnbd3-rootfs/hooks/pre-mount/mount-qcow.sh new file mode 100755 index 00000000..d70492bf --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/pre-mount/mount-qcow.sh @@ -0,0 +1,49 @@ +############################################################################### +# CHECKS +# + +SETUP_ROOTFS_SCRIPT="/sbin/setup-qcow2" + +if [ ! -e "${SETUP_ROOTFS_SCRIPT}" ]; then + warn "No such file of directory: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +if [ ! -x "${SETUP_ROOTFS_SCRIPT}" ]; then + warn "Cannot execute: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +# +# END CHECKS +############################################################################### + +############################################################################### +# MAIN CODE +# + +# ok, let's source the setup script +if ! . ${SETUP_ROOTFS_SCRIPT} ; then + warn "Could not source: ${SETUP_ROOTFS_SCRIPT}" + emergency_shell -n "Error in $0" + return 1 +fi + +# just go over the functions in the right order ;-) +for fun in connect_dnbd3 create_qcow export_qcow connect_qcow; do + if ! $fun; then + # something failed, drop a shell for debugging + warn "'$fun' failed with: $?" + emergency_shell -n "Error in $fun" + return 1 + fi +done + +# all good, we are done +return 0 + +# +# END MAIN CODE +############################################################################### diff --git a/builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh b/builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh new file mode 100755 index 00000000..8b5ea48e --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/pre-mount/prepare-root-partition.sh @@ -0,0 +1,42 @@ +function create_partition_via_offset() { + local device="$1" + local nameOrUUID="$2" + local loopDevice=$(losetup -f) + + local sectorSize=$(blockdev --getbsz $device) + local partitionInfo=$(partx --raw --noheadings --output START,NAME,UUID /dev/nbd0 2>/dev/null| grep $nameOrUUID) + local offsetSectors=$(echo $partitionInfo | cut -d' ' -f1) + if [ -z "$offsetSectors" ]; then + warn "could not find partition with label/uuid '$nameOrUUID' on device $device" + return 1 + fi + #warn $(($offsetSectors*512)) # could overflow on 32bit systems + local offsetBytes=$(echo $| awk -v x=$offsetSectors -v y=$sectorSize '{print x * y}') + + # test if mount works directly (problem with btrfs device id) + #mount -v -o loop,offset=$offsetBytes $device $mountPoint + losetup -v -o $offsetBytes $loopDevice $device + echo $loopDevice +} + +# Close previous connections to be able to run this script many times. +dnbd3-client --device /dev/dnbd0 --close && \ +dnbd3-client --host gateway --image archLinux.qcow2 --device /dev/dnbd0 && \ +qemu-nbd --connect=/dev/nbd0 /dev/dnbd0 --read-only && \ +local read_only_partition="$(create_partition_via_offset /dev/nbd0 system)" && \ +# Make read-only partition writable. +# TODO implement persistent available indicator. +if true; then + local writable_device="/dev/ram0" && \ + mknod --mode 660 "$writable_device" b 1 1 && \ + chown root.disk "$writable_device" +else + # Use next free loop device. + local writable_device="$(losetup -f)" && \ + dd if=/dev/zero of=persistent_storage.img bs=1k count=1000 && \ + losetup "$writable_device" persistent_storage.img +fi +local size="$(blockdev --getsz "$read_only_partition")" && \ +local writable_partition_name="root" && \ +dmsetup create "$writable_partition_name" --table \ + "0 $partion_size snapshot $read_only_partition $writable_device N 1" diff --git a/builder/dnbd3-rootfs/hooks/pre-pivot/mount-tmp.sh b/builder/dnbd3-rootfs/hooks/pre-pivot/mount-tmp.sh new file mode 100755 index 00000000..3e702064 --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/pre-pivot/mount-tmp.sh @@ -0,0 +1,40 @@ +# This script only checks if we found a usable partition for the +# future /tmp. The discovery of that partition is done by udev during +# the initqueue. If a valid partition is found (either GPT with the label +# OPENSLX_TMP or MBR with the type 0x44) its path will be written to +# /tmp/openslx.tmpdisk +OPENSLX_TMP_DISK_FLAG="/tmp/openslx.disk.tmp" + +if [ ! -e "$OPENSLX_TMP_DISK_FLAG" ]; then + warn "'$OPENSLX_TMP_DISK_FLAG' not found!" + warn "Systemd will manage $NEWROOT/tmp on its own." + # no partition for the future /tmp found, just + # let systemd manage it then (probably a tmpfs) + return 1 +fi + +# in /tmp/openslx.disk.tmp is the name of the device +# to mount as /tmp in the real system +# meaning we need to mount it to /sysroot/tmp here. + +OPENSLX_TMP_DISK_DEV="$(cat $OPENSLX_TMP_DISK_FLAG)" + +# sanity check: is the content a block device? +if [ ! -b "$OPENSLX_TMP_DISK_DEV" ]; then + warn "'$OPENSLX_TMP_DISK_DEV' appears not to be a block device!" + warn "Systemd will manage $NEWROOT/tmp on its own." + return 1 +fi + +# all good, keep on +if ! mount -t auto "$OPENSLX_TMP_DISK_DEV" $NEWROOT/tmp; then + # something else went wrong :( + warn "Mounting '$OPENSLX_TMP_DISK_DEV' to '$NEWROOT/tmp' failed with: $!" + warn "Systemd will manage $NEWROOT/tmp on its own." + return 1 +fi + +# still here? mount worked wohoo +# set permissions +chmod a+rwxt $NEWROOT/tmp +return 0 diff --git a/builder/dnbd3-rootfs/hooks/pre-udev/load-custom-kernel-modules.sh b/builder/dnbd3-rootfs/hooks/pre-udev/load-custom-kernel-modules.sh new file mode 100755 index 00000000..29f9f210 --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/pre-udev/load-custom-kernel-modules.sh @@ -0,0 +1,32 @@ +# include dracut-lib.sh to use 'warn' +command -v warn >/dev/null || . /lib/dracut-lib.sh + +NBD_MOD_PATH="/usr/lib/modules/current/extra/nbd.ko" +DNBD3_MOD_PATH="/usr/lib/modules/current/extra/dnbd3.ko" + +# do we actually have our modules? +if [ ! -e "${NBD_MOD_PATH}" ]; then + warn "No such file of directory: ${NBD_MOD_PATH}" + emergency_shell -n "Error in $0" + return 1 +fi +if [ ! -e "${DNBD3_MOD_PATH}" ]; then + warn "No such file of directory: ${DNBD3_MOD_PATH}" + emergency_shell -n "Error in $0" + return 1 +fi + +# load the kernel modules for dnbd3 and nbd +if ! insmod "${DNBD3_MOD_PATH}"; then + warn "Failed to load DNBD3 kernel module..." + emergency_shell -n "Error in $0" + return 1 +fi + +if ! insmod "${NBD_MOD_PATH}"; then + warn "Failed to load NBD kernel module..." + emergency_shell -n "Error in $0" + return 1 +fi + +return 0 diff --git a/builder/dnbd3-rootfs/hooks/pre-udev/setup-loopback-device.sh b/builder/dnbd3-rootfs/hooks/pre-udev/setup-loopback-device.sh new file mode 100755 index 00000000..9103afd9 --- /dev/null +++ b/builder/dnbd3-rootfs/hooks/pre-udev/setup-loopback-device.sh @@ -0,0 +1 @@ +/sbin/initqueue --name ifup-lo --unique --onetime /sbin/ifup lo -m |
