Skip to content

Instantly share code, notes, and snippets.

@eldondev
Last active December 4, 2023 16:33
Show Gist options
  • Save eldondev/33366c2842df9d1b4a0e to your computer and use it in GitHub Desktop.
Save eldondev/33366c2842df9d1b4a0e to your computer and use it in GitHub Desktop.
Because everyone needs a good preseed
wget -nc http://ftp.debian.org/debian/dists/jessie/main/installer-amd64/current/images/netboot/debian-installer/amd64/linux
wget -nc http://ftp.debian.org/debian/dists/jessie/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz
cp -nv ~/.ssh/id_rsa.pub .
qemu-system-x86_64 -machine accel=kvm -kernel linux -initrd initrd.gz -m 1G -smp 2 -append "blacklist=vga16fb fb=false video=false vga=normal auto=true url=http://10.0.2.10:8080/debian-preseed.txt hostname=otto domain=" -net user,guestfwd=:10.0.2.10:8080-cmd:"/bin/busybox httpd -i" -hda /dev/shm/deb.img -net nic -display none
wget -nc https://d-i.debian.org/daily-images/amd64/daily/netboot/debian-installer/amd64/linux
wget -nc https://d-i.debian.org/daily-images/amd64/daily/netboot/debian-installer/amd64/initrd.gz
cp -nv ~/.ssh/id_rsa.pub .
time qemu-system-x86_64 -machine accel=kvm -kernel linux -initrd initrd.gz -m 1G -smp 2 -append "blacklist=mac80211 fb=false video=false vga=normal auto=true url=http://10.0.2.10:8080/debian-preseed.txt hostname=otto domain=" -net user,guestfwd=:10.0.2.10:8080-cmd:"/bin/busybox httpd -i" -hda /dev/shm/deb.img -net nic -display curses
# Derived from https://www.debian.org/releases/stable/example-preseed.txt
d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/hostname string hostname
d-i netcfg/wireless_wep string
d-i mirror/country string manual
d-i mirror/http/hostname string http.us.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string http://172.19.1.1:3142
d-i passwd/root-login boolean true
d-i passwd/root-password-crypted password !00000000000000000000000000000000
d-i passwd/make-user false
d-i clock-setup/utc boolean true
d-i time/zone string US/Eastern
d-i clock-setup/ntp boolean true
d-i partman-auto/method string regular
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/expert_recipe string \
root :: \
40 300 100000000 btrfs \
$primary{ } \
$bootable{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ btrfs } \
mountpoint{ / } \
. \
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman-basicfilesystems/no_swap boolean false
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-md/confirm boolean true
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
tasksel tasksel/first multiselect
d-i pkgsel/include string wget openssh-server vim build-essential git net-tools curl strace htop lsof rsync wget
d-i preseed/late_command string \
in-target sh -c "mkdir -m 700 /root/.ssh ; wget --no-proxy -O /root/.ssh/authorized_keys 10.0.2.10:8080/id_rsa.pub ; wget --no-proxy -O /etc/sysctl.d/local.conf 10.0.2.10:8080/local.conf; chmod 600 /root/.ssh/authorized_keys; echo GRUB_TERMINAL=console >>/etc/default/grub; update-grub"
popularity-contest popularity-contest/participate boolean false
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string default
d-i finish-install/reboot_in_progress note
d-i debian-installer/exit/poweroff boolean true
qemu-system-x86_64 -machine accel=kvm -m 1G -smp 2 -hda /dev/shm/deb.img -net user,hostfwd=::2200-:22 -display none -net nic -monitor stdio
time qemu-system-x86_64 -machine accel=kvm -m 4G -smp 2 -kernel ubuntu/linux -initrd ubuntu/initrd.gz -net nic -net user,tftp=. -hda /dev/shm/preseed-min.img -append "blacklist=vga16fb fb=false video=false vga=normal auto=true priority=high locale=en_US.UTF-8 kdb-chooser/method=us netcfg/choose_interface=auto hostname=otto domain= url=tftp://10.0.2.2/preseed.cfg" -curses
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.ens3.disable_ipv6 = 1
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string otto
d-i netcfg/get_domain string example.pvt
d-i netcfg/wireless_wep string
d-i mirror/country string manual
d-i mirror/http/hostname string archive.ubuntu.com
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy string http://10.0.2.2:3142/
d-i clock-setup/utc boolean true
d-i time/zone string US/Eastern
d-i clock-setup/ntp boolean true
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-lvm/device_remove_lvm_span boolean true
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-auto-lvm/new_vg_name string system
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-auto-lvm/guided_size string max
d-i partman-lvm/confirm boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman-auto/expert_recipe string \
boot-root :: \
40 300 300 ext4 \
$primary{ } \
$bootable{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ /boot } \
. \
2000 10000 10000 ext4 \
$lvmok{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ / } \
.\
2000 10000 100000000 ext4 \
$lvmok{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ /srv } \
. \
d-i partman-lvm/confirm boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm boolean true
d-i partman-basicfilesystems/no_swap boolean false
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password password r00tme
d-i passwd/root-password-again password r00tme
d-i user-setup/allow-password-weak boolean true
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i pkgsel/update-policy select none
tasksel tasksel/first multiselect openssh-server
d-i preseed/late_command string \
in-target sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config ; \
in-target sh -c "echo GRUB_TERMINAL=console | tee -a /etc/default/grub" ; \
in-target sh -c "grub-install /dev/sda && grub-mkconfig >/boot/grub/grub.cfg"
d-i finish-install/reboot_in_progress note
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string ubuntu
d-i netcfg/get_domain string example.com
d-i netcfg/wireless_wep string
d-i mirror/country string manual
d-i mirror/http/hostname string archive.ubuntu.com
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy string http://172.19.1.1:3142/
d-i clock-setup/utc boolean true
d-i time/zone string US/Eastern
d-i clock-setup/ntp boolean true
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm boolean true
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password password r00tme
d-i passwd/root-password-again password r00tme
d-i user-setup/allow-password-weak boolean true
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i pkgsel/update-policy select none
tasksel tasksel/first multiselect openssh-server
d-i preseed/late_command string \
in-target sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
d-i finish-install/reboot_in_progress note
d-i debian-installer/exit/poweroff boolean true
# qemu config file
[drive]
media = "disk"
index = "0"
file = "news.img"
[chardev "compat_monitor1"]
backend = "stdio"
[net]
type = "user"
hostfwd = "::2200-:22"
[net]
type = "nic"
[mon "compat_monitor2"]
mode = "readline"
chardev = "compat_monitor1"
pretty = "off"
[machine]
accel = "kvm"
[memory]
size = "1G"
[smp-opts]
cpus = "2"
qemu-system-x86_64 -machine accel=kvm -m 4G -smp 2 -redir :8024::22 -hda /mnt/out/preseed.img -curses
@eldondev
Copy link
Author

@Nemame make sure you are using in-target in the prefix as above, to run scripts on the root filesystem of the machine being installed. Putting the shell scripts in the preseed file is frustrating. Consider downloading the script via a wget -O or curl | sh in a way similar to the installation of the id_rsa in the above examples. These days I would actually consider using something like https://github.com/coreos/ignition for early provisioning. If you want to post your preseed, happy to take a look at it.

@eldondev
Copy link
Author

You can also check /var/log/installer/syslog for debugging purposes after install has completed.

Copy link

ghost commented Dec 25, 2020

Thank you so much, I have been trying to login as root all day after a preseeded install, your preseed finally helped me figure it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment