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 todo: make it so this can run this on a network we dont control, the 2
39 ways I know which could work are either running in libvirt's the nated
40 network, and altering the dnsmasq options for the dnsmasq that runs in
41 that, or giving the vm a static ip and for resolving faiserver, and then
42 for resolving "faiserver", either setup some static resolution in the
43 vm, or give it the host machine's ip as a dns server, or in general
44 change references of faiserver to faiserver.b8.nz (I like this idea
45 because it helps in other cases too).
47 Note, sometimes shutting down the existing demohost vm
48 fails. Just run again if that happens.
50 -d When doing pxe with -p, don't do dhcp setup. Good for when we
51 aren't on Ian's home network.
52 -n Create new qcow2(s) for vm. Good for testing partitioning
53 script, to ensure a blank disk.
54 -p Use pxe instead of autodiscover iso with fai.
55 -c Use normal fai-cd iso is instead of autodiscover iso.
56 -r Do not boot after install is complete
57 -h|--help Print help and exit.
59 Note: Uses GNU getopt options parsing style
68 temp
=$
(getopt
-l help dnpcrh
"$@") || usage
1
72 -d) dhcp_arg
=-d; shift ;;
73 -n) new_disk
=true
; shift ;;
74 -p) pxe
=true
; shift ;;
75 -c) iso
=netinst.iso
; shift ;;
76 -r) reboot_arg
=--noreboot; shift ;;
79 *) echo "$0: Internal error!" ; exit 1 ;;
84 # change this to test different disk counts.
89 rm -f /tmp
/fai-revm-did-pxe
91 if ! ip l show br0
&>/dev
/null
; then
93 fai-rvm error: no bridge detected. add one to interfaces like this:
94 iface eth0 inet manual
103 if [[ $script_dir == /a
/bin
/* ]]; then
104 # Copy our script elsewhere so we can develop it
105 # and save it at the same time it's running
106 rm -rf /tmp
/faifreeze
107 cp -ar /a
/bin
/fai
/tmp
/faifreeze
108 exec /tmp
/faifreeze
/${BASH_SOURCE##*/} "${orig_args[@]}"
113 [[ ${0##*/} == arch-revm
]]
118 if [[ -e /tmp
/fai-revm-did-pxe
]]; then
119 e .
/pxe-server
$dhcp_arg
125 if is_arch_revm
; then
126 e .
/pxe-server
$dhcp_arg demohost arch
127 touch /tmp
/fai-revm-did-pxe
129 # via osinfo-query os. guessing arch is closest to latest fedora.
133 e .
/pxe-server
$dhcp_arg demohost fai
134 touch /tmp
/fai-revm-did-pxe
137 killall fai-monitor
&>/dev
/null ||
:
139 if [[ ! $BASEFILE_DIR ]]; then
142 isopath
=$BASEFILE_DIR/$iso
143 isosrc
=$BASEFILE_DIR/BULLSEYE64.
tar.gz
144 if [[ ! -e $isopath || $
(stat
-c %Y
$isopath) -lt $
(stat
-c %Y
$isosrc) ]]; then
145 e fai-cd
-g $
(readlink
-f grub.cfg.
${iso%%.*}) -f -A $isopath
147 boot_arg
="--cdrom $isopath"
149 cat ~
/.ssh
/demo.pub |
/a
/exe
/cedit
-s /srv
/fai
/nfsroot
/root
/.ssh
/authorized_keys
150 e myfai-chboot default
152 # I don't think these variants actually make a diff for us, but I
153 # use the appropriate one when trying a new distro just in case.
162 e virsh destroy
$name ||
:
164 e virsh destroy
$name ||
:
165 e virsh undefine
$name ||
:
170 for ((i
=1; i
<= disk_count
; i
++)); do
171 f
=/var
/lib
/libvirt
/images
/${name}$i
172 disk_arg
+=("--disk path=$f")
173 if $new_disk ||
[[ ! -e $f ]]; then
175 # https://btrfs.wiki.kernel.org/index.php/FAQ
178 e qemu-img create
-o preallocation
=metadata
-f qcow2
$f 50G
182 if [[ $SSH_CLIENT ]]; then
183 console_arg
=--noautoconsole
186 # docker makes forward default to drop, which blocks the vm pxe on flidas. easiest solution:
187 e iptables
-P FORWARD ACCEPT
189 # --cpu host: this causes mkfs.btrfs to fail with a stack trace which began
191 # init_module+0x108/0x1000 [raid6_pq]
193 # uniq is to stop gtk-warning spam
194 # e virt-install --os-variant $variant -n $name --pxe -r 2048 --vcpus 1 \
195 # ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad $reboot_arg \
196 # --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^ *$' | uniq &
199 if (( $
(nproc
) > 2 )); then
203 e systemctl start libvirtd
204 e virt-install
--rng /dev
/urandom
--os-variant $variant -n $name $boot_arg -r 2048 --vcpus $cpus \
205 ${disk_arg[*]} -w bridge
=br0
,mac
=52:54:00:9c
:ef
:ad
$reboot_arg \
206 --graphics spice
,listen
=0.0.0.0 $console_arg |
& grep -v '^ *$' |
uniq &
209 if [[ $SSH_CLIENT ]]; then
214 while ! timeout
-s 9 10 ssh -oBatchMode=yes root@
$name true
; do
219 rm -f /tmp
/fai-revm-did-pxe
220 e .
/pxe-server
$dhcp_arg
223 # this tends to remove it too soon
224 #echo | /a/exe/cedit -s /srv/fai/nfsroot/root/.ssh/authorized_keys
226 if is_arch_revm
; then
227 .
/arch-init-remote
$name