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.
19 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
22 readonly this_file
="$(readlink -f -- "${BASH_SOURCE[0]}")"
23 script_dir
="${this_file%/*}"
24 # shellcheck source=./bash-trace
25 source "${script_dir}/bash-trace"
29 e
() { echo "$*"; "$@"; }
34 # Usage: ${0##*/} [OPTIONS]
35 Setup fai or arch pxe (depending on $0 name)
36 then start a virtual machine to test the config
38 Note, sometimes shutting down the existing demohost vm
39 fails. Just run again if that happens.
41 -d When doing pxe, don't do dhcp setup. Good for when we
42 aren't on Ian's home network.
43 -n Create new qcow2(s) for vm. Good for testing partitioning
44 script, to ensure a blank disk.
45 -p Use pxe instead of autodiscover iso with fai.
46 -c Use normal fai-cd iso is instead of autodiscover iso.
47 -r Do not boot after install is complete
48 -h|--help Print help and exit.
50 Note: Uses GNU getopt options parsing style
59 temp
=$
(getopt
-l help dnpcrh
"$@") || usage
1
63 -d) dhcp_arg
=-d; shift ;;
64 -n) new_disk
=true
; shift ;;
65 -p) pxe
=true
; shift ;;
66 -c) iso
=netinst.iso
; shift ;;
67 -r) reboot_arg
=--noreboot; shift ;;
70 *) echo "$0: Internal error!" ; exit 1 ;;
75 # change this to test different disk counts.
80 rm -f /tmp
/fai-revm-did-pxe
82 if ! ip l show br0
&>/dev
/null
; then
84 fai-rvm error: no bridge detected. add one to interfaces like this:
85 iface eth0 inet manual
94 if [[ $script_dir == /a
/bin
/* ]]; then
95 # Copy our script elsewhere so we can develop it
96 # and save it at the same time it's running
98 cp -ar /a
/bin
/fai
/tmp
/faifreeze
99 exec /tmp
/faifreeze
/${BASH_SOURCE##*/} "${orig_args[@]}"
104 [[ ${0##*/} == arch-revm
]]
109 if [[ -e /tmp
/fai-revm-did-pxe
]]; then
110 e .
/pxe-server
$dhcp_arg
116 if is_arch_revm
; then
117 e .
/pxe-server
$dhcp_arg demohost arch
118 touch /tmp
/fai-revm-did-pxe
120 # via osinfo-query os. guessing arch is closest to latest fedora.
124 e .
/pxe-server
$dhcp_arg demohost fai
125 touch /tmp
/fai-revm-did-pxe
128 killall fai-monitor
&>/dev
/null ||
:
130 if [[ ! $BASEFILE_DIR ]]; then
133 isopath
=$BASEFILE_DIR/$iso
134 isosrc
=$BASEFILE_DIR/BULLSEYE64.
tar.gz
135 if [[ ! -e $isopath || $
(stat
-c %Y
$isopath) -lt $
(stat
-c %Y
$isosrc) ]]; then
136 e fai-cd
-g $
(readlink
-f grub.cfg.
${iso%%.*}) -f -A $isopath
138 boot_arg
="--cdrom $isopath"
140 cat ~
/.ssh
/demo.pub |
/a
/exe
/cedit
-s /srv
/fai
/nfsroot
/root
/.ssh
/authorized_keys
141 e myfai-chboot default
143 # I don't think these variants actually make a diff for us, but I
144 # use the appropriate one when trying a new distro just in case.
153 e virsh destroy
$name ||
:
155 e virsh destroy
$name ||
:
156 e virsh undefine
$name ||
:
161 for ((i
=1; i
<= disk_count
; i
++)); do
162 f
=/var
/lib
/libvirt
/images
/${name}$i
163 disk_arg
+=("--disk path=$f")
164 if $new_disk ||
[[ ! -e $f ]]; then
166 # https://btrfs.wiki.kernel.org/index.php/FAQ
169 e qemu-img create
-o preallocation
=metadata
-f qcow2
$f 50G
173 if [[ $SSH_CLIENT ]]; then
174 console_arg
=--noautoconsole
177 # docker makes forward default to drop, which blocks the vm pxe on flidas. easiest solution:
178 e iptables
-P FORWARD ACCEPT
180 # --cpu host: this causes mkfs.btrfs to fail with a stack trace which began
182 # init_module+0x108/0x1000 [raid6_pq]
184 # uniq is to stop gtk-warning spam
185 # e virt-install --os-variant $variant -n $name --pxe -r 2048 --vcpus 1 \
186 # ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad $reboot_arg \
187 # --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^ *$' | uniq &
190 if (( $
(nproc
) > 2 )); then
194 e systemctl start libvirtd
195 e virt-install
--rng /dev
/urandom
--os-variant $variant -n $name $boot_arg -r 2048 --vcpus $cpus \
196 ${disk_arg[*]} -w bridge
=br0
,mac
=52:54:00:9c
:ef
:ad
$reboot_arg \
197 --graphics spice
,listen
=0.0.0.0 $console_arg |
& grep -v '^ *$' |
uniq &
200 if [[ $SSH_CLIENT ]]; then
205 while ! timeout
-s 9 10 ssh -oBatchMode=yes root@
$name true
; do
210 rm -f /tmp
/fai-revm-did-pxe
211 e .
/pxe-server
$dhcp_arg
214 # this tends to remove it too soon
215 #echo | /a/exe/cedit -s /srv/fai/nfsroot/root/.ssh/authorized_keys
217 if is_arch_revm
; then
218 .
/arch-init-remote
$name