User Tools

Site Tools


computing:preseed

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
computing:preseed [2024/02/17 17:42] – created oemb1905computing:preseed [2024/02/17 18:01] (current) oemb1905
Line 1: Line 1:
-I created my own virtualization stack which is complete with version control, file backups, full image backups and more. Additionally, because my client base and use-case does not require that I spin up VMs too often, it was very easy to just keep a few VMs pre-configured generically and then virt-clone them upon need and then tweak a few settings. However, my use-cases and needs are expanding and so I wanted to be able to spin up a new VM with a shell script and have a super minimal and clean copy of Debian installed on it, with absolutely no network configuration, extra packages, etc. So, I decided to dig deeper into both qemu and libvirt to see if there was something that could be developed. After working on qemu options for a bit, I decided that libvirt fit my needs better. After studying forums, I saw that Debian had an "auto-installer" feature and that you could pass configs to it through virsh by adding a few xml lines. After a little trial and error with using a remote site for the config vslocalhost, I developed the following recipe:+------------------------------------------- 
 +  * **preseed**  
 +  * **Jonathan Haack** 
 +  * **Haack's Networking** 
 +  * **webmaster@haacksnetworking.org** 
  
-virt-install --name=domain.org.qcow2 \ +-------------------------------------------
---os-variant=debian11 \ +
---vcpu=2 \ +
---ram=4096 \ +
---disk path=/mnt/vms/production/domain.org.qcow2 \ +
---check path_in_use=off \ +
---graphics spice \ +
---location=/mnt/vms/isos/debian-12.4.0-amd64-netinst.iso \ +
---network bridge:br0 \ +
---initrd-inject /mnt/vms/cfgs/preseed.cfg+
  
-Other resources online insisted that I needed to add something like --extra-args="ks=file:/mnt/vms/cfgs/preseed.cfg console=tty0 console=ttyS0,115200" to the recipe as well, but I found that was unnecessary through trial and error. I think that syntax is required for those desiring kickstarter and/or if they are not using standard X passthrough for the shell. I'm not sure though. After I got the installer to recognize configuration file, I then began making a list as to which options worked automatically and which did not. One by one, I checked the stock configuration file here and adjusted my config until everything worked. Below, I've linked the stock configuration file I used as a jumping off point, and the one I developed for my use-case.+//preseed//      
  
-Stock Configuration+-------------------------------------------
  
