Add support for VMs that use efi sysmount

This commit is contained in:
Sandro Jäckel 2024-06-17 14:30:34 +02:00
parent 5dbf3d676f
commit 1261e34cd9
No known key found for this signature in database
GPG key ID: 3AF5A43A3EECC2E5

View file

@ -56,15 +56,30 @@ makeConf() {
EOF EOF
if isEFI; then if isEFI; then
bootcfg=$(cat << EOF if [[ $bootFs == /boot ]]; then
bootcfg=$(cat << EOF
boot.loader.grub = { boot.loader.grub = {
efiSupport = true; efiSupport = true;
efiInstallAsRemovable = true; efiInstallAsRemovable = true;
device = "nodev"; device = "nodev";
}; };
fileSystems."/boot" = { device = "$esp"; fsType = "vfat"; }; fileSystems."$bootFs" = { device = "$esp"; fsType = "vfat"; };
EOF EOF
) )
else
bootcfg=$(cat << EOF
boot.loader = {
efi.efiSysMountPoint = "/boot/efi";
grub = {
efiSupport = true;
efiInstallAsRemovable = true;
device = "nodev";
};
};
fileSystems."$bootFs" = { device = "$esp"; fsType = "vfat"; };
EOF
)
fi
else else
bootcfg=$(cat << EOF bootcfg=$(cat << EOF
boot.loader.grub.device = "$grubdev"; boot.loader.grub.device = "$grubdev";
@ -234,6 +249,13 @@ prepareEnv() {
# $esp and $grubdev are used in makeConf() # $esp and $grubdev are used in makeConf()
if isEFI; then if isEFI; then
esp="$(findESP)" esp="$(findESP)"
if mount | grep -q /boot/efi; then
bootFs=/boot/efi
elif mount | grep -q /boot/EFI; then
bootFs=/boot/EFI
else
bootFs=/boot
fi
else else
for grubdev in /dev/vda /dev/sda /dev/xvda /dev/nvme0n1 ; do [[ -e $grubdev ]] && break; done for grubdev in /dev/vda /dev/sda /dev/xvda /dev/nvme0n1 ; do [[ -e $grubdev ]] && break; done
fi fi
@ -370,14 +392,14 @@ infect() {
echo root/.nix-defexpr/channels >> /etc/NIXOS_LUSTRATE echo root/.nix-defexpr/channels >> /etc/NIXOS_LUSTRATE
(cd / && ls etc/ssh/ssh_host_*_key* || true) >> /etc/NIXOS_LUSTRATE (cd / && ls etc/ssh/ssh_host_*_key* || true) >> /etc/NIXOS_LUSTRATE
rm -rf /boot.bak rm -rf $bootFs.bak
isEFI && umount "$esp" isEFI && umount "$esp"
mv -v /boot /boot.bak || { cp -a /boot /boot.bak ; rm -rf /boot/* ; umount /boot ; } mv -v $bootFs $bootFs.bak || { cp -a $bootFs $bootFs.bak ; rm -rf $bootFs/* ; umount $bootFs ; }
if isEFI; then if isEFI; then
mkdir -p /boot mkdir -p $bootFs
mount "$esp" /boot mount "$esp" $bootFs
find /boot -depth ! -path /boot -exec rm -rf {} + find $bootFs -depth ! -path $bootFs -exec rm -rf {} +
fi fi
/nix/var/nix/profiles/system/bin/switch-to-configuration boot /nix/var/nix/profiles/system/bin/switch-to-configuration boot
} }