As an example, here’s a recent write up on how to build a tiny bootable Linux:
https://blinry.org/tiny-linux/<p>Like many of us here, I sometimes want to try out a tutorial like this briefly and then forget about it.<p>But just like the Author of the example story, you often end up installing additional packages and libraries to your system that become useless the second you close the browser window.<p>In the web, when you want a temporary browsing session, you fire up Incognito mode and then just close the window to clear history and cache.<p>In that Incognito window one can still use old bookmarks, stored passwords, access history etc. (Maybe this is a Safari Private Browsing thing only?).<p>Anyways, it has some conveniences from your base browser setp so that makes usage and alternarive logins in the Incognito window are a bit easier.<p>What I’d like, is to take this Incognito window concept and bring it to my terminal:<p>Open a terminal window into my current system, have all the access rights and history my normal shell has, but any installed packages and system file changes from the shells in that window will ”undo” / rollback on terminal close.<p>I would use it in this article example to:<p>- start a new Incognito window<p>- create a project directory under home<p>- install random packages to build kernel<p>- install qemu to run it<p>- try to get the kernel working in qemu<p>- might have multiple shells open in the terminal window, all share the temporary environment<p>- finally finish up and close window<p>After the session, the project folder in my home directory would stay intact but changes to my system files would be ”removed”.<p>My question is:
How you’d you achieve this now, without special shell/terminal software support?<p>Note that the convenience of sharing my current system environment as the basis is the key here, so just creating a separate preconfigured VM is not the goal.
Hey :) I don't know how familiar you are with Nix, but the process I describe in the blog post works almost exactly as you describe:<p>The command `nix shell nixpkgs#qemu` puts the qemu binaries in your $PATH temporarily, you can hit Ctrl-D to leave that environment. And the Nix flake I show works similarly – the specified tools are only available to you when entering the directory where the .envrc file is.<p>These techniques work without other special shell/terminal software, and you can use Nix on any operating system, not only on NixOS. This is my favorite introduction to the ecosystem, I think you might like it: <a href="https://zero-to-nix.com" rel="nofollow">https://zero-to-nix.com</a>
ZFS lets you create copy-on-write clones of live filesystems. It also lets you re-define (via `zfs promote`) which one is the clone and which one is the original.<p>Two downsides of that approach would be that 1. you would have to have ZFS as your root filesystem (which comes with its very own layers of complexity and trouble), and 2. to roll back, you'd have to reboot the system and change a kernel cmdline parameter so it boots back into the previous filesystem in its original state.<p>No matter which technique you end up using (ZFS or anything else), I think as long as you're on a bare metal system, rebooting or at least `kexec`-ing will be unavoidable. A live kernel can't change its own state back to a saved previous version, except in a few select special situations.