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,17 +56,32 @@ makeConf() {
EOF
if isEFI; then
if [[ $bootFs == /boot ]]; then
bootcfg=$(cat << EOF
boot.loader.grub = {
efiSupport = true;
efiInstallAsRemovable = true;
device = "nodev";
};
fileSystems."/boot" = { device = "$esp"; fsType = "vfat"; };
fileSystems."$bootFs" = { device = "$esp"; fsType = "vfat"; };
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
bootcfg=$(cat << EOF
boot.loader.grub.device = "$grubdev";
EOF
)
@ -234,6 +249,13 @@ prepareEnv() {
# $esp and $grubdev are used in makeConf()
if isEFI; then
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
for grubdev in /dev/vda /dev/sda /dev/xvda /dev/nvme0n1 ; do [[ -e $grubdev ]] && break; done
fi
@ -370,14 +392,14 @@ infect() {
echo root/.nix-defexpr/channels >> /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"
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
mkdir -p /boot
mount "$esp" /boot
find /boot -depth ! -path /boot -exec rm -rf {} +
mkdir -p $bootFs
mount "$esp" $bootFs
find $bootFs -depth ! -path $bootFs -exec rm -rf {} +
fi
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
}