Subject: Erase / on boot

From: Tom Fitzhenry <[email-masked]>
Date: Mon, 1 Nov 2021 23:19:08 +1100

Adventures so far...

I've pasted a working system configuration at the bottom.

The idea is to boot / as tmpfs, and to mount the minimal set of 
directories from persistent storage:
* /boot
* /gnu
* /home is not strictly required, but is useful!
* /var/guix

What's working:
* Booting to GNOME
* `guix system reconfigure`
* Booting previous generations
* /etc and /var are empty upon boot, woo!

A few issues:

* Bootstrapping all this is non-trivial. It requires fiddling with 
partitions, and getting it wrong can easily make your system unbootable. 
Suggestions? Maybe the user could set up bind-mounts to map to their 
preferred partition scheme? A basic cookbook entry could bind-mount 
directories from a single ext4 partition to the required directories.

* I tried setting up /gnu and /var/guix as bind-mounts per 
<https://guix.gnu.org/cookbook/en/html_node/Setting-up-a-bind-mount.html>, 
but this didn't seem to work from initrd: the kernel panic'd on boot. I 
need to confirm this and raise a bug.

* Mounting / as tmpfs falsely requires a device, otherwise it waits 
forever on boot. I need to confirm this and raise a bug.

* Activation-on-boot fails due to inexistence of /run and /var/run. 
<https://issues.guix.gnu.org/51548> fixes this.

Here's the config:

(use-modules (gnu))
(use-service-modules desktop networking ssh xorg)

(operating-system
  (timezone "Australia/Sydney")
  (host-name "test")
  (users (cons* (user-account
                 (name "tom")
                 (comment "Tom")
                 (group "users")
                 (home-directory "/home/tom")
		;; Needed since /etc/passwd is not persisted.
		(password (crypt "password" "foobar"))
                 (supplementary-groups
                  '("wheel" "netdev" "audio" "video")))
                %base-user-accounts))
  (packages
   (append
    (list
     (specification->package "emacs-next"))
    %base-packages))
  (services
   (append
    (list (service gnome-desktop-service-type)
          (set-xorg-configuration
           (xorg-configuration
            (keyboard-layout keyboard-layout))))
    %desktop-services))
  (bootloader
   (bootloader-configuration
    (bootloader grub-bootloader)
    (target "/dev/sda")
    (keyboard-layout keyboard-layout)))
  (file-systems
   (cons* (file-system
           (mount-point "/")
           (device
	   ;; TODO: Raise bug that root-as-tmpfs falsely requires a partition.
            (uuid "59457d60-2b08-4f5c-b1c7-e29cd5f7a3da"
                  'btrfs))
	  (options "size=1G")
           (type "tmpfs"))
	 (file-system
	  (mount-point "/boot")
           (device
            (uuid "59457d60-2b08-4f5c-b1c7-e29cd5f7a3da"
                  'btrfs))
	  (options "subvol=boot")
	  (needed-for-boot? #t)
           (type "btrfs"))	
	 (file-system
	  (mount-point "/home")
           (device
            (uuid "59457d60-2b08-4f5c-b1c7-e29cd5f7a3da"
                  'btrfs))
	  (options "subvol=home")
           (type "btrfs"))
  	 (file-system
	  (mount-point "/var/guix")
           (device
            (uuid "59457d60-2b08-4f5c-b1c7-e29cd5f7a3da"
                  'btrfs))
	  (options "subvol=var/guix")
	  ;; Needed to boot old generations, which needs /var/guix/profiles/
	  (needed-for-boot? #t)
           (type "btrfs"))
	 (file-system
	  (mount-point "/gnu")
           (device
            (uuid "59457d60-2b08-4f5c-b1c7-e29cd5f7a3da"
                  'btrfs))
	  (options "subvol=gnu")
	  (needed-for-boot? #t)
           (type "btrfs"))
          %base-file-systems)))