# Debian Preseed Configuration File
# Automates Debian installation with specific UK/UEFI requirements
### Localization
# Set locale to UK English (corrected from en_UK.UTF-8 to proper en_GB.UTF-8)
d-i debian-installer/locale string en_GB.UTF-8
d-i debian-installer/language string en
d-i debian-installer/country string GB
# Keyboard configuration - UK layout
d-i keyboard-configuration/xkb-keymap select gb
d-i keyboard-configuration/layoutcode string gb
### Network configuration
# Use DHCP for automatic network configuration
d-i netcfg/choose_interface select auto
d-i netcfg/use_dhcp boolean true
# Set hostname
d-i netcfg/get_hostname string debian-13
d-i netcfg/get_domain string
# Disable WEP key dialog
d-i netcfg/wireless_wep string
### Mirror settings
# Use deb.debian.org mirror for UK
d-i mirror/country string manual
d-i mirror/http/hostname string deb.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
### Account setup
# Set root password
d-i passwd/root-login boolean true
d-i passwd/root-password password password
d-i passwd/root-password-again password password
# Create regular user account
d-i passwd/user-fullname string Guest User
d-i passwd/username string guest
d-i passwd/user-password password password
d-i passwd/user-password-again password password
### Clock and time zone setup
d-i clock-setup/utc boolean true
d-i time/zone string Europe/London
d-i clock-setup/ntp boolean true
### Partitioning
d-i partman/early_command string \
echo "=== DEBUG: Detecting mmc target disk ===" > /dev/console; \
found_device=false; \
for dev in $(ls /sys/block/ | grep -E '^mmcblk[0-9]+$'); do \
    size=$(cat /sys/block/$dev/size 2>/dev/null); \
    if [ "$size" -gt 2000000 ] 2>/dev/null; then \
    echo "partman-auto/disk string /dev/$dev" | debconf-set-selections; \
    echo "Selected mmc /dev/$dev with size $size sectors" > /dev/console; \
    dd if=/dev/zero of=/dev/$dev bs=1M count=1
    echo "Clear partition table before partitioning to avoid any prompts"
    found_device=true; \
    break; \
    fi; \
done; \
if [ "$found_device" = false ]; then \
    echo "ERROR: No suitable mmc device found!" > /dev/console; \
    echo "Available block devices:" > /dev/console; \
    ls /sys/block/ > /dev/console; \
    exit 1; \
fi; \
echo "=== DEBUG: dmesg mmc ===" > /dev/console; \
dmesg | grep -i mmc > /dev/console 2>&1; \
echo "Debug output complete" > /dev/console
# Use GPT partition table for UEFI systems
d-i partman-efi/non_efi_system boolean false
d-i partman-auto/method string regular
d-i partman/alignment string cylinder
d-i partman-auto/choose_recipe select boot-swap-root
# Simplified partitioning recipe for GPT with ESP, swap, and root
d-i partman-auto/expert_recipe string                         \
    boot-swap-root ::                                       \
            512 512 512 fat32                              \
                    $primary{ } $bootable{ }              \
                    method{ efi }                          \
                    format{ }                              \
            .                                               \
            1024 1024 1024 linux-swap                      \
                    $primary{ }                            \
                    method{ swap } format{ }               \
            .                                               \
            1000 10000 1000000000 ext4                     \
                    $primary{ }                            \
                    method{ format } format{ }             \
                    use_filesystem{ } filesystem{ ext4 }   \
                    mountpoint{ / }                        \
            .
# Confirm partitioning
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
# Don't use LVM
d-i partman-auto-lvm/guided_size string max
d-i partman-auto-lvm/new_vg_name string main
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/confirm boolean false
# Don't use RAID
d-i partman-md/device_remove_md boolean true
d-i partman-md/confirm boolean false
### Base system installation
d-i base-installer/kernel/override-image string linux-server
### Apt setup
d-i apt-setup/restricted boolean true
d-i apt-setup/universe boolean true
d-i apt-setup/backports boolean true
d-i apt-setup/services-select multiselect security
d-i apt-setup/security_host string security.debian.org
d-i apt-setup/security_path string /debian-security
### Package selection
# Install only standard system utilities (no desktop environment)
tasksel tasksel/first multiselect standard
d-i pkgsel/upgrade select none
# Install additional packages for LAVA testing
d-i pkgsel/include string curl ethtool zip
# Disable popularity contest
popularity-contest popularity-contest/participate boolean false
### Boot loader installation
# Install GRUB to EFI system partition
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean false
d-i grub-installer/bootdev string default
### Finishing up the installation
# Avoid that last message about the install being complete
d-i finish-install/reboot_in_progress note
# Invalidate installation media to prevent re-booting into installer
d-i preseed/late_command string \
echo "Prepare wiping of install media" > /dev/console; \
dev=$(echo /dev/disk/by-label/debian-*); \
if [ -z "$dev" ]; then \
    echo "No installer found" > /dev/console; \
    echo "Available devices under /dev/disk/by-label/:" > /dev/console; \
    ls -la /dev/disk/by-label/ > /dev/console; \
    exit 0; \
fi; \
echo "Found installation media at $dev" > /dev/console; \
echo "Zeroing first megabyte of $dev to invalidate installer" > /dev/console; \
dd if=/dev/zero of="$dev" bs=1M count=128; \
sync; \
echo "Installer wiped. Waiting for Reboot" > /dev/consol
