script rewrite
This commit is contained in:
parent
e5bd5aa61e
commit
3175211f7c
2 changed files with 42 additions and 30 deletions
70
common.nix
70
common.nix
|
|
@ -129,15 +129,15 @@
|
|||
};
|
||||
};
|
||||
virtualisation.oci-containers.containers.fedora-dracut = {
|
||||
pull = "newer";
|
||||
autoStart = false;
|
||||
entrypoint = "bash";
|
||||
autoRemoveOnStop = false;
|
||||
image = "docker.io/fedora:latest";
|
||||
cmd = [ "/data/workdir/entry.sh" ];
|
||||
volumes = [
|
||||
"/var/lib/podman-dracut:/data/workdir"
|
||||
"/srv/nfs/arch/lower:/data/ro-arch:ro"
|
||||
"/srv/nfs/fedora/lower:/data/ro-fedora:ro"
|
||||
"/srv/nfs/arch/lower:/data/arch:ro"
|
||||
"/srv/nfs/fedora/lower:/data/fedora:ro"
|
||||
];
|
||||
};
|
||||
systemd = {
|
||||
|
|
@ -145,32 +145,36 @@
|
|||
services.pxeboot = {
|
||||
serviceConfig.Type = "oneshot";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
path = with pkgs; [ xz grub2_efi util-linux ];
|
||||
path = with pkgs; [ xz e2fsprogs grub2_efi util-linux ];
|
||||
script = let
|
||||
resolv = pkgs.writeText "resolv.conf" ''
|
||||
nameserver fc02::1
|
||||
nameserver 10.2.0.1
|
||||
options edns0 trust-ad
|
||||
'';
|
||||
grubCfg = pkgs.writeText "grub.cfg" ''
|
||||
set timeout=10
|
||||
set path=(http,$net_default_server)/local/boot/pxe
|
||||
set nfs="rw ifname=ens0:$net_default_mac ip=$net_default_ip::$net_default_server:255.255.0.0::ens0:none root=nfs4:$net_default_server:/srv/nfs"
|
||||
. $path/grub.cfg
|
||||
'';
|
||||
entryScript = pkgs.writeText "entry.sh" ''
|
||||
set -e
|
||||
dnf install -y dracut-network nfs-utils
|
||||
cd /data/workdir
|
||||
for target in $(cd ..; ls | grep -v workdir); do
|
||||
modsDir=../$target/usr/lib/modules/*
|
||||
mkdir $target
|
||||
cp $modsDir/vmlinuz $target
|
||||
dracut -Nm "network-manager nfs" --zstd -k $modsDir --kver $(basename $modsDir) $target/initramfs
|
||||
done
|
||||
'';
|
||||
in ''
|
||||
cd /srv/tftp
|
||||
if [ ! -e grubx64.efi ]; then
|
||||
grub-mkstandalone -O x86_64-efi --compress=xz --modules=efinet -o grubx64.efi /boot/grub/grub.cfg=${grubCfg}
|
||||
fi
|
||||
cat > /var/lib/podman-dracut/entry.sh <<'EOF'
|
||||
set -e
|
||||
dnf install -y dracut-network nfs-utils
|
||||
cd /data/workdir
|
||||
target=$(cat target)
|
||||
modsDir=../ro-$target/usr/lib/modules/*
|
||||
mkdir $target
|
||||
cp $modsDir/vmlinuz $target
|
||||
dracut -Nm "network-manager nfs" --zstd -k $modsDir --kver $(basename $modsDir) $target/initramfs
|
||||
EOF
|
||||
for distro in arch:arch/x86_64/airootfs.sfs: fedora:LiveOS/squashfs.img:selinux=0; do
|
||||
cmdline=''${distro##*:}
|
||||
distro=''${distro%:*}
|
||||
for distro in arch:arch/x86_64/airootfs.sfs fedora:LiveOS/squashfs.img; do
|
||||
rootfs=''${distro##*:}
|
||||
distro=''${distro%:*}
|
||||
cd /srv/nfs/$distro
|
||||
|
|
@ -178,23 +182,31 @@
|
|||
mountpoint -q loop || mount $distro.iso loop
|
||||
mountpoint -q lower || mount loop/$rootfs lower
|
||||
mountpoint -q root || mount -t overlay overlay -o lowerdir=lower,upperdir=upper,workdir=work,nfs_export=on root
|
||||
cd /srv/http/local/boot/pxe
|
||||
if [ ! -e $distro ]; then
|
||||
echo $distro > /var/lib/podman-dracut/target
|
||||
systemctl --wait restart podman-fedora-dracut.service
|
||||
mv /var/lib/podman-dracut/$distro .
|
||||
if [ ! -e upper/etc/resolv.conf ]; then
|
||||
cd root/etc
|
||||
rm -f resolv.conf
|
||||
cp ${resolv} resolv.conf
|
||||
chattr +i resolv.conf
|
||||
fi
|
||||
if [ ! -e .grub.cfg.lock ]; then
|
||||
done
|
||||
cd /srv/http/local/boot
|
||||
if [ ! -e pxe ]; then
|
||||
mkdir pxe
|
||||
cp ${entryScript} /var/lib/podman-dracut/entry.sh
|
||||
systemctl --wait start podman-fedora-dracut.service
|
||||
for distro in arch: fedora:selinux=0; do
|
||||
cmdline=''${distro##*:}
|
||||
distro=''${distro%:*}
|
||||
mv /var/lib/podman-dracut/$distro pxe
|
||||
echo "menuentry $distro {
|
||||
linux \$path/$distro/vmlinuz \$nfs/$distro/root $cmdline
|
||||
initrd \$path/$distro/initramfs
|
||||
}" >> grub.cfg
|
||||
fi
|
||||
}" >> pxe/grub.cfg
|
||||
done
|
||||
touch .grub.cfg.lock
|
||||
chmod -R 640 .
|
||||
chgrp -R php .
|
||||
chmod ug+x $(find -type d)
|
||||
chmod -R 640 pxe
|
||||
chgrp -R php pxe
|
||||
chmod ug+x $(find pxe -type d)
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
|
|||
0
ls
Normal file
0
ls
Normal file
Loading…
Add table
Add a link
Reference in a new issue