-My Use-Case+I created my own [[https://wiki.haacksnetworking.org/doku.php?id=computing:vmserver|virtualization stack]] about two and a half years ago. As I expanded and needed to spin up VMs, my first strategy was to create model VMs that fit particular use cases and then ''virt-clone'' those and then adapt to the new use case. Over time, this became cumbersome, and I started having use-cases that did not fit the templates. For this reason, it came to time to automate fresh Debian installs on new VMs. After studying forums, I saw that Debian had an "auto-installer" feature and that you could pass configs to it through virsh by adding a few xml lines. After a little trial and error with using a remote site for the config vs. localhost, I learned that you could pass the preseed config file to virsh with the last line in this block:
  
-After getting the virt-install recipe and config to perform the desired Debian install, my next task was to automate all of this with a simple script that would create a virtual hard disk of any desired size and a libvirt entry with my desired naming convention in my production VM directoryHere's what I came up with:+  virt-install --name=domain.org.qcow2 \ 
 +   --os-variant=debian11 \ 
 +   --vcpu=2 \ 
 +   --ram=4096 \ 
 +   --disk path=/mnt/vms/production/domain.org.qcow2 \ 
 +   --check path_in_use=off \ 
 +   --graphics spice \ 
 +   --location=/mnt/vms/isos/debian-12.4.0-amd64-netinst.iso \ 
 +   --network bridge:br0 \ 
 +   --initrd-inject /mnt/vms/cfgs/preseed.cfg
  
-echo -n "Please enter the fully qualified hostname:" +Other resources online insisted that I needed to add something like --extra-args="ks=file:/mnt/vms/cfgs/preseed.cfg console=tty0 console=ttyS0,115200" to the recipe as well, but I found that that was only required for those desiring kickstarter and/or if they are using a remote site to host the configs from. My next task was to check the stock configuration file and create my own preseed config that would create machines as I desired. Here's the stock Debian config and the one I developed:
-read hostname +
-echo -n "How large (in GB) would you like the virtual hard disk to be?" +
-read size +
-qemu-img create -f qcow2 /mnt/vms/production/${hostname}.qcow2 ${size}G +
-sleep 2s+
  
-echo "Okay, I am now creating the preseed.cfg file for your host …" +  * [[https://www.debian.org/releases/stable/example-preseed.txt|Stock Configuration]] 
-mkdir /mnt/vms/cfgs/${hostname} +  * [[https://repo.haacksnetworking.org/haacknet/haackingclub/-/blob/main/scripts/preseeds/external/preseed.cfg?ref_type=heads|My Use-Case]]
-cp -ar /mnt/vms/cfgs/preseed.cfg /mnt/vms/cfgs/${hostname}/preseed.cfg +
-rpl -w "unassigned-hostname" "$hostname" /mnt/vms/cfgs/${hostname}/preseed.cfg +
-rpl -w "unassigned-domain" "$hostname" /mnt/vms/cfgs/${hostname}/preseed.cfg +
-sleep 2s +
-echo "Alright, I am opening up virt-installer and building your host …"+
  
-virt-install --name=${hostname}.qcow2 \ +My next task was to automate all of this with a simple shell scriptHere's what I came up with:
---os-variant=debian11 \ +
---vcpu=2 \ +
---ram=4096 \ +
---disk path=/mnt/pathtovms/${hostname}.qcow2 \ +
---check path_in_use=off \ +
---graphics spice \ +
---location=/mnt/vms/isos/debian-12.4.0-amd64-netinst.iso \ +
---network bridge:br0 \ +
---initrd-inject /mnt/pathtovms/${hostname}/preseed.cfg+
  
-For now, I just need really simple Debian VMs as quickly as possible. However, as I wrote this, I began to realize that I could easily expand this script to meet the needs of a variety of different use cases, could add conditionals to it, validation and more. Down the road, I plan to do that, and you can stay up to date with how expand this script's functionality on the repositoryWell, after all that, I deleted everything and ran the script fresh from top to bottom and tested that everything workedNo more waiting for the jenky X passthrough feedback or putting in details that never/rarely changeIt's all hot and ready!+  #!/bin/bash 
 +  echo -n "Please enter the fully qualified hostname: " 
 +  read hostname 
 +  echo -n "How large (in GB) would you like the virtual hard disk to be? " 
 +  read size 
 +  qemu-img create -f qcow2 /mnt/vms/production/${hostname}.qcow2 ${size}G 
 +  sleep 2s 
 +  echo -n "What do you want the last octet of the IP address for this host to be? " 
 +  read ip 
 +  sleep 2s 
 +  echo "Okay, am now creating the preseed.cfg file for your host ..." 
 +  mkdir /mnt/vms/cfgs/external/${hostname} 
 +  cp -ar /mnt/vms/cfgs/external/preseed.cfg /mnt/vms/cfgs/external/${hostname}/preseed.cfg 
 +  rpl -w "unassigned-hostname" "$hostname" /mnt/vms/cfgs/external/${hostname}/preseed.cfg 
 +  rpl -w "unassigned-domain" "$hostname" /mnt/vms/cfgs/external/${hostname}/preseed.cfg 
 +  rpl -w "XXX" "$ip" /mnt/vms/cfgs/external/${hostname}/preseed.cfg 
 +  sleep 2s 
 +  echo "Alright, I am opening up virt-installer and building your host ..." 
 +  sleep 2s 
 +  virt-install --name=${hostname}.qcow2 \ 
 +   --os-variant=debian11 \ 
 +   --vcpu=2 \ 
 +   --ram=4096 \ 
 +   --disk path=/mnt/vms/production/${hostname}.qcow2 \ 
 +   --check path_in_use=off \ 
 +   --graphics spice \ 
 +   --location=/mnt/vms/isos/debian-12.4.0-amd64-netinst.iso \ 
 +   --network bridge:br0 \ 
 +   --network bridge:virbr1 \ 
 +   --initrd-inject /mnt/vms/cfgs/external/${hostname}/preseed.cfg
  
-Happy Hacking +This script prompts me for domain name and size of the virtual hard disk. I will likely expand the script to add more parameters down the road, such as but not exclusive to networking, vdd location, ram, and so on. As I expand this, I will update the wiki here and also push my latest scripts and configs to the repository: 
-@oemb1905+ 
 +  * [[https://repo.haacksnetworking.org/haacknet/haackingclub/-/tree/main/scripts/preseeds?ref_type=heads|Preseed Project]] 
 + 
 + --- //[[jonathan@haacksnetworking.org|oemb1905]] 2024/02/17 17:53//
computing/preseed.1708191758.txt.gz · Last modified: 2024/02/17 17:42 by oemb1905