diff --git a/nixos/doc/manual/installation/installing-usb.xml b/nixos/doc/manual/installation/installing-usb.xml
index dae73306056..4a74e406b14 100644
--- a/nixos/doc/manual/installation/installing-usb.xml
+++ b/nixos/doc/manual/installation/installing-usb.xml
@@ -34,6 +34,11 @@ ISO, copy its contents verbatim to your drive, then either:
in
the kernel documentation for more details).
+
+ If you want to load the contents of the ISO to ram after bootin
+ (So you can remove the stick after bootup) you can append the parameter
+ copytoramto the options field.
+
diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh
index c75e637124a..9a125dcb0ae 100644
--- a/nixos/modules/system/boot/stage-1-init.sh
+++ b/nixos/modules/system/boot/stage-1-init.sh
@@ -154,6 +154,9 @@ for o in $(cat /proc/cmdline); do
fi
ln -s "$root" /dev/root
;;
+ copytoram)
+ copytoram=1
+ ;;
esac
done
@@ -474,6 +477,22 @@ while read -u 3 mountPoint; do
# doing something with $device right now.
udevadm settle
+ # If copytoram is enabled: skip mounting the ISO and copy its content to a tmpfs.
+ if [ -n "$copytoram" ] && [ "$device" = /dev/root ] && [ "$mountPoint" = /iso ]; then
+ fsType=$(blkid -o value -s TYPE "$device")
+ fsSize=$(blockdev --getsize64 "$device")
+
+ mkdir -p /tmp-iso
+ mount -t "$fsType" /dev/root /tmp-iso
+ mountFS tmpfs /iso size="$fsSize" tmpfs
+
+ cp -r /tmp-iso/* /mnt-root/iso/
+
+ umount /tmp-iso
+ rmdir /tmp-iso
+ continue
+ fi
+
mountFS "$device" "$mountPoint" "$options" "$fsType"
done