From 05e2b4b7564ba517aed3e1e714235312df6349d9 Mon Sep 17 00:00:00 2001 From: Eric Hameleers Date: Fri, 15 Jun 2018 13:06:32 +0200 Subject: Add support for on-disk OS configuration file The configuration file must be in the liveslak main directory ('/liveslak' by default) and be called 'DISTRO_os.cfg' where DISTRO is the lower-case name of the distro ('slackware' by default). The following variables can be defined in the configuration file, one per line, in the format VAR=value: BLACKLIST, INIT, KEYMAP, LIVE_HOSTNAME, LOAD, LOCALE, LUKSVOL, NOLOAD, RUNLEVEL, TWEAKS, TZ, XKB. Since the configuration file is sourced by the live init script, it is OK to have comments in it that are prefixed with '#'. --- EFI/BOOT/help.txt | 5 +++++ README.txt | 5 +++++ liveinit.tpl | 38 +++++++++++++++++++++++++++++++++++++- syslinux/f3.txt | 5 +++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/EFI/BOOT/help.txt b/EFI/BOOT/help.txt index ed13122..dbfb5b2 100644 --- a/EFI/BOOT/help.txt +++ b/EFI/BOOT/help.txt @@ -66,6 +66,11 @@ swap => Allow the Live OS to activate all swap partitions on === Media tweaks === +cfg=[skip|write] => + Specify 'skip' to skip disk-based configuration file containing + OS parameters; or specify 'write' to write current OS parameters + to disk. + hostname=your_custom_hostname[,qualifier] => Specify a custom hostname. A qualifier 'fixed' can be appended to prohibit hostname modification in case of network boot. diff --git a/README.txt b/README.txt index c6c6e3b..d8a4128 100644 --- a/README.txt +++ b/README.txt @@ -330,6 +330,11 @@ swap => Allow the Live OS to activate all swap partitions on === Media tweaks === +cfg=[skip|write] => + Specify 'skip' to skip disk-based configuration file containing + OS parameters; or specify 'write' to write current OS parameters + to disk. + hostname=your_custom_hostname[,qualifier] => Specify a custom hostname. A qualifier 'fixed' can be appended to prohibit hostname modification in case of network boot. diff --git a/liveinit.tpl b/liveinit.tpl index 5cddd02..da1b4ff 100755 --- a/liveinit.tpl +++ b/liveinit.tpl @@ -2,7 +2,7 @@ # # Copyright 2004 Slackware Linux, Inc., Concord, CA, USA # Copyright 2007, 2008, 2009, 2010, 2012 Patrick J. Volkerding, Sebeka, MN, USA -# Copyright 2015, 2016, 2017 Eric Hameleers, Eindhoven, NL +# Copyright 2015, 2016, 2017, 2018 Eric Hameleers, Eindhoven, NL # All rights reserved. # # Redistribution and use of this script, with or without modification, is @@ -49,6 +49,9 @@ LIVEUID="@LIVEUID@" LIVEMEDIA="" LIVEPATH="" +DISTROCFG="@DISTRO@_os.cfg" +CFGACTION="" + # By default, let the media determine if we can write persistent changes: # However, if we define TORAM=1, we will also set VIRGIN=1 since we want # to avoid anything that writes to disk after we copy the OS to RAM. @@ -185,6 +188,10 @@ for ARG in $(cat /proc/cmdline); do # nic=::[:ipaddr:netmask[:gateway]] ENET=$(echo $ARG | cut -f2 -d=) ;; + cfg=*) + CFGACTION=$(echo $ARG | cut -f2 -d=) + if [ "${CFGACTION}" = "skip" ]; then DISTROCFG="" ; fi + ;; noload=*) NOLOAD=$(echo $ARG | cut -f2 -d=) ;; @@ -676,6 +683,35 @@ if [ "$RESCUE" = "" ]; then debugit + # liveslak can optionally load a OS config file "@DISTRO@_os.cfg" + # which contains "VARIABLE=value" lines, where VARIABLE is one of + # the following variables that are used below in the live init script: + # BLACKLIST, INIT, KEYMAP, LIVE_HOSTNAME, LOAD, LOCALE, LUKSVOL, + # NOLOAD, RUNLEVEL, TWEAKS, TZ, XKB. + if [ -z "$CFGACTION" ]; then + # Read OS configuration from disk file if present + # (prevent this by adding 'cfg=skip' to the boot commandline). + if [ -f "/mnt/media/${LIVEMAIN}/${DISTROCFG}" ]; then + source /mnt/media/${LIVEMAIN}/${DISTROCFG} + fi + elif [ "$CFGACTION" = "write" ]; then + # Write liveslak OS parameters to disk: + echo > /mnt/media/${LIVEMAIN}/${DISTROCFG} 2>/dev/null + if [ $? -ne 0 ]; then + echo "${MARKER}: Live media read-only, cannot write config file." + else + echo "${MARKER}: Writing config to /${LIVEMAIN}/${DISTROCFG}" + for LIVEPARM in \ + BLACKLIST INIT KEYMAP LIVE_HOSTNAME LOAD LOCALE LUKSVOL \ + NOLOAD RUNLEVEL TWEAKS TZ XKB ; + do + if [ -n "$(eval echo \$$LIVEPARM)" ]; then + echo $LIVEPARM=$(eval echo \$$LIVEPARM) >> /mnt/media/${LIVEMAIN}/${DISTROCFG} + fi + done + fi + fi + # Start assembling our live system components below /mnt/live : mkdir /mnt/live diff --git a/syslinux/f3.txt b/syslinux/f3.txt index 6cce00d..a5400f5 100644 --- a/syslinux/f3.txt +++ b/syslinux/f3.txt @@ -4,6 +4,11 @@ To boot with default values just press ENTER. === Media tweaks === +cfg=[skip|write] => + Specify 'skip' to skip disk-based configuration file containing + OS parameters; or specify 'write' to write current OS parameters + to disk. + hostname=your_custom_hostname[,qualifier] => Specify a custom hostname. A qualifier 'fixed' can be appended to prohibit hostname modification in case of network boot. -- cgit v1.2.3