From d3ef216c34d9b8e0c720cbb3b9b3b88da63b08a2 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 15 Apr 2018 22:03:06 +0100 Subject: Support persistance and multiboot USB sticks in examples. --- examples/dracut/mgalive-parse.sh | 31 +++++++++++++++ examples/dracut/mgalive-root.sh | 84 +++++++++++++++++++++++++++++++++++++++ examples/gui/config/build.cfg | 3 ++ examples/minimal/config/build.cfg | 4 ++ examples/xfce/config/build.cfg | 3 ++ 5 files changed, 125 insertions(+) create mode 100755 examples/dracut/mgalive-parse.sh create mode 100755 examples/dracut/mgalive-root.sh diff --git a/examples/dracut/mgalive-parse.sh b/examples/dracut/mgalive-parse.sh new file mode 100755 index 0000000..c5225ba --- /dev/null +++ b/examples/dracut/mgalive-parse.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# live images are specified with +# root=mgalive:backingdev + +[ -z "$root" ] && root=$(getarg root=) + +if [ "${root%%:*}" = "mgalive" ] ; then + liveroot=$root +fi + +[ "${liveroot%%:*}" = "mgalive" ] || return + +modprobe -q loop + +case "$liveroot" in + mgalive:LABEL=*|LABEL=*) \ + root="${root#mgalive:}" + root="$(echo $root | sed 's,/,\\x2f,g')" + root="mgalive:/dev/disk/by-label/${root#LABEL=}" + rootok=1 ;; + mgalive:UUID=*|UUID=*) \ + root="${root#mgalive:}" + root="mgalive:/dev/disk/by-uuid/${root#UUID=}" + rootok=1 ;; +esac +info "root was $liveroot, is now $root" + +# make sure that init doesn't complain +[ -z "$root" ] && root="mgalive" + +wait_for_dev /live/union diff --git a/examples/dracut/mgalive-root.sh b/examples/dracut/mgalive-root.sh new file mode 100755 index 0000000..a8fee5c --- /dev/null +++ b/examples/dracut/mgalive-root.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +. /lib/dracut-lib.sh + +[ -f /tmp/root.info ] && . /tmp/root.info + +PATH=/usr/sbin:/usr/bin:/sbin:/bin + +[ -z "$1" ] && exit 1 +livedev="$1" + +# Create the live tree +mkdir -m 0755 -p /live/distrib +mkdir -m 0755 -p /live/media +mkdir -m 0755 -p /live/overlay +mkdir -m 0755 -p /live/union +mkdir -m 0755 -p /run/mgalive/ovlsize + +# Get the base device name +basedev=$(echo $livedev | sed 's,\(/dev/sd[a-z]\)1,\1,g') + +# Get the base directory for locating the loopback file. In normal use this is +# the root directory, but a multi-boot USB stick may want to override this. +basedir=$(getarg mgalive.basedir) +if [ -z "$basedir" ] ; then + basedir="/" +fi + +# Get the device or path used for persistant storage (if it exists). In normal +# use this is another partition on the same base device, but a multi-boot USB +# stick may want to override this. +overlay=$(getarg mgalive.overlay) +if [ -z "$overlay" ] ; then + overlay=`blkid -t LABEL=Mageia-Persist -o device | grep $basedev` +else + overlay=$livedev$overlay +fi + +if [ "$basedir" = "/" -a -z "$overlay" ] ; then + # Fix udev isohybrid LABEL issues (mga #3334) + # (things have moved on - this may not be needed now) + media=$basedev +else + media=$livedev +fi + +info "mgalive basedev is $basedev" +info "mgalive livedev is $livedev" +info "mgalive basedir is $basedir" +info "mgalive overlay is $overlay" + +# Mount the live media +mount -n -o ro $media /live/media + +# Mount the loopback filesystem +LOOPDEV=$( losetup -f ) +if [ -e /live/media$basedir/loopbacks/distrib-lzma.sqfs ] ; then + # Retain support for original draklive. Note that despite the file + # name, it too uses xz compression. + losetup -r $LOOPDEV /live/media$basedir/loopbacks/distrib-lzma.sqfs +else + losetup -r $LOOPDEV /live/media$basedir/loopbacks/distrib.sqfs +fi +mount -n -t squashfs -o ro $LOOPDEV /live/distrib +mount -n -t squashfs -o ro $LOOPDEV /run/mgalive/ovlsize + +# Mount the overlay filesystem +if [ -z "$overlay" ] ; then + mount -n -t tmpfs -o mode=755 none /live/overlay +else + mount -n -o noatime $overlay /live/overlay +fi +# work and memory must be on same root +mkdir -m 0755 -p /live/overlay/work +mkdir -m 0755 -p /live/overlay/memory +mount -n -t overlay overlay -o lowerdir=/live/distrib,upperdir=/live/overlay/memory,workdir=/live/overlay/work,noatime /live/union + +ln -s /live/union /dev/root + +printf '/bin/mount --rbind /live/union %s\n' "$NEWROOT" > $hookdir/mount/01-$$-live.sh + +need_shutdown + +exit 0 diff --git a/examples/gui/config/build.cfg b/examples/gui/config/build.cfg index 9e6d770..69502f6 100644 --- a/examples/gui/config/build.cfg +++ b/examples/gui/config/build.cfg @@ -125,6 +125,9 @@ my $config = { # Fix for sometimes wrong permissions after install. [ 'files/draklive-install.d/run.d/home-live-permissions.sh', '/etc/draklive-install.d/run.d/home-live-permissions.sh', { mode => 755 } ], + # Support for persistence and multi-boot USB. + # (move to the dracut package if it works) + [ '../dracut/*', '/usr/lib/dracut/modules.d/90mgalive/', { mode => 0755 } ], ], remove_files => [ (map { "/etc/modprobe.preload.d/$_" } qw(cpufreq pcmcia rfswitch)), diff --git a/examples/minimal/config/build.cfg b/examples/minimal/config/build.cfg index 03b12b1..578ba6f 100755 --- a/examples/minimal/config/build.cfg +++ b/examples/minimal/config/build.cfg @@ -124,6 +124,10 @@ my $config = { # Eject medium before live system halt/reboot. [ 'files/halt-local.service', '/etc/systemd/system/halt-local.service', { mode => 0644, no_install => 1 } ], [ 'files/halt.local', '/sbin/halt.local', { mode => 0755, no_install => 1 } ], + + # Support for persistence and multi-boot USB. + # (move to the dracut package if it works) + [ '../dracut/*', '/usr/lib/dracut/modules.d/90mgalive/', { mode => 0755 } ], ], remove_files => [ (map { "/etc/modprobe.preload.d/$_" } qw(cpufreq pcmcia rfswitch)), diff --git a/examples/xfce/config/build.cfg b/examples/xfce/config/build.cfg index db17310..e5e2d96 100644 --- a/examples/xfce/config/build.cfg +++ b/examples/xfce/config/build.cfg @@ -177,6 +177,9 @@ my $config = { # Fix for sometimes wrong permissions after install. [ 'files/draklive-install.d/run.d/home-live-permissions.sh', '/etc/draklive-install.d/run.d/home-live-permissions.sh', { mode => 755 } ], + # Support for persistence and multi-boot USB. + # (move to the dracut package if it works) + [ '../dracut/*', '/usr/lib/dracut/modules.d/90mgalive/', { mode => 0755 } ], ], remove_files => [ (map { "/etc/modprobe.preload.d/$_" } qw(cpufreq pcmcia rfswitch)), -- cgit v1.2.1