├── .gitignore ├── README.md ├── create-iso.sh ├── preseed-template.cfg └── txt.cfg /.gitignore: -------------------------------------------------------------------------------- 1 | *.iso 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Motivation 2 | 3 | I wanted to be able to quickly launch new Virtual Machines in my hypervisor (Proxmox) with minimal interaction. For scenarios where a KVM is preferred over a LXC. 4 | 5 | # Purpose 6 | 7 | This script will generate a debian 9 iso with a preseed configuration which provides an semi-automated installation of the standard Debian packages. It is a semi-automatic installation because it will prompt for the machine's hostname. 8 | 9 | * Generates a random password for the root user. 10 | * Install only the standard debian packages, `sudo`, `apt-transport-https`, and `aptitude`. 11 | * Create an Admin user with specified password. 12 | * Populate the Admin user's `.ssh/authorized_keys` file with the specified public key. 13 | * Set the timezone to your timezone. 14 | * Set the domain name to desired value or localhost. 15 | 16 | # Requirements 17 | 18 | You must have already downloaded a Debian 9 iso and mounted it somewhere on your computer. 19 | 20 | ``` 21 | curl -L -O https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-9.4.0-amd64-netinst.iso 22 | mkdir /tmp/debian-9-iso 23 | sudo mount -o loop debian-9.4.0-amd64-netinst.iso /tmp/debian-9-iso 24 | ``` 25 | 26 | # Usage 27 | 28 | Run the `create-iso.sh` script from anywhere: `/path/to/repository/create-iso.sh` and input the information as you are prompted. 29 | 30 | The generated iso will be created in the current working directory. 31 | 32 | When the Grub loader for the iso opens, select `Automatic Install`. After a short period of time, you will be prompted to input the hostname. The installation will automatically run to completion after that point. 33 | -------------------------------------------------------------------------------- /create-iso.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -l 2 | set -e 3 | 4 | function cleanup { 5 | chmod -R 777 "$TEMP_DIR" 6 | rm -rf "$TEMP_DIR" 7 | } 8 | 9 | TIMEZONE=$(sed -e 's/[\/&]/\\&/g' /etc/timezone) 10 | SCRIPT=`realpath $0` 11 | SCRIPTPATH=`dirname $SCRIPT` 12 | TEMP_DIR=$(mktemp -d) 13 | trap cleanup EXIT 14 | 15 | echo "Using temp directory: $TEMP_DIR" 16 | echo "" 17 | 18 | read -ep "Path to mounted iso: " ISO_PATH 19 | if [ ! -d "$ISO_PATH" ]; then 20 | echo "Unable to find $ISO_PATH" 21 | exit 1 22 | fi 23 | 24 | read -p "Admin username: " USERNAME 25 | read -sp "Admin password: " PASSWORD 26 | echo "" 27 | read -sp "Admin password (again): " PASSWORD_AGAIN 28 | echo "" 29 | if [ ! "$PASSWORD" == "$PASSWORD_AGAIN" ]; then 30 | echo "Passwords do not match" 31 | exit 1 32 | fi 33 | read -ep "Admin authorized ssh pub key path: " PUBKEY_PATH 34 | PUBKEY_PATH="${PUBKEY_PATH/#\~/$HOME}" 35 | 36 | if [ ! -f "$PUBKEY_PATH" ]; then 37 | echo "Unable to find $PUBKEY_PATH" 38 | exit 1 39 | fi 40 | read -p "Domain name (default to localhost if blank: " DOMAIN_NAME 41 | if [ "$DOMAIN_NAME" == "" ]; then 42 | DOMAIN_NAME=localhost 43 | fi 44 | 45 | echo "Copying files from iso" 46 | cp -rT "$ISO_PATH" "$TEMP_DIR" 47 | chmod -R u+w "$TEMP_DIR" 48 | 49 | PUBKEY=$(sed -e 's/[\/&]/\\&/g' "$PUBKEY_PATH") 50 | CPASS=$(mkpasswd -m sha-512 -S "$(pwgen -ns 16 1)" "$PASSWORD" | sed -e 's/[\/&]/\\&/g') 51 | 52 | PRESEED_DEST="$TEMP_DIR/preseed.cfg" 53 | cp "$SCRIPTPATH/preseed-template.cfg" "$PRESEED_DEST" 54 | cp "$SCRIPTPATH/txt.cfg" "$TEMP_DIR/isolinux/" 55 | 56 | sed -i "s/USERNAME/${USERNAME}/g" "$PRESEED_DEST" 57 | sed -i "s/CRYPTED_PASSWORD/${CPASS}/g" "$PRESEED_DEST" 58 | sed -i "s/SSH_PUB_KEY/${PUBKEY}/g" "$PRESEED_DEST" 59 | sed -i "s/TIMEZONE/${TIMEZONE}/g" "$PRESEED_DEST" 60 | sed -i "s/DOMAIN_NAME/${DOMAIN_NAME}/g" "$PRESEED_DEST" 61 | 62 | ISO_DEST="debian-9.x.x-amd64-$USERNAME.iso" 63 | echo "Writing updated ISO to $ISO_DEST" 64 | genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o "$ISO_DEST" "$TEMP_DIR" > /dev/null 65 | -------------------------------------------------------------------------------- /preseed-template.cfg: -------------------------------------------------------------------------------- 1 | d-i debian-installer/locale string en_US 2 | d-i keyboard-configuration/xkb-keymap select us 3 | 4 | d-i netcfg/choose_interface select auto 5 | d-i netcfg/get_domain string DOMAIN_NAME 6 | 7 | d-i mirror/country string manual 8 | d-i mirror/http/hostname string deb.debian.org 9 | d-i mirror/http/directory string /debian 10 | d-i mirror/http/proxy string 11 | 12 | d-i passwd/root-password password ! 13 | d-i passwd/root-password-again password ! 14 | 15 | d-i passwd/user-fullname string Admin User 16 | d-i passwd/username string USERNAME 17 | d-i passwd/user-password-crypted password CRYPTED_PASSWORD 18 | d-i passwd/user-uid string 1000 19 | 20 | d-i clock-setup/utc boolean true 21 | d-i time/zone string TIMEZONE 22 | d-i clock-setup/ntp boolean true 23 | 24 | d-i partman-auto/disk string /dev/sda 25 | d-i partman-auto/method string regular 26 | d-i partman-lvm/device_remove_lvm boolean true 27 | d-i partman-md/device_remove_md boolean true 28 | d-i partman-lvm/confirm boolean true 29 | d-i partman-lvm/confirm_nooverwrite boolean true 30 | d-i partman-basicfilesystems/no_swap boolean false 31 | d-i partman-auto/choose_recipe select atomic 32 | d-i partman-partitioning/confirm_write_new_label boolean true 33 | d-i partman/choose_partition select finish 34 | d-i partman/confirm boolean true 35 | d-i partman/confirm_nooverwrite boolean true 36 | d-i partman-md/confirm boolean true 37 | d-i partman/choose_partition select finish 38 | d-i partman/confirm boolean true 39 | d-i partman/confirm_nooverwrite boolean true 40 | 41 | ### Base system installation 42 | # Configure APT to not install recommended packages by default. Use of this 43 | # option can result in an incomplete system and should only be used by very 44 | # experienced users. 45 | #d-i base-installer/install-recommends boolean false 46 | 47 | d-i apt-setup/non-free boolean true 48 | d-i apt-setup/contrib boolean true 49 | d-i apt-setup/services-select multiselect security, updates 50 | d-i apt-setup/security_host string security.debian.org 51 | apt-mirror-setup apt-setup/use_mirror boolean true 52 | 53 | # Additional repositories, local[0-9] available 54 | #d-i apt-setup/local0/repository string \ 55 | # http://local.server/debian stable main 56 | #d-i apt-setup/local0/comment string local server 57 | # Enable deb-src lines 58 | #d-i apt-setup/local0/source boolean true 59 | # URL to the public key of the local repository; you must provide a key or 60 | # apt will complain about the unauthenticated repository and so the 61 | # sources.list line will be left commented out 62 | #d-i apt-setup/local0/key string http://local.server/key 63 | 64 | ### Package selection 65 | tasksel tasksel/first multiselect standard, ssh-server 66 | d-i pkgsel/include string sudo apt-transport-https aptitude 67 | d-i pkgsel/upgrade select none 68 | popularity-contest popularity-contest/participate boolean false 69 | 70 | ### Boot loader installation 71 | # Grub is the default boot loader (for x86). If you want lilo installed 72 | # instead, uncomment this: 73 | #d-i grub-installer/skip boolean true 74 | # To also skip installing lilo, and install no bootloader, uncomment this 75 | # too: 76 | #d-i lilo-installer/skip boolean true 77 | 78 | 79 | d-i grub-installer/only_debian boolean true 80 | d-i grub-installer/with_other_os boolean true 81 | d-i grub-installer/bootdev string /dev/sda 82 | 83 | d-i preseed/late_command string \ 84 | echo 'USERNAME ALL=(ALL) ALL' > /target/etc/sudoers.d/USERNAME ; \ 85 | in-target chmod 440 /etc/sudoers.d/USERNAME ; \ 86 | in-target mkdir /home/USERNAME/.ssh; \ 87 | echo 'SSH_PUB_KEY' > /target/home/USERNAME/.ssh/authorized_keys ; \ 88 | in-target chown -R USERNAME.USERNAME /home/USERNAME/.ssh; \ 89 | in-target chmod 700 /home/USERNAME/.ssh; \ 90 | sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list ; 91 | 92 | apt-cdrom-setup apt-setup/cdrom/set-first boolean false 93 | 94 | d-i finish-install/reboot_in_progress note 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /txt.cfg: -------------------------------------------------------------------------------- 1 | label autoinstall 2 | menu label ^Automatic Install 3 | kernel /install.amd/vmlinuz 4 | append vga=788 initrd=/install.amd/initrd.gz --- quiet priority=high locale=en_US.UTF-8 keymap=us file=/cdrom/preseed.cfg 5 | label install 6 | menu label ^Install 7 | kernel /install.amd/vmlinuz 8 | append vga=788 initrd=/install.amd/initrd.gz --- quiet 9 | --------------------------------------------------------------------------------