2 # Copyright (C) 2016 Ian Kelling
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 readonly this_file
="$(readlink -f -- "${BASH_SOURCE[0]}")"
21 script_dir
="${this_file%/*}"
22 # shellcheck source=./bash-trace
23 source "${script_dir}/bash-trace"
27 e
() { echo "$*"; "$@"; }
32 # Usage: ${0##*/} [OPTIONS]
33 Setup fai or arch pxe (depending on $0 name)
34 then start a virtual machine to test the config
36 Note, sometimes shutting down the existing demohost vm
37 fails. Just run again if that happens.
39 -d Don't do dhcp setup for when we aren't on Ian's home network.
40 -n Create new qcow2(s) for vm. Good for testing partitioning
41 script, to ensure a blank disk.
42 -p Use pxe instead of autodiscover iso with fai.
43 -c Use normal fai-cd iso is instead of autodiscover iso.
44 -r Do not boot after install is complete
45 -h|--help Print help and exit.
47 Note: Uses GNU getopt options parsing style
56 temp
=$
(getopt
-l help dnpcrh
"$@") || usage
1
60 -d) dhcp_arg
=-d; shift ;;
61 -n) new_disk
=true
; shift ;;
62 -p) pxe
=true
; shift ;;
63 -c) iso
=netinst.iso
; shift ;;
64 -r) reboot_arg
=--noreboot; shift ;;
67 *) echo "$0: Internal error!" ; exit 1 ;;
72 # change this to test different disk counts. 1 and > 1 should be the only
73 # important things to test.
77 if ! ip l show br0
&>/dev
/null
; then
79 fai-rvm error: no bridge detected. add one to interfaces like this:
80 iface eth0 inet manual
89 if [[ $script_dir == /a
/bin
/* ]]; then
90 # Copy our script elsewhere so we can develop it
91 # and save it at the same time it's running
93 cp -ar /a
/bin
/fai
/tmp
/faifreeze
94 exec /tmp
/faifreeze
/${BASH_SOURCE##*/} "${orig_args[@]}"
99 [[ ${0##*/} == arch-revm
]]
104 e .
/pxe-server
$dhcp_arg
109 if is_arch_revm
; then
110 e .
/pxe-server
$dhcp_arg demohost arch
112 # via osinfo-query os. guessing arch is closest to latest fedora.
116 e .
/pxe-server
$dhcp_arg demohost fai
119 killall fai-monitor
&>/dev
/null ||
:
121 if [[ ! $BASEFILE_DIR ]]; then
124 isopath
=$BASEFILE_DIR/$iso
125 isosrc
=$BASEFILE_DIR/BUSTER64.
tar.gz
126 if [[ ! -e $isopath || $
(stat
-c %Y
$isopath) -lt $
(stat
-c %Y
$isosrc) ]]; then
127 e sudo fai-cd
-g $
(readlink
-f grub.cfg.
${iso%%.*}) -f -A $isopath
129 boot_arg
="--cdrom $isopath"
131 e myfai-chboot default
133 # I don't think these variants actually make a diff for us, but I
134 # use the appropriate one when trying a new distro just in case.
142 e sudo virsh destroy
$name ||
:
143 e sudo virsh undefine
$name ||
:
147 for ((i
=1; i
<= disk_count
; i
++)); do
148 f
=/var
/lib
/libvirt
/images
/${name}$i
149 disk_arg
+=("--disk path=$f")
150 if $new_disk ||
[[ ! -e $f ]]; then
152 e sudo qemu-img create
-o preallocation
=metadata
-f qcow2
$f 50G
156 if [[ $SSH_CLIENT ]]; then
157 console_arg
=--noautoconsole
160 # docker makes forward default to drop, which blocks the vm pxe on flidas. easiest solution:
161 e sudo iptables
-P FORWARD ACCEPT
163 # --cpu host: this causes mkfs.btrfs to fail with a stack trace which began
165 # init_module+0x108/0x1000 [raid6_pq]
167 # uniq is to stop gtk-warning spam
168 # e sudo virt-install --os-variant $variant -n $name --pxe -r 2048 --vcpus 1 \
169 # ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad $reboot_arg \
170 # --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^ *$' | uniq &
173 if (( $
(nproc
) > 2 )); then
177 e sudo systemctl start libvirtd
178 e sudo virt-install
--rng /dev
/urandom
--os-variant $variant -n $name $boot_arg -r 2048 --vcpus $cpus \
179 ${disk_arg[*]} -w bridge
=br0
,mac
=52:54:00:9c
:ef
:ad
$reboot_arg \
180 --graphics spice
,listen
=0.0.0.0 $console_arg |
& grep -v '^ *$' |
uniq &
183 if [[ $SSH_CLIENT ]]; then
188 while ! timeout
-s 9 10 ssh -oBatchMode=yes root@
$name /bin
/true
; do
192 e .
/pxe-server
$dhcp_arg
193 if is_arch_revm
; then
194 .
/arch-init-remote
$name