Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIAi2 WildChat-4.8M (AI2)

how to use grub-btrfs in nixos

  1. User

    how to use grub-btrfs in nixos

  2. Assistant

    Using grub-btrfs in NixOS involves setting up a Btrfs file system for your root partition and configuring GRUB to properly boot from it. Here's a step-by-step guide to get you started:

    Step 1: Setup Btrfs File System

    If you haven't already set up a Btrfs file system, you can do so during installation. Suppose you are working on a newly created partition (like /dev/sda1), you would format it with the Btrfs file system:

    sudo mkfs.btrfs /dev/sda1
    

    Step 2: Mount Btrfs Volume

    Mount the Btrfs file system to a temporary location:

    sudo mount /dev/sda1 /mnt
    

    Step 3: Install NixOS

    Create the NixOS configuration. Ensure that you're using the Btrfs file system for your root by modifying the NixOS configuration file typically located at /mnt/etc/nixos/configuration.nix.

    Set the fileSystems option to use Btrfs. Here’s an example configuration:

    {
      fileSystems."/" =
        { device = "/dev/sda1";
          fsType = "btrfs";
        };
    }
    

    You can specify additional Btrfs subvolumes if you want to mount them as well.

    Step 4: Enable GRUB for Btrfs

    In your configuration.nix, enable the GRUB bootloader and set it to support Btrfs:

    {
      boot.loader.grub.enable = true;
      boot.loader.grub.device = "/dev/sda"; # Modify this according to your setup
      boot.loader.grub.useOSProber = true;  # If you have other operating systems
    }
    

    Step 5: Configure Grub with grub-btrfs

    To utilize grub-btrfs, you can add configurations related to snapshots and root subvolumes in your configuration.nix. Here’s an example configuration:

    {
      boot.loader.grub.extraConfig = ''
        set default=0
        set timeout=5
    
        insmod btrfs
        btrfs scan
        btrfs subvolumelist
      '';
    }
    

    Step 6: Build and Switch to the Configuration

    Run the following commands to build and apply your configuration:

    sudo nixos-rebuild switch
    

    Step 7: Reboot the System

    Now, you should be able to reboot your system. If everything is configured correctly, GRUB should show the available boot options configured with grub-btrfs.

    Step 8: Creating Snapshots (Optional)

    If you want to use the snapshot capabilities of Btrfs, you can create subvolumes and snapshots. Here’s how you might create a snapshot after your system is up and running:

    sudo btrfs subvolume snapshot /mnt /mnt/@snapshot-2023-XX-XX
    

    Troubleshooting

    • GRUB Not Finding Your Installation: Make sure your Btrfs partition is correctly set up and that you have the appropriate subvolumes if you’re using them.
    • Boot Errors: Make sure the GRUB configuration is correct and that you are using the appropriate GRUB modules.

    Additional Resources

    This process should help you set up grub-btrfs on NixOS effectively! Make sure to adapt configurations according to your specific needs and setups.