summaryrefslogtreecommitdiffstats
path: root/modules.d/90livenet
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:54:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 13:54:25 +0000
commit9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a (patch)
tree2efb72864cc69e174c9c5ee33efb88a5f1553b48 /modules.d/90livenet
parentInitial commit. (diff)
downloaddracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.tar.xz
dracut-9cb1c4df7b9ce1a9ad1312621b0f2b16a94fba3a.zip
Adding upstream version 060+5.upstream/060+5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-xmodules.d/90livenet/fetch-liveupdate.sh31
-rwxr-xr-xmodules.d/90livenet/livenet-generator.sh84
-rwxr-xr-xmodules.d/90livenet/livenetroot.sh60
-rwxr-xr-xmodules.d/90livenet/module-setup.sh24
-rwxr-xr-xmodules.d/90livenet/parse-livenet.sh33
5 files changed, 232 insertions, 0 deletions
diff --git a/modules.d/90livenet/fetch-liveupdate.sh b/modules.d/90livenet/fetch-liveupdate.sh
new file mode 100755
index 0000000..3ff2a9c
--- /dev/null
+++ b/modules.d/90livenet/fetch-liveupdate.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# fetch-liveupdate - fetch an update image for dmsquash-live media.
+# this gets called by the "initqueue/online" hook for each network interface
+# that comes online.
+
+# no updates requested? we're not needed.
+[ -e /tmp/liveupdates.info ] || return 0
+
+command -v getarg > /dev/null || . /lib/dracut-lib.sh
+command -v fetch_url > /dev/null || . /lib/url-lib.sh
+command -v unpack_img > /dev/null || . /lib/img-lib.sh
+
+read -r url < /tmp/liveupdates.info
+
+info "fetching live updates from $url"
+
+if ! fetch_url "$url" /tmp/updates.img; then
+ warn "failed to fetch update image!"
+ warn "url: $url"
+ return 1
+fi
+
+if ! unpack_img /tmp/updates.img /updates.tmp.$$; then
+ warn "failed to unpack update image!"
+ warn "url: $url"
+ return 1
+fi
+
+copytree /updates.tmp.$$ /updates
+
+mv /tmp/liveupdates.info /tmp/liveupdates.done
diff --git a/modules.d/90livenet/livenet-generator.sh b/modules.d/90livenet/livenet-generator.sh
new file mode 100755
index 0000000..3e9226b
--- /dev/null
+++ b/modules.d/90livenet/livenet-generator.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+[ -z "$root" ] && root=$(getarg root=)
+
+# support legacy syntax of passing liveimg and then just the base root
+if getargbool 0 rd.live.image -d -y liveimg; then
+ liveroot="live:$root"
+fi
+
+if [ "${root%%:*}" = "live" ]; then
+ liveroot=$root
+fi
+
+[ "${liveroot%%:*}" = "live" ] || exit 0
+
+case "$liveroot" in
+ live:nfs://* | nfs://*)
+ root="${root#live:}"
+ rootok=1
+ ;;
+ live:http://* | http://*)
+ root="${root#live:}"
+ rootok=1
+ ;;
+ live:https://* | https://*)
+ root="${root#live:}"
+ rootok=1
+ ;;
+ live:ftp://* | ftp://*)
+ root="${root#live:}"
+ rootok=1
+ ;;
+ live:torrent://* | torrent://*)
+ root="${root#live:}"
+ rootok=1
+ ;;
+ live:tftp://* | tftp://*)
+ root="${root#live:}"
+ rootok=1
+ ;;
+esac
+
+[ "$rootok" != "1" ] && exit 0
+
+GENERATOR_DIR="$2"
+[ -z "$GENERATOR_DIR" ] && exit 1
+
+[ -d "$GENERATOR_DIR" ] || mkdir -p "$GENERATOR_DIR"
+
+getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay=""
+getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes"
+[ -e /xor_overlayfs ] && xor_overlayfs="yes"
+[ -e /xor_readonly ] && xor_readonly="--readonly"
+ROOTFLAGS="$(getarg rootflags)"
+{
+ echo "[Unit]"
+ echo "Before=initrd-root-fs.target"
+ echo "[Mount]"
+ echo "Where=/sysroot"
+ if [ "$overlayfs$xor_overlayfs" = "yes" ]; then
+ echo "What=LiveOS_rootfs"
+ if [ "$readonly_overlay$xor_readonly" = "--readonly" ]; then
+ ovlfs=lowerdir=/run/overlayfs-r:/run/rootfsbase
+ else
+ ovlfs=lowerdir=/run/rootfsbase
+ fi
+ echo "Options=${ROOTFLAGS},${ovlfs},upperdir=/run/overlayfs,workdir=/run/ovlwork"
+ echo "Type=overlay"
+ _dev=LiveOS_rootfs
+ else
+ echo "What=/dev/mapper/live-rw"
+ [ -n "$ROOTFLAGS" ] && echo "Options=${ROOTFLAGS}"
+ _dev=$'dev-mapper-live\\x2drw'
+ fi
+} > "$GENERATOR_DIR"/sysroot.mount
+
+mkdir -p "$GENERATOR_DIR/$_dev.device.d"
+{
+ echo "[Unit]"
+ echo "JobTimeoutSec=3000"
+ echo "JobRunningTimeoutSec=3000"
+} > "$GENERATOR_DIR/$_dev.device.d/timeout.conf"
diff --git a/modules.d/90livenet/livenetroot.sh b/modules.d/90livenet/livenetroot.sh
new file mode 100755
index 0000000..66dd41b
--- /dev/null
+++ b/modules.d/90livenet/livenetroot.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+# livenetroot - fetch a live image from the network and run it
+
+type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh
+
+. /lib/url-lib.sh
+
+PATH=/usr/sbin:/usr/bin:/sbin:/bin
+RETRIES=${RETRIES:-100}
+SLEEP=${SLEEP:-5}
+
+[ -e /tmp/livenet.downloaded ] && exit 0
+
+# args get passed from 40network/netroot
+netroot="$2"
+liveurl="${netroot#livenet:}"
+info "fetching $liveurl"
+
+if getargbool 0 'rd.writable.fsimg'; then
+
+ imgsize=$(($(curl -sIL "$liveurl" | sed -n 's/Content-Length: *\([[:digit:]]*\).*/\1/p') / (1024 * 1024)))
+
+ check_live_ram $imgsize
+fi
+
+imgfile=
+#retry until the imgfile is populated with data or the max retries
+i=1
+while [ "$i" -le "$RETRIES" ]; do
+ imgfile=$(fetch_url "$liveurl")
+
+ # shellcheck disable=SC2181
+ if [ $? != 0 ]; then
+ warn "failed to download live image: error $?"
+ imgfile=
+ fi
+
+ if [ -n "$imgfile" -a -s "$imgfile" ]; then
+ break
+ else
+ if [ $i -ge "$RETRIES" ]; then
+ warn "failed to download live image after $i attempts."
+ exit 1
+ fi
+
+ sleep "$SLEEP"
+ fi
+
+ i=$((i + 1))
+done > /tmp/livenet.downloaded
+
+# TODO: couldn't dmsquash-live-root handle this?
+if [ "${imgfile##*.}" = "iso" ]; then
+ root=$(losetup -f)
+ losetup "$root" "$imgfile"
+else
+ root=$imgfile
+fi
+
+exec /sbin/dmsquash-live-root "$root"
diff --git a/modules.d/90livenet/module-setup.sh b/modules.d/90livenet/module-setup.sh
new file mode 100755
index 0000000..db0def5
--- /dev/null
+++ b/modules.d/90livenet/module-setup.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+# module-setup.sh for livenet
+
+# called by dracut
+check() {
+ return 255
+}
+
+# called by dracut
+depends() {
+ echo network url-lib dmsquash-live img-lib bash
+ return 0
+}
+
+# called by dracut
+install() {
+ inst_hook cmdline 29 "$moddir/parse-livenet.sh"
+ inst_hook initqueue/online 95 "$moddir/fetch-liveupdate.sh"
+ inst_script "$moddir/livenetroot.sh" "/sbin/livenetroot"
+ if dracut_module_included "systemd-initrd"; then
+ inst_script "$moddir/livenet-generator.sh" "$systemdutildir"/system-generators/dracut-livenet-generator
+ fi
+ dracut_need_initqueue
+}
diff --git a/modules.d/90livenet/parse-livenet.sh b/modules.d/90livenet/parse-livenet.sh
new file mode 100755
index 0000000..a1d14a8
--- /dev/null
+++ b/modules.d/90livenet/parse-livenet.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# live net images - just like live images, but specified like:
+# root=live:[url-to-backing-file]
+
+[ -z "$root" ] && root=$(getarg root=)
+. /lib/url-lib.sh
+
+# live updates
+updates=$(getarg live.updates=)
+if [ -n "$updates" ]; then
+ # make sure network comes up even if we're doing a local live device
+ if [ -z "$netroot" ]; then
+ echo > /tmp/net.ifaces
+ fi
+ echo "$updates" > /tmp/liveupdates.info
+ echo '[ -e /tmp/liveupdates.done ]' > "$hookdir"/initqueue/finished/liveupdates.sh
+fi
+
+str_starts "$root" "live:" && liveurl="$root"
+str_starts "$liveurl" "live:" || return
+liveurl="${liveurl#live:}"
+
+# setting netroot to "livenet:..." makes "livenetroot" get run after ifup
+if get_url_handler "$liveurl" > /dev/null; then
+ info "livenet: root image at $liveurl"
+ netroot="livenet:$liveurl"
+ root="livenet" # quiet complaints from init
+ # shellcheck disable=SC2034
+ rootok=1
+ wait_for_dev -n /dev/root
+else
+ info "livenet: no url handler for $liveurl"
+fi