dracut/dracut-037-squash-overlayfs-live-openmamba.patch

260 lines
9.8 KiB
Diff

diff -Nru dracut-037.orig/modules.d/99squash-live/apply-live-updates.sh dracut-037/modules.d/99squash-live/apply-live-updates.sh
--- dracut-037.orig/modules.d/99squash-live/apply-live-updates.sh 1970-01-01 01:00:00.000000000 +0100
+++ dracut-037/modules.d/99squash-live/apply-live-updates.sh 2014-04-16 17:01:00.492528268 +0200
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+if [ -d /updates ]; then
+ info "Applying updates to live image..."
+ mount -o bind /run $NEWROOT/run
+ # avoid overwriting symlinks (e.g. /lib -> /usr/lib) with directories
+ (
+ cd /updates
+ find . -depth -type d | while read dir; do
+ mkdir -p "$NEWROOT/$dir"
+ done
+ find . -depth \! -type d | while read file; do
+ cp -a "$file" "$NEWROOT/$file"
+ done
+ )
+ umount $NEWROOT/run
+fi
diff -Nru dracut-037.orig/modules.d/99squash-live/module-setup.sh dracut-037/modules.d/99squash-live/module-setup.sh
--- dracut-037.orig/modules.d/99squash-live/module-setup.sh 1970-01-01 01:00:00.000000000 +0100
+++ dracut-037/modules.d/99squash-live/module-setup.sh 2014-04-16 17:15:26.401669184 +0200
@@ -0,0 +1,31 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+check() {
+ # a live host-only image doesn't really make a lot of sense
+ [[ $hostonly ]] && return 1
+ return 0
+}
+
+depends() {
+ return 0
+}
+
+installkernel() {
+ instmods squashfs loop overlayfs ehci-hcd ohci-hcd uhci-hcd xhci-hcd usb_storage iso9660
+}
+
+install() {
+ dracut_install umount dmsetup blkid dd losetup grep blockdev
+ dracut_install -o checkisomd5
+ inst_hook cmdline 30 "$moddir/parse-squash-live.sh"
+ inst_hook pre-udev 30 "$moddir/squash-live-genrules.sh"
+ inst_hook pre-udev 30 "$moddir/squash-liveiso-genrules.sh"
+ inst_hook pre-pivot 20 "$moddir/apply-live-updates.sh"
+ inst_script "$moddir/squash-live-root.sh" "/sbin/squash-live-root"
+ # should probably just be generally included
+ inst_rules 60-cdrom_id.rules
+ # fix required since systemd-udev 212 because udev now mounts in its own namespace
+ sed -i "s/MountFlags=.*/MountFlags=shared/" ${initdir}/lib/systemd/system/systemd-udevd.service
+}
diff -Nru dracut-037.orig/modules.d/99squash-live/parse-squash-live.sh dracut-037/modules.d/99squash-live/parse-squash-live.sh
--- dracut-037.orig/modules.d/99squash-live/parse-squash-live.sh 1970-01-01 01:00:00.000000000 +0100
+++ dracut-037/modules.d/99squash-live/parse-squash-live.sh 2014-04-16 17:01:00.492528268 +0200
@@ -0,0 +1,50 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+# live images are specified with
+# root=live:backingdev
+
+[ -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" ] || return
+
+modprobe -q loop
+
+case "$liveroot" in
+ live:LABEL=*|LABEL=*) \
+ root="${root#live:}"
+ root="$(echo $root | sed 's,/,\\x2f,g')"
+ root="live:/dev/disk/by-label/${root#LABEL=}"
+ rootok=1 ;;
+ live:CDLABEL=*|CDLABEL=*) \
+ root="${root#live:}"
+ root="$(echo $root | sed 's,/,\\x2f,g')"
+ root="live:/dev/disk/by-label/${root#CDLABEL=}"
+ rootok=1 ;;
+ live:UUID=*|UUID=*) \
+ root="${root#live:}"
+ root="live:/dev/disk/by-uuid/${root#UUID=}"
+ rootok=1 ;;
+ live:/*.[Ii][Ss][Oo]|/*.[Ii][Ss][Oo])
+ root="${root#live:}"
+ root="liveiso:${root}"
+ rootok=1 ;;
+ live:/dev/*)
+ rootok=1 ;;
+ live:/*.[Ii][Mm][Gg]|/*.[Ii][Mm][Gg])
+ [ -f "${root#live:}" ] && rootok=1 ;;
+esac
+info "root was $liveroot, is now $root"
+
+# make sure that init doesn't complain
+[ -z "$root" ] && root="live"
+
diff -Nru dracut-037.orig/modules.d/99squash-live/squash-live-genrules.sh dracut-037/modules.d/99squash-live/squash-live-genrules.sh
--- dracut-037.orig/modules.d/99squash-live/squash-live-genrules.sh 1970-01-01 01:00:00.000000000 +0100
+++ dracut-037/modules.d/99squash-live/squash-live-genrules.sh 2014-04-16 17:01:00.492528268 +0200
@@ -0,0 +1,16 @@
+#!/bin/sh
+if [ "${root%%:*}" = "live" ]; then
+ {
+ printf 'KERNEL=="%s", SYMLINK+="live"\n' \
+ ${root#live:/dev/}
+ printf 'SYMLINK=="%s", SYMLINK+="live"\n' \
+ ${root#live:/dev/}
+ } >> /etc/udev/rules.d/99-live-mount.rules
+ {
+ printf 'KERNEL=="%s", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/squash-live-root $env{DEVNAME}"\n' \
+ ${root#live:/dev/}
+ printf 'SYMLINK=="%s", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/squash-live-root $env{DEVNAME}"\n' \
+ ${root#live:/dev/}
+ } >> /etc/udev/rules.d/99-live-squash.rules
+ echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/squash.sh
+fi
diff -Nru dracut-037.orig/modules.d/99squash-live/squash-liveiso-genrules.sh dracut-037/modules.d/99squash-live/squash-liveiso-genrules.sh
--- dracut-037.orig/modules.d/99squash-live/squash-liveiso-genrules.sh 1970-01-01 01:00:00.000000000 +0100
+++ dracut-037/modules.d/99squash-live/squash-liveiso-genrules.sh 2014-04-16 17:01:00.492528268 +0200
@@ -0,0 +1,14 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+if [ "${root%%:*}" = "liveiso" ]; then
+ DEVLABEL=${root#liveiso:/}
+ DEVLABEL=${DEVLABEL%%/*}
+ {
+ printf 'ENV{ID_FS_LABEL}=="%s", RUN+="/bin/mkdir /%s", RUN+="/bin/mount /dev/%%k /%s", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/squash-live-root `/sbin/losetup -f --show %s` /%s"\n' \
+ ${DEVLABEL} ${DEVLABEL} ${DEVLABEL} ${root#liveiso:} ${DEVLABEL}
+# printf 'KERNEL=="loop-control", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/squash-live-root `/sbin/losetup -f --show %s` /%s"\n' \
+# ${root#liveiso:} ${DEVLABEL}
+ } >> /etc/udev/rules.d/99-liveiso-mount.rules
+ echo '[ -e /dev/root ]' > $hookdir/initqueue/finished/squash.sh
+fi
diff -Nru dracut-037.orig/modules.d/99squash-live/squash-live-root.sh dracut-037/modules.d/99squash-live/squash-live-root.sh
--- dracut-037.orig/modules.d/99squash-live/squash-live-root.sh 1970-01-01 01:00:00.000000000 +0100
+++ dracut-037/modules.d/99squash-live/squash-live-root.sh 2014-04-16 17:01:00.492528268 +0200
@@ -0,0 +1,107 @@
+#!/bin/sh
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
+PATH=/usr/sbin:/usr/bin:/sbin:/bin
+
+if getargbool 0 rd.live.debug -n -y rdlivedebug; then
+ exec > /tmp/liveroot.$$.out
+ exec 2>> /tmp/liveroot.$$.out
+ set -x
+fi
+
+[ -z "$1" ] && { warn "Missing livedvd from command line."; action_on_fail "Could not boot."; }
+livedev="$1"
+
+# With e.g. root=live:/openmamba_live/openmamba-live.iso DEVLABEL is /openmamba_live
+DEVLABEL="$2"
+
+# parse various live image specific options that make sense to be
+# specified as their own things
+live_dir=$(getarg rd.live.dir -d live_dir)
+[ -z "$live_dir" ] && live_dir="LiveOS"
+getargbool 0 rd.live.ram -d -y live_ram && live_ram="yes"
+getargbool 0 rd.live.overlay.reset -d -y reset_overlay && reset_overlay="yes"
+getargbool 0 rd.live.overlay.readonly -d -y readonly_overlay && readonly_overlay="--readonly" || readonly_overlay=""
+overlay=$(getarg rd.live.overlay -d overlay)
+
+# FIXME: we need to be able to hide the plymouth splash for the check really
+[ -b $livedev ] && fs=$(blkid -s TYPE -o value $livedev)
+if [ "$fs" = "iso9660" -o "$fs" = "udf" ]; then
+ check="yes"
+fi
+getarg rd.live.check -d check || check=""
+if [ -n "$check" ]; then
+ [ -x /bin/plymouth ] && /bin/plymouth --hide-splash
+ checkisomd5 --verbose $livedev
+ if [ $? -ne 0 ]; then
+ warn "CD check failed!"
+ action_on_fail "Could not boot."
+ fi
+ [ -x /bin/plymouth ] && /bin/plymouth --show-splash
+fi
+
+ln -s $livedev /run/initramfs/livedev
+
+getarg ro && liverw=ro
+getarg rw && liverw=rw
+[ -z "$liverw" ] && liverw=ro
+
+# FIXME: loop to wait for partition to become available
+c=0
+while [ ! -e $livedev -a $c -lt 10 ]; do
+ echo "Device $livedev not ready; sleeping 1 second"
+ sleep 1
+ c=$(($c+1))
+done
+
+# mount the backing of the live image first
+mkdir /cdrom
+mount -n -t $fstype -o $liverw $livedev /cdrom
+RES=$?
+if [ "$RES" != "0" ]; then
+ warn "Failed to mount block device of live image"
+ action_on_fail "Could not boot."
+fi
+
+if [ -e /cdrom/${live_dir}/squashfs.img ]; then
+ SQUASHED="/cdrom/${live_dir}/squashfs.img"
+fi
+
+if [ -e "$SQUASHED" ] ; then
+ echo "Mounting compressed filesystem"
+ losetup -r /dev/loop1 $SQUASHED
+ mkdir -p /squashfs
+ mount -r -t squashfs /dev/loop1 /squashfs
+
+ if [ ! "${DEVLABEL}" -o "$live_ram" = "yes" ]; then
+ echo "Creating ramdisk (dinamic size=${RAMSIZE}k) using /dev/shm..."
+ mkdir -p /ramfs
+ mount -t tmpfs tmpfs /ramfs -o mode=755
+ echo "Mounting overlayfs using ramdisk"
+ mount -t overlayfs -o lowerdir=/squashfs,upperdir=/ramfs overlayfs ${NEWROOT}
+ mkdir -p ${NEWROOT}/ramfs
+ mount -n -o bind /ramfs ${NEWROOT}/ramfs
+ else
+ echo "Mounting overlayfs using /${DEVLABEL}/rwroot"
+ mkdir -p /${DEVLABEL}/rwroot
+ mount -t overlayfs -o lowerdir=/squashfs,upperdir=/${DEVLABEL}/rwroot overlayfs ${NEWROOT}
+ mkdir -p ${NEWROOT}/flash
+ mount -n -o bind /${DEVLABEL} ${NEWROOT}/flash
+ fi
+ mkdir -p ${NEWROOT}/squashfs ${NEWROOT}/cdrom
+ mount -n -o bind /cdrom ${NEWROOT}/cdrom
+ mount -n -o bind /squashfs ${NEWROOT}/squashfs
+fi
+
+ROOTFLAGS="$(getarg rootflags)"
+if [ -n "$ROOTFLAGS" ]; then
+ ROOTFLAGS="-o $ROOTFLAGS"
+fi
+
+ln -s /dev/shm /dev/root
+printf '# already mounted' > $hookdir/mount/01-$$-live.sh
+
+exit 0