Because systemd-boot stores linux kernel and initrd on EFI partition, I am occasionally forced to nix-collect-garbage -d, so sudo nixos-rebuild switch does not output ‘No space left on device’.
There are some ways to deal with fulled EFI partition:
But I want to deal with this problem by moving EFI partition to another place on disk where there is more room. I don’t want to enlarge current EFI partition because I don’t want to move Windows partition or MSR.
It was working, but since the 100MB old partition was still being recognized as ‘system’ in Windows Disk Manager and using it. Loaded EasyUEFI, chose the Rebuild Windows System partition option, select the boot partition (C: drive) and the system partition (esp), and it will rebuild correctly. Windows was then recognizing the 500MB partition as ESP Boot System and Windows 10 boots up correctly. I was able to delete the 100MB old partition. You might be able to do the same thing without using EasyUEFI via command line, but this was quicker and easier.
Do you know how to make it work without using EasyUEFI or using windows command line?
That SO answer was in the context of me solving exactly the same problem. On my side, I think I’ve just moved windows partitions (including MSR) using gparted, and nothing seems to have been obviously broken
efibootmgr is the way to do it through Linux. As a word of warning, I’ve semi-fried a buggy motherboard with that command before, though I guess EFI motherboards are more stable nowadays?
No, sadly. There might be something out there, but I stuck to the manual and figuring it out by hand.
It should be fairly straightforward, make a new partition, copy over the contents, set your system to boot from the new one using efibootmgr while being careful to keep the original around so that you can use a rescue disk to set it back to the original partition, and then once you’ve verified it’s all working delete the old partition.
That is the theory I think, the devil is in the details. You’ll likely have to change some of your nixos config for this to work (mainly fstab configuration), and I don’t know enough about windows boot to guarantee this will (still) work there - it might also have state elsewhere that refers to the old partition.
I just know that efibootmgr is how you set efi vars from Linux, and that a few years ago I just about succeeded with this exact problem while making my motherboard unable to change its boot order again
$ sgdisk -u 1:2b95e4aa-736e-45a8-b654-9330261c002f /dev/nvme0n1p8
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory.
***************************************************************
Non-GPT disk; not saving changes. Use -g to override.
$ gdisk /dev/nvme0n1
GPT fdisk (gdisk) version 1.0.7
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): ?
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu
Command (? for help): x
Expert command (? for help): ?
a set attributes
c change partition GUID
d display the sector alignment value
e relocate backup data structures to the end of the disk
f randomize disk and partition unique GUIDs
g change disk GUID
h recompute CHS values in protective/hybrid MBR
i show detailed information on a partition
j move the main partition table
l set the sector alignment value
m return to main menu
n create a new protective MBR
o print protective MBR data
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s resize partition table
t transpose two partition table entries
u replicate partition table on new device
v verify disk
w write table to disk and exit
z zap (destroy) GPT data structures and exit
? print this menu
Expert command (? for help): c
Partition number (1-8): 8
Enter the partition's new unique GUID ('R' to randomize): 2b95e4aa-736e-45a8-b654-9330261c002f
New GUID is 2B95E4AA-736E-45A8-B654-9330261C002F
Expert command (? for help): p
Disk /dev/nvme0n1: 2000409264 sectors, 953.9 GiB
Model: Lexar 1TB SSD
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): DE6B70B1-1E09-4975-8BBA-495DE4091F63
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2000409230
Partitions will be aligned on 2048-sector boundaries
Total free space is 6091373 sectors (2.9 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 616447 300.0 MiB 0700 Basic data partition
2 616448 821247 100.0 MiB 0700 EFI System Partition
3 821248 1083391 128.0 MiB 0C01 Microsoft reserved ...
4 1083392 254789631 121.0 GiB 0700 Basic data partition
5 254789632 1795608575 734.7 GiB 0700 Basic data partition
6 1795608576 1949990911 73.6 GiB 8300
7 1949990912 1990223871 19.2 GiB 8300
8 1996312576 2000408575 2.0 GiB 0700
Expert command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
$ partprobe
$ blkid
/dev/nvme0n1p1: LABEL="Windows RE tools" BLOCK_SIZE="512" UUID="3C7CF7997CF74C60" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="593e6f89-fa68-472f-85d7-b6fe1dbb2e56"
/dev/nvme0n1p2: LABEL_FATBOOT="SYSTEM" LABEL="SYSTEM" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/nvme0n1p4: LABEL="Windows" BLOCK_SIZE="512" UUID="4E98FE2698FE0C69" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="916bd45a-eaf0-4a13-83a6-054828309907"
/dev/nvme0n1p5: LABEL="Dane" BLOCK_SIZE="512" UUID="CC242F3B242F2842" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="97257a5d-c2b0-48c7-a3f3-c1aa0da7076a"
/dev/nvme0n1p6: LABEL="nixos" UUID="a86a408b-2039-4002-bb13-ae15ae3d6d1a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a529a036-1e3c-4f5f-af32-6702890eb8b4"
/dev/nvme0n1p7: LABEL="debian" UUID="381b1f3e-67b9-46af-8ad9-dace488e197b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a141548b-5cb7-43e8-ac0a-08c149f18a10"
/dev/nvme0n1p8: UUID="1563-4529" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/nvme0n1p3: PARTLABEL="Microsoft reserved partition" PARTUUID="5d833726-0e87-430b-b015-dd511b387b19"
$ mkfs.fat -i DCF7-772A -F32 /dev/nvme0n1p8
mkfs.fat 4.1 (2017-01-24)
Volume ID must be a hexadecimal number
$ fatlabel /dev/nvme0n1p2 SYSTEMOLD
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
Automatically removing dirty bit.
$ blkid
/dev/nvme0n1p1: LABEL="Windows RE tools" BLOCK_SIZE="512" UUID="3C7CF7997CF74C60" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="593e6f89-fa68-472f-85d7-b6fe1dbb2e56"
/dev/nvme0n1p2: LABEL_FATBOOT="SYSTEMOLD" LABEL="SYSTEMOLD" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/nvme0n1p4: LABEL="Windows" BLOCK_SIZE="512" UUID="4E98FE2698FE0C69" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="916bd45a-eaf0-4a13-83a6-054828309907"
/dev/nvme0n1p5: LABEL="Dane" BLOCK_SIZE="512" UUID="CC242F3B242F2842" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="97257a5d-c2b0-48c7-a3f3-c1aa0da7076a"
/dev/nvme0n1p6: LABEL="nixos" UUID="a86a408b-2039-4002-bb13-ae15ae3d6d1a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a529a036-1e3c-4f5f-af32-6702890eb8b4"
/dev/nvme0n1p7: LABEL="debian" UUID="381b1f3e-67b9-46af-8ad9-dace488e197b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a141548b-5cb7-43e8-ac0a-08c149f18a10"
/dev/nvme0n1p8: LABEL_FATBOOT="SYSTEM" LABEL="SYSTEM" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/nvme0n1p3: PARTLABEL="Microsoft reserved partition" PARTUUID="5d833726-0e87-430b-b015-dd511b387b19"
$ parted
GNU Parted 3.4
Using /dev/nvme0n1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) name 2 "EFI System Partition OLD"
(parted) quit
$ blkid
/dev/nvme0n1p1: LABEL="Windows RE tools" BLOCK_SIZE="512" UUID="3C7CF7997CF74C60" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="593e6f89-fa68-472f-85d7-b6fe1dbb2e56"
/dev/nvme0n1p2: LABEL_FATBOOT="SYSTEMOLD" LABEL="SYSTEMOLD" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition OLD" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/nvme0n1p4: LABEL="Windows" BLOCK_SIZE="512" UUID="4E98FE2698FE0C69" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="916bd45a-eaf0-4a13-83a6-054828309907"
/dev/nvme0n1p5: LABEL="Dane" BLOCK_SIZE="512" UUID="CC242F3B242F2842" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="97257a5d-c2b0-48c7-a3f3-c1aa0da7076a"
/dev/nvme0n1p6: LABEL="nixos" UUID="a86a408b-2039-4002-bb13-ae15ae3d6d1a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a529a036-1e3c-4f5f-af32-6702890eb8b4"
/dev/nvme0n1p7: LABEL="debian" UUID="381b1f3e-67b9-46af-8ad9-dace488e197b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a141548b-5cb7-43e8-ac0a-08c149f18a10"
/dev/nvme0n1p8: LABEL_FATBOOT="SYSTEM" LABEL="SYSTEM" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/nvme0n1p3: PARTLABEL="Microsoft reserved partition" PARTUUID="5d833726-0e87-430b-b015-dd511b387b19"
$ gdisk /dev/nvme0n1
GPT fdisk (gdisk) version 1.0.7
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): x
Expert command (? for help): c
Partition number (1-8): 2
Enter the partition's new unique GUID ('R' to randomize): R
New GUID is 4F264EA1-25E5-4309-98D9-79FF1DBE046D
Expert command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
$ blkid
/dev/nvme0n1p1: LABEL="Windows RE tools" BLOCK_SIZE="512" UUID="3C7CF7997CF74C60" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="593e6f89-fa68-472f-85d7-b6fe1dbb2e56"
/dev/nvme0n1p2: LABEL_FATBOOT="SYSTEMOLD" LABEL="SYSTEMOLD" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition OLD" PARTUUID="4f264ea1-25e5-4309-98d9-79ff1dbe046d"
/dev/nvme0n1p4: LABEL="Windows" BLOCK_SIZE="512" UUID="4E98FE2698FE0C69" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="916bd45a-eaf0-4a13-83a6-054828309907"
/dev/nvme0n1p5: LABEL="Dane" BLOCK_SIZE="512" UUID="CC242F3B242F2842" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="97257a5d-c2b0-48c7-a3f3-c1aa0da7076a"
/dev/nvme0n1p6: LABEL="nixos" UUID="a86a408b-2039-4002-bb13-ae15ae3d6d1a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a529a036-1e3c-4f5f-af32-6702890eb8b4"
/dev/nvme0n1p7: LABEL="debian" UUID="381b1f3e-67b9-46af-8ad9-dace488e197b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a141548b-5cb7-43e8-ac0a-08c149f18a10"
/dev/nvme0n1p8: LABEL_FATBOOT="SYSTEM" LABEL="SYSTEM" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/nvme0n1p3: PARTLABEL="Microsoft reserved partition" PARTUUID="5d833726-0e87-430b-b015-dd511b387b19"
$ umount /dev/nvme0n1p2
$ mkdosfs -i DCF7772B /dev/nvme0n1p2
mkfs.fat 4.1 (2017-01-24)
$ blkid
/dev/nvme0n1p1: LABEL="Windows RE tools" BLOCK_SIZE="512" UUID="3C7CF7997CF74C60" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="593e6f89-fa68-472f-85d7-b6fe1dbb2e56"
/dev/nvme0n1p2: SEC_TYPE="msdos" UUID="DCF7-772B" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition OLD" PARTUUID="4f264ea1-25e5-4309-98d9-79ff1dbe046d"
/dev/nvme0n1p4: LABEL="Windows" BLOCK_SIZE="512" UUID="4E98FE2698FE0C69" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="916bd45a-eaf0-4a13-83a6-054828309907"
/dev/nvme0n1p5: LABEL="Dane" BLOCK_SIZE="512" UUID="CC242F3B242F2842" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="97257a5d-c2b0-48c7-a3f3-c1aa0da7076a"
/dev/nvme0n1p6: LABEL="nixos" UUID="a86a408b-2039-4002-bb13-ae15ae3d6d1a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a529a036-1e3c-4f5f-af32-6702890eb8b4"
/dev/nvme0n1p7: LABEL="debian" UUID="381b1f3e-67b9-46af-8ad9-dace488e197b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a141548b-5cb7-43e8-ac0a-08c149f18a10"
/dev/nvme0n1p8: LABEL_FATBOOT="SYSTEM" LABEL="SYSTEM" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/nvme0n1p3: PARTLABEL="Microsoft reserved partition" PARTUUID="5d833726-0e87-430b-b015-dd511b387b19"
$ efibootmgr -v
BootCurrent: 0002
Timeout: 2 seconds
BootOrder: 0000,0002,0001
Boot0000* Windows Boot Manager HD(8,GPT,2b95e4aa-736e-45a8-b654-9330261c002f,0x76fd5000,0x3e8000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}....................
Boot0001 UEFI: VerbatimSTORE N GO 8.07 PciRoot(0x0)/Pci(0x14,0x0)/USB(3,0)/CDROM(1,0x307c,0x2c000)..BO
Boot0002* UEFI: VerbatimSTORE N GO 8.07, Partition 2 PciRoot(0x0)/Pci(0x14,0x0)/USB(3,0)/HD(2,MBR,0x9fb6382f,0x307c,0xb000)..BO
$ mount /dev/disk/by-label/nixos /mnt
$ mount /dev/disk/by- /mnt/boot
by-id/ by-label/ by-partlabel/ by-partuuid/ by-path/ by-uuid/
$ mount /dev/disk/by-uuid/DCF7-772A /mnt/boot
$ ls /mnt/boot
Boot bootmgr BOOTNXT EFI loader mach_kernel System 'System Volume Information'
$ vim foo.sh
$ bash foo.sh
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Copied "/nix/store/9sl5iy49gm5wyhn60c1bi7xq2ngxw195-systemd-247.6/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/systemd/systemd-bootx64.efi".
Copied "/nix/store/9sl5iy49gm5wyhn60c1bi7xq2ngxw195-systemd-247.6/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/BOOT/BOOTX64.EFI".
Random seed file /boot/loader/random-seed successfully written (512 bytes).
Created EFI boot entry "Linux Boot Manager".
This is how to name partition using command mode. If you have spaces in name, you need to enclose them with single quote.
Without single quotes, help was printed, and parittion name was changed to first word.
$ parted /dev/nvme0n1 -- name 2 "To delete"
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE. If no COMMAND(s) are given, run in
interactive mode.
...
$ parted -sm /dev/nvme0n1 print
BYT;
/dev/nvme0n1:1024GB:nvme:512:512:gpt:Lexar 1TB SSD:;
1:1049kB:316MB:315MB:ntfs:Basic data partition:msftdata;
2:316MB:420MB:105MB:fat16:To:msftdata;
...
$ parted -s /dev/nvme0n1 -- name 2 "'To delete'"
$ blkid
/dev/nvme0n1p1: LABEL="Windows RE tools" BLOCK_SIZE="512" UUID="3C7CF7997CF74C60" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="593e6f89-fa68-472f-85d7-b6fe1dbb2e56"
/dev/nvme0n1p2: SEC_TYPE="msdos" UUID="DCF7-772B" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="To delete" PARTUUID="4f264ea1-25e5-4309-98d9-79ff1dbe046d"
/dev/nvme0n1p4: LABEL="Windows" BLOCK_SIZE="512" UUID="4E98FE2698FE0C69" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="916bd45a-eaf0-4a13-83a6-054828309907"
/dev/nvme0n1p5: LABEL="Dane" BLOCK_SIZE="512" UUID="CC242F3B242F2842" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="97257a5d-c2b0-48c7-a3f3-c1aa0da7076a"
/dev/nvme0n1p6: LABEL="nixos" UUID="a86a408b-2039-4002-bb13-ae15ae3d6d1a" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a529a036-1e3c-4f5f-af32-6702890eb8b4"
/dev/nvme0n1p7: LABEL="debian" UUID="381b1f3e-67b9-46af-8ad9-dace488e197b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="a141548b-5cb7-43e8-ac0a-08c149f18a10"
/dev/nvme0n1p8: LABEL_FATBOOT="SYSTEM" LABEL="SYSTEM" UUID="DCF7-772A" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="2b95e4aa-736e-45a8-b654-9330261c002f"
/dev/sda1: BLOCK_SIZE="2048" UUID="1980-01-01-00-00-00-00" LABEL="nixos-gnome-21.05-x86_64" TYPE="iso9660" PTUUID="9fb6382f" PTTYPE="dos" PARTUUID="9fb6382f-01"
/dev/sda2: SEC_TYPE="msdos" LABEL_FATBOOT="EFIBOOT" LABEL="EFIBOOT" UUID="1234-5678" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="9fb6382f-02"
/dev/nvme0n1p3: PARTLABEL="Microsoft reserved partition" PARTUUID="5d833726-0e87-430b-b015-dd511b387b19"
$ parted -sm /dev/nvme0n1 print
BYT;
/dev/nvme0n1:1024GB:nvme:512:512:gpt:Lexar 1TB SSD:;
1:1049kB:316MB:315MB:ntfs:Basic data partition:msftdata;
2:316MB:420MB:105MB:fat16:To delete:msftdata;
3:420MB:555MB:134MB::Microsoft reserved partition:msftres;
4:555MB:130GB:130GB:ntfs:Basic data partition:msftdata;
5:130GB:919GB:789GB:ntfs:Basic data partition:msftdata;
6:919GB:998GB:79,0GB:ext4::;
7:998GB:1019GB:20,6GB:ext4::;
8:1022GB:1024GB:2097MB:fat32:EFI System Partition:boot, esp;
That’s a nice observation! I’ve seen similar behavior before, I suspect Windows ran through its bootloader installation because something was a bit off, and proceeded to wipe grub in the process. Re-installing windows will do much the same to a multiboot system.