#cloud-config hostname: null fqdn: null manage_etc_hosts: true bootcmd: - | # Detect the primary network interface primary_interface=$(ip -o link show | awk '$2 !~ "lo:" {print substr($2, 1, length($2)-1); exit}') # Write the network configuration cat < /etc/sysconfig/network-scripts/ifcfg-$primary_interface DEVICE=$primary_interface BOOTPROTO=dhcp ONBOOT=yes EOF # Restart network if systemctl is-active --quiet NetworkManager; then nmcli connection reload nmcli device disconnect $primary_interface nmcli device connect $primary_interface else systemctl restart network fi runcmd: - | #!/bin/bash echo "Backup Assure is building. Please wait for 'Backup Assure is ready'." | tee /dev/console # Find unpartitioned disks >= 40 GiB, excluding temporary disk unpartitioned_disks=() min_size=$((40*1024*1024*1024)) # 40 GiB in bytes for lun in 0 1; do if [ -b /dev/disk/azure/scsi1/lun$lun ]; then disk=$(readlink -f /dev/disk/azure/scsi1/lun$lun) if ! lsblk -no PARTTYPE "$disk" | grep -q .; then if ! readlink -f /dev/disk/azure/resource | grep -q "$disk"; then size_bytes=$(lsblk -bdno SIZE "$disk") if [ "$size_bytes" -ge "$min_size" ]; then unpartitioned_disks+=("$disk") fi fi fi fi done num_disks=${#unpartitioned_disks[@]} if [ "$num_disks" -eq 1 ]; then echo "One unpartitioned disk (>=40 GiB) found. Mounting to /backups" disk=${unpartitioned_disks[0]} for i in {1..5}; do if parted "$disk" --script mklabel gpt; then break; fi sleep 2 done || { echo "Failed to partition $disk" | tee /dev/console; exit 1; } parted "$disk" --script mkpart primary ext4 0% 100% || { echo "Failed to create partition" | tee /dev/console; exit 1; } mkfs.ext4 "${disk}1" || { echo "Failed to format ${disk}1" | tee /dev/console; exit 1; } UUID=$(blkid -s UUID -o value "${disk}1") mkdir -p /backups mount -U "$UUID" /backups || { echo "Failed to mount ${disk}1" | tee /dev/console; exit 1; } echo "UUID=$UUID /backups ext4 defaults,nofail 0 0" >> /etc/fstab mkdir -p /backups/nfs /backups/rsync elif [ "$num_disks" -eq 2 ]; then echo "Two unpartitioned disks (>=40 GiB) found. Mounting to /backups/nfs and /backups/rsync" disk_nfs=${unpartitioned_disks[0]} disk_rsync=${unpartitioned_disks[1]} for disk in "$disk_nfs" "$disk_rsync"; do for i in {1..5}; do if parted "$disk" --script mklabel gpt; then break; fi sleep 2 done || { echo "Failed to partition $disk" | tee /dev/console; exit 1; } parted "$disk" --script mkpart primary ext4 0% 100% || { echo "Failed to create partition" | tee /dev/console; exit 1; } mkfs.ext4 "${disk}1" || { echo "Failed to format ${disk}1" | tee /dev/console; exit 1; } done UUID_nfs=$(blkid -s UUID -o value "${disk_nfs}1") mkdir -p /backups/nfs mount -U "$UUID_nfs" /backups/nfs || { echo "Failed to mount ${disk_nfs}1" | tee /dev/console; exit 1; } echo "UUID=$UUID_nfs /backups/nfs ext4 defaults,nofail 0 0" >> /etc/fstab UUID_rsync=$(blkid -s UUID -o value "${disk_rsync}1") mkdir -p /backups/rsync mount -U "$UUID_rsync" /backups/rsync || { echo "Failed to mount ${disk_rsync}1" | tee /dev/console; exit 1; } echo "UUID=$UUID_rsync /backups/rsync ext4 defaults,nofail 0 0" >> /etc/fstab else echo "No unpartitioned disks >=40 GiB or unexpected number ($num_disks). No action taken." | tee /dev/console fi clear echo "Backup Assure is ready." | tee /dev/console