Utilizing kernal and ram init files

This commit is contained in:
vandomej 2025-09-30 18:07:35 -07:00
parent af28a59ac6
commit 6ad23a615a

View file

@ -7,7 +7,9 @@ CONTROLPLANE_NAME="talos-controlplane"
MEMORY="2048" # 2GB per VM MEMORY="2048" # 2GB per VM
CPUS="2" CPUS="2"
DISK_SIZE="10G" # 10GB disk DISK_SIZE="10G" # 10GB disk
TALOS_ISO_URL="https://github.com/siderolabs/talos/releases/download/v1.11.0/metal-arm64.iso" TALOS_VERSION="v1.11.1"
KERNEL_URL="https://github.com/siderolabs/talos/releases/download/${TALOS_VERSION}/vmlinuz-arm64"
INITRAMFS_URL="https://github.com/siderolabs/talos/releases/download/${TALOS_VERSION}/initramfs-arm64.xz"
# Colors for output # Colors for output
RED='\033[0;31m' RED='\033[0;31m'
@ -36,14 +38,25 @@ create_vm_dir() {
echo "$vm_path" echo "$vm_path"
} }
# Download Talos ISO if not exists # Download Talos kernel and initramfs
download_talos_iso() { download_kernal_file() {
local iso_path="$VM_DIR/talos.iso" local initramfs_path="$VM_DIR/initramfs-arm64.xz"
if [[ ! -f "$iso_path" ]]; then if [[ ! -f "$kernel_path" ]]; then
curl -L -o "$iso_path" "$TALOS_ISO_URL" curl -L -o "$kernel_path" "$KERNEL_URL"
fi fi
echo "$iso_path"
echo "$kernel_path"
}
download_initramfs_file() {
local initramfs_path="$VM_DIR/initramfs-arm64.xz"
if [[ ! -f "$initramfs_path" ]]; then
curl -L -o "$initramfs_path" "$INITRAMFS_URL"
fi
echo "$initramfs_path"
} }
# Create disk image # Create disk image
@ -70,16 +83,15 @@ create_vm_script() {
local vm_path=$1 local vm_path=$1
local vm_name=$2 local vm_name=$2
local mac_address=$3 local mac_address=$3
local iso_path=$4 local kernel_path=$4
local disk_path=$5 local initramfs_path=$5
local disk_path=$6
local script_path="$vm_path/start.sh" local script_path="$vm_path/start.sh"
# Use a function to escape the variables
cat > "$script_path" << EOF cat > "$script_path" << EOF
#!/bin/bash #!/bin/bash
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES \\ OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES qemu-system-aarch64 \\
qemu-system-aarch64 \\
-name "$vm_name" \\ -name "$vm_name" \\
-machine virt,highmem=off \\ -machine virt,highmem=off \\
-accel hvf \\ -accel hvf \\
@ -87,9 +99,13 @@ qemu-system-aarch64 \\
-smp "$CPUS" \\ -smp "$CPUS" \\
-m "${MEMORY}M" \\ -m "${MEMORY}M" \\
-drive file="$disk_path",if=virtio,format=qcow2 \\ -drive file="$disk_path",if=virtio,format=qcow2 \\
-cdrom "$iso_path" \\ -kernel "$kernel_path" \\
-initrd "$initramfs_path" \\
-append "talos.platform=metal console=tty0 console=ttyS0" \\
-netdev user,id=net0 \\ -netdev user,id=net0 \\
-device virtio-net-pci,netdev=net0,mac=$mac_address \\ -device virtio-net-pci,netdev=net0,mac=$mac_address \\
-nographic \\
-serial mon:stdio \\
-daemonize -daemonize
EOF EOF
@ -133,13 +149,13 @@ main() {
exit 1 exit 1
fi fi
local iso_path=$(download_talos_iso)
log_info "Creating controlplane VM..." log_info "Creating controlplane VM..."
local controlplane_path=$(create_vm_dir "$CONTROLPLANE_NAME") local controlplane_path=$(create_vm_dir "$CONTROLPLANE_NAME")
local controlplane_disk=$(create_disk_image "$controlplane_path" "$CONTROLPLANE_NAME") local controlplane_disk=$(create_disk_image "$controlplane_path" "$CONTROLPLANE_NAME")
local controlplane_mac=$(generate_mac "$CONTROLPLANE_NAME") local controlplane_mac=$(generate_mac "$CONTROLPLANE_NAME")
local controlplane_script=$(create_vm_script "$controlplane_path" "$CONTROLPLANE_NAME" "$controlplane_mac" "$iso_path" "$controlplane_disk") local kernal_path=$(download_kernal_file)
local initramfs_path=$(download_initramfs_file)
local controlplane_script=$(create_vm_script "$controlplane_path" "$CONTROLPLANE_NAME" "$controlplane_mac" "$kernel_path" "$initramfs_path" "$controlplane_disk")
create_service_file "$controlplane_path" "$CONTROLPLANE_NAME" "$controlplane_script" create_service_file "$controlplane_path" "$CONTROLPLANE_NAME" "$controlplane_script"
local manage_script="$VM_DIR/manage-vm.sh" local manage_script="$VM_DIR/manage-vm.sh"