Resize root partition (btrfs)

hello, i am trying to increase the size of my root (hence also the /nix/store). i tried using gparted which didnt work, i also tried booting into a liveusb and resizing it there, also didnt work. i should guess that its hard to resize the root partition of an atomic os but im really out of luck, also there is barely any kind of docs for this.

here is my hardware conf:

{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" "wl" ];
  boot.extraModulePackages = [ config.boot.kernelPackages.broadcom_sta ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/e7942737-1956-4414-a7e3-9cfa66a9ecd6";
      fsType = "btrfs";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/4A4C-F2E8";
      fsType = "vfat";
      options = [ "fmask=0077" "dmask=0077" ];
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/6ec85843-d080-488a-8a4b-21d314f82617"; }
    ];

  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

kiss your heart if you have anything on this cuz i have an assignment due on vms, which is the reason why i am trying to increase the size of my root.

what commands did you run? what errors did you see?

Can you share the output of parted -l or fdisk -l?
In the end the situation you’re describing does not really differ from other Linux distributions. The underlying disk changed and the filesystem needs adoption in an imperative manner.

first is used gparted ran as superuser and tried to resize root, i got an error telling me that my root is read-only (duh). after that, i booted into a liveusb and tried to resize it that way using cfdisk, where i got an error telling me that my root partition has an arbitrarily big/small maximum size that i cannot exceed by resizing it.

sure

Disk /dev/sda: 113 GiB, 121332826112 bytes, 236978176 sectors
Disk model: APPLE SSD SD0128
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 4929A3E1-E26B-496D-B224-88F0C279D425

Device         Start       End   Sectors  Size Type
/dev/sda2   10307584  98807397  88499814 42.2G Linux filesystem
/dev/sda3  119828480 222232575 102404096 48.8G Linux filesystem
/dev/sda4  222232576 224329727   2097152    1G EFI System
/dev/sda5  224329728 236976127  12646400    6G Linux swap

clarification, /dev/sda3 is my root partition and /dev/sda2 is a partition i created and mounted to be able to do my pretty large assignment.
i imagine there might be a first party nix way to resize partitions but i didnt have time to rtfm yet beyond the bare minimum.

GitHub - nix-community/disko: Declarative disk partitioning and formatting using nix [maintainers=Lassulus Enzime iFreilicht Mic92 phaer] has a pretty summary of this:

NixOS is a Linux distribution where everything is described as code, with one exception: during installation, the disk partitioning and formatting are manual steps. disko aims to correct this sad :clown_face: omission.

Are both btrfs? Personally I’d remove sda2 and try to enlarge sda3 once more with parted/fdisk and btrfs filesystem resize max.

Or a quick and dirty approach if sda2 is currently not used/mounted:

btrfs device add /dev/sda2 /mnt

well, trying to resize /dev/sda3 is what ive been trying to do the whole time.
the /dev/sda2 part is just a temporary solution, besides i still have 15GB of unallocated storage that ive been trying allocate to my root partition.

this sounds like a cool idea, ill try it and see if that worked.
cheers for the input though.

FYI disko is not for resizing, it’s for when you want to wipe the whole disk and start from zero.

parted, gparted, gptfdisk, etc. are the ways to resize partitions, and your filesystem-specific tools are the same - nixos does not want to (or even try to) reimplement standard Linux tools in any way.

1 Like

okay, i fixed my issue by simply booting into a proper livecd with gparted.
gparted did everything for me🙏

1 Like