| 1 | #!/usr/bin/env bash
|
|---|
| 2 | set -o errexit -o nounset -o pipefail
|
|---|
| 3 | #set -o xtrace
|
|---|
| 4 |
|
|---|
| 5 | start() {
|
|---|
| 6 | local vm=debian-stretch-netinst
|
|---|
| 7 | local ostype=Debian_64
|
|---|
| 8 | local os_iso_url=https://cdimage.debian.org/cdimage/release/9.7.0/amd64/iso-cd/debian-9.7.0-amd64-netinst.iso
|
|---|
| 9 | local os_iso=/tmp/$(basename $os_iso_url)
|
|---|
| 10 |
|
|---|
| 11 | if ! test -e $os_iso; then
|
|---|
| 12 | curl --fail --location --create-dirs --output $os_iso-$$ $os_iso_url
|
|---|
| 13 | mv $os_iso-$$ $os_iso # this only happens if previous cmds succeeds (because of errexit)
|
|---|
| 14 | fi
|
|---|
| 15 |
|
|---|
| 16 | local base_dir=/tmp/vms
|
|---|
| 17 | local aux_base_path=/tmp/$vm/$vm-unattended-install-
|
|---|
| 18 |
|
|---|
| 19 | VBoxManage unregistervm $vm --delete > /dev/null || true
|
|---|
| 20 |
|
|---|
| 21 | rm -fr $base_dir/$vm
|
|---|
| 22 | mkdir -p $base_dir/$vm
|
|---|
| 23 |
|
|---|
| 24 | rm -fr $(dirname $aux_base_path)
|
|---|
| 25 | mkdir -p $(dirname $aux_base_path)
|
|---|
| 26 |
|
|---|
| 27 | VBoxManage createvm \
|
|---|
| 28 | --name $vm \
|
|---|
| 29 | --basefolder $base_dir \
|
|---|
| 30 | --ostype $ostype \
|
|---|
| 31 | --register \
|
|---|
| 32 |
|
|---|
| 33 | VBoxManage modifyvm $vm \
|
|---|
| 34 | --memory 1024 \
|
|---|
| 35 | --vram 16 \
|
|---|
| 36 |
|
|---|
| 37 | VBoxManage storagectl $vm \
|
|---|
| 38 | --name SAS \
|
|---|
| 39 | --add sas \
|
|---|
| 40 | --portcount 1 \
|
|---|
| 41 | --bootable on \
|
|---|
| 42 |
|
|---|
| 43 | VBoxManage createmedium disk \
|
|---|
| 44 | --filename $base_dir/$vm/$vm.vdi \
|
|---|
| 45 | --size 8192 \
|
|---|
| 46 | --format VDI \
|
|---|
| 47 |
|
|---|
| 48 | # SAS-0-0
|
|---|
| 49 | VBoxManage storageattach $vm \
|
|---|
| 50 | --medium $base_dir/$vm/$vm.vdi \
|
|---|
| 51 | --storagectl SAS \
|
|---|
| 52 | --port 0 \
|
|---|
| 53 | --device 0 \
|
|---|
| 54 | --type hdd \
|
|---|
| 55 |
|
|---|
| 56 | VBoxManage storagectl $vm \
|
|---|
| 57 | --name SATA \
|
|---|
| 58 | --add sata \
|
|---|
| 59 | --portcount 1 \
|
|---|
| 60 | --bootable on \
|
|---|
| 61 |
|
|---|
| 62 | # SATA-0-0
|
|---|
| 63 | VBoxManage storageattach $vm \
|
|---|
| 64 | --medium emptydrive \
|
|---|
| 65 | --storagectl SATA \
|
|---|
| 66 | --port 0 \
|
|---|
| 67 | --device 0 \
|
|---|
| 68 | --type dvddrive \
|
|---|
| 69 | --mtype readonly \
|
|---|
| 70 |
|
|---|
| 71 | local aux_base_path=/tmp/$vm/$vm-unattended-install-
|
|---|
| 72 |
|
|---|
| 73 | VBoxManage unattended install $vm \
|
|---|
| 74 | --auxiliary-base-path $aux_base_path \
|
|---|
| 75 | --iso $os_iso \
|
|---|
| 76 |
|
|---|
| 77 | if test ${fix:-0} -ne 0; then # fix isolinux-txt.cfg (isolinux/txt.cfg)
|
|---|
| 78 | echo "fixing ${aux_base_path}isolinux-txt.cfg"
|
|---|
| 79 | cp ${aux_base_path}isolinux-txt.cfg ${aux_base_path}isolinux-txt.cfg.orig
|
|---|
| 80 |
|
|---|
| 81 | patch ${aux_base_path}isolinux-txt.cfg < fix.patch
|
|---|
| 82 |
|
|---|
| 83 | diff ${aux_base_path}isolinux-txt.cfg.orig ${aux_base_path}isolinux-txt.cfg || true
|
|---|
| 84 | fi
|
|---|
| 85 |
|
|---|
| 86 | VBoxManage startvm $vm
|
|---|
| 87 | }
|
|---|
| 88 | start
|
|---|