From 948de104de09cc27184d97aed2fe3b758133cc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Wed, 1 Apr 2020 03:54:21 +0200 Subject: [PATCH] stage-1-init: add boot.persistence option This option allows replacing the tmpfs mounted on / by the live CD's init script with a physical device Since nixOS symlinks everything there's no trouble at all. That enables the user to easily use a nixOS live CD as a portable installation. Note that due to some limitations in how the store is mounted currently only the non-store things are persisted. --- nixos/modules/system/boot/stage-1-init.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index 607aec87f01e..54e3a691b2f8 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -144,6 +144,14 @@ for o in $(cat /proc/cmdline); do set -- $(IFS==; echo $o) stage2Init=$2 ;; + boot.persistence=*) + set -- $(IFS==; echo $o) + persistence=$2 + ;; + boot.persistence.opt=*) + set -- $(IFS==; echo $o) + persistence_opt=$2 + ;; boot.trace|debugtrace) # Show each command. set -x @@ -534,6 +542,14 @@ while read -u 3 mountPoint; do continue fi + if [ "$mountPoint" = / ] && [ "$device" = tmpfs ] && [ ! -z "$persistence" ]; then + echo persistence... + waitDevice "$persistence" + echo enabling persistence... + mountFS "$persistence" "$mountPoint" "$persistence_opt" "auto" + continue + fi + mountFS "$device" "$mountPoint" "$options" "$fsType" done