Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/run_archiso.sh158
1 files changed, 88 insertions, 70 deletions
diff --git a/scripts/run_archiso.sh b/scripts/run_archiso.sh
index 210246c..6ddce15 100755
--- a/scripts/run_archiso.sh
+++ b/scripts/run_archiso.sh
@@ -15,117 +15,131 @@
set -eu
print_help() {
- cat << EOF
+ local usagetext
+ IFS='' read -r -d '' usagetext <<EOF || true
Usage:
run_archiso [options]
Options:
- -b set boot type to 'bios' (default)
+ -a set accessibility support using brltty
+ -b set boot type to 'BIOS' (default)
+ -d set image type to hard disk instead of optical disc
-h print help
-i [image] image to boot into
- -s use secure boot (only relevant when using UEFI)
- -u set boot type to 'uefi'
+ -s use Secure Boot (only relevant when using UEFI)
+ -u set boot type to 'UEFI'
+ -v use VNC display (instead of default SDL)
+ -c [image] attach an additional optical disc image (e.g. for cloud-init)
Example:
Run an image using UEFI:
$ run_archiso -u -i archiso-2020.05.23-x86_64.iso
EOF
+ printf '%s' "${usagetext}"
}
cleanup_working_dir() {
- if [ -d "${working_dir}" ]; then
- rm -rf "${working_dir}"
+ if [[ -d "${working_dir}" ]]; then
+ rm -rf -- "${working_dir}"
fi
}
copy_ovmf_vars() {
- if [ ! -f /usr/share/edk2-ovmf/x64/OVMF_VARS.fd ]; then
- echo "ERROR: OVMF_VARS.fd not found. Install edk2-ovmf."
+ if [[ ! -f '/usr/share/edk2-ovmf/x64/OVMF_VARS.fd' ]]; then
+ printf 'ERROR: %s\n' "OVMF_VARS.fd not found. Install edk2-ovmf."
exit 1
fi
- cp -av /usr/share/edk2-ovmf/x64/OVMF_VARS.fd "${working_dir}"
+ cp -av -- '/usr/share/edk2-ovmf/x64/OVMF_VARS.fd' "${working_dir}/"
}
check_image() {
- if [ -z "$image" ]; then
- echo "ERROR: Image name can not be empty."
+ if [[ -z "$image" ]]; then
+ printf 'ERROR: %s\n' "Image name can not be empty."
exit 1
fi
- if [ ! -f "$image" ]; then
- echo "ERROR: Image file ($image) does not exist."
+ if [[ ! -f "$image" ]]; then
+ printf 'ERROR: %s\n' "Image file (${image}) does not exist."
exit 1
fi
}
run_image() {
- [ "$boot_type" == "bios" ] && run_image_using_bios
- [ "$boot_type" == "uefi" ] && run_image_using_uefi
-}
+ if [[ "$boot_type" == 'uefi' ]]; then
+ copy_ovmf_vars
+ if [[ "${secure_boot}" == 'on' ]]; then
+ printf '%s\n' 'Using Secure Boot'
+ local ovmf_code='/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd'
+ else
+ local ovmf_code='/usr/share/edk2-ovmf/x64/OVMF_CODE.fd'
+ fi
+ qemu_options+=(
+ '-drive' "if=pflash,format=raw,unit=0,file=${ovmf_code},read-only=on"
+ '-drive' "if=pflash,format=raw,unit=1,file=${working_dir}/OVMF_VARS.fd"
+ '-global' "driver=cfi.pflash01,property=secure,value=${secure_boot}"
+ )
+ fi
-run_image_using_bios() {
- qemu-system-x86_64 \
- -boot order=d,menu=on,reboot-timeout=5000 \
- -m size=3072,slots=0,maxmem=$((3072*1024*1024)) \
- -k en \
- -name archiso,process=archiso_0 \
- -drive file="${image}",media=cdrom,readonly=on,if=virtio \
- -display sdl \
- -vga virtio \
- -device virtio-net-pci,netdev=net0 -netdev user,id=net0 \
- -enable-kvm \
- -no-reboot
-}
+ if [[ "${accessibility}" == 'on' ]]; then
+ qemu_options+=(
+ '-chardev' 'braille,id=brltty'
+ '-device' 'usb-braille,id=usbbrl,chardev=brltty'
+ )
+ fi
-run_image_using_uefi() {
- local ovmf_code=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd
- local secure_boot_state=off
- copy_ovmf_vars
- if [ "${secure_boot}" == "yes" ]; then
- echo "Using Secure Boot"
- ovmf_code=/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd
- secure_boot_state=on
+ if [[ -n "${oddimage}" ]]; then
+ qemu_options+=(
+ '-device' 'scsi-cd,bus=scsi0.0,drive=cdrom1'
+ '-drive' "id=cdrom1,if=none,format=raw,media=cdrom,read-only=on,file=${oddimage}"
+ )
fi
+
qemu-system-x86_64 \
-boot order=d,menu=on,reboot-timeout=5000 \
- -m size=3072,slots=0,maxmem=$((3072*1024*1024)) \
- -k en \
+ -m "size=3072,slots=0,maxmem=$((3072*1024*1024))" \
+ -k en-us \
-name archiso,process=archiso_0 \
- -drive file="${image}",media=cdrom,readonly=on,if=virtio \
- -drive if=pflash,format=raw,unit=0,file="${ovmf_code}",readonly \
- -drive if=pflash,format=raw,unit=1,file="${working_dir}/OVMF_VARS.fd" \
- -machine type=q35,smm=on,accel=kvm \
- -global driver=cfi.pflash01,property=secure,value="${secure_boot_state}" \
- -global ICH9-LPC.disable_s3=1 \
- -display sdl \
+ -device virtio-scsi-pci,id=scsi0 \
+ -device "scsi-${mediatype%rom},bus=scsi0.0,drive=${mediatype}0" \
+ -drive "id=${mediatype}0,if=none,format=raw,media=${mediatype/hd/disk},read-only=on,file=${image}" \
+ -display "${display}" \
-vga virtio \
- -device virtio-net-pci,netdev=net0 -netdev user,id=net0 \
+ -audiodev pa,id=snd0 \
+ -device ich9-intel-hda \
+ -device hda-output,audiodev=snd0 \
+ -device virtio-net-pci,romfile=,netdev=net0 -netdev user,id=net0,hostfwd=tcp::60022-:22 \
+ -machine type=q35,smm=on,accel=kvm,usb=on,pcspk-audiodev=snd0 \
+ -global ICH9-LPC.disable_s3=1 \
-enable-kvm \
+ "${qemu_options[@]}" \
+ -serial stdio \
-no-reboot
}
-set_image() {
- if [ -z "$image" ]; then
- echo "ERROR: Image name can not be empty."
- exit 1
- fi
- if [ ! -f "$image" ]; then
- echo "ERROR: Image ($image) does not exist."
- exit 1
- fi
- image="$1"
-}
-
-image=""
-boot_type="bios"
-secure_boot="no"
-working_dir="$(mktemp -d)"
+image=''
+oddimage=''
+accessibility=''
+boot_type='bios'
+mediatype='cdrom'
+secure_boot='off'
+display='sdl'
+qemu_options=()
+working_dir="$(mktemp -dt run_archiso.XXXXXXXXXX)"
trap cleanup_working_dir EXIT
-if [ ${#@} -gt 0 ]; then
- while getopts 'bhi:su' flag; do
- case "${flag}" in
+if (( ${#@} > 0 )); then
+ while getopts 'abc:dhi:suv' flag; do
+ case "$flag" in
+ a)
+ accessibility='on'
+ ;;
b)
- boot_type=bios
+ boot_type='bios'
+ ;;
+ c)
+ oddimage="$OPTARG"
+ ;;
+ d)
+ mediatype='hd'
;;
h)
print_help
@@ -135,13 +149,17 @@ if [ ${#@} -gt 0 ]; then
image="$OPTARG"
;;
u)
- boot_type=uefi
+ boot_type='uefi'
;;
s)
- secure_boot=yes
+ secure_boot='on'
+ ;;
+ v)
+ display='none'
+ qemu_options+=(-vnc 'vnc=0.0.0.0:0,vnc=[::]:0')
;;
*)
- echo "Error: Wrong option. Try 'run_archiso -h'."
+ printf '%s\n' "Error: Wrong option. Try 'run_archiso -h'."
exit 1
;;
esac