Add features to qemu script and support for other linux distros #6

Merged
brl merged 1 commits from isa/citadel:miscellaneous into master 2024-08-30 09:34:23 -04:00

View File

@ -1,16 +1,11 @@
#!/bin/bash #!/usr/bin/env bash
EXTRA_KERNEL_CMDLINE="" EXTRA_KERNEL_CMDLINE=""
SCRIPT=$(realpath ${BASH_SOURCE}) SCRIPT=$(realpath ${BASH_SOURCE})
BUILD_ROOT=$(realpath $(dirname ${SCRIPT})/../build) BUILD_ROOT=$(realpath $(dirname ${SCRIPT})/../build)
SYSROOT=${BUILD_ROOT}/tmp-glibc/work/x86_64-linux/qemu-helper-native/1.0-r1/recipe-sysroot-native SYSROOT=${BUILD_ROOT}/tmp-glibc/work/x86_64-linux/qemu-helper-native/1.0/recipe-sysroot-native
QEMU=${SYSROOT}/usr/bin/qemu-system-x86_64 QEMU=qemu-system-x86_64
if [[ ! -f ${QEMU} ]]; then
>&2 printf "Qemu binary not found at: ${QEMU}\n"
exit 1
fi
ENABLE_KVM="--enable-kvm -cpu host" ENABLE_KVM="--enable-kvm -cpu host"
@ -20,9 +15,13 @@ if [[ ! -c "/dev/kvm" ]]; then
fi fi
EFI_BIOS="-bios /usr/share/qemu/OVMF.fd" EFI_BIOS="-bios /usr/share/qemu/OVMF.fd"
if [[ ! -f "/usr/share/qemu/OVMF.fd" ]]; then if [[ -f "/usr/share/qemu/OVMF.fd" ]]; then
printf "Disabling EFI boot because OVMF.fd not found in /usr/share/qemu\n" printf "Using EFI boot because OVMF.fd found in /usr/share/qemu/\n"
EFI_BIOS="" elif [[ -f "/usr/share/edk2-ovmf/x64/OVMF.fd" ]]; then # fedora and arch
printf "Using EFI boot because OVMF.fd found in /usr/share/edk2-ovmf/x64/\n"
EFI_BIOS="-bios /usr/share/edk2-ovmf/x64/OVMF.fd"
else
printf "Disabling EFI boot because OVMF.fd not found\n"
fi fi
usage() { usage() {
@ -43,7 +42,7 @@ exit 0
} }
BOOT_TARGET="" BOOT_TARGET=""
MEMORY_ARG="-m 4G" MEMORY_ARG="-m 8G"
DEBUG_MODE=0 DEBUG_MODE=0
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
@ -70,6 +69,14 @@ while [[ $# -gt 0 ]]; do
BOOT_TARGET="installer" BOOT_TARGET="installer"
shift shift
;; ;;
boot-to-install)
BOOT_TARGET="boot-to-install"
shift
;;
boot-installed)
BOOT_TARGET="boot-installed"
shift
;;
--help) --help)
usage usage
;; ;;
@ -84,23 +91,50 @@ COMMON_INSTALLER_ARGS="\
${ENABLE_KVM} \ ${ENABLE_KVM} \
${MEMORY_ARG} \ ${MEMORY_ARG} \
${EFI_BIOS} \ ${EFI_BIOS} \
-vga virtio \ -device virtio-vga-gl \
-display sdl,gl=on \
-vga none \
-usb -device usb-tablet,id=input0 \ -usb -device usb-tablet,id=input0 \
-drive format=raw,file=${BUILD_ROOT}/images/citadel-installer.img \ -nic user,model=virtio-net-pci \
-net none \
-smp 2" -smp 2"
boot_installer() { boot_installer() {
if [[ ${DEBUG_MODE} -eq 1 ]]; then if [[ ${DEBUG_MODE} -eq 1 ]]; then
${QEMU} ${COMMON_INSTALLER_ARGS} \ ${QEMU} ${COMMON_INSTALLER_ARGS} \
-serial stdio \ -serial stdio \
-kernel ${BUILD_ROOT}/images/bzImage \ -kernel ${BUILD_ROOT}/images/bzImage \
-drive format=raw,file=${BUILD_ROOT}/images/citadel-installer.img \
-append "console=ttyS0 earlyprintk=ttyS0 root=/dev/mapper/rootfs citadel.verbose citadel.install fstab=no luks=no systemd.journald.forward_to_console=1 ${EXTRA_KERNEL_CMDLINE}" -append "console=ttyS0 earlyprintk=ttyS0 root=/dev/mapper/rootfs citadel.verbose citadel.install fstab=no luks=no systemd.journald.forward_to_console=1 ${EXTRA_KERNEL_CMDLINE}"
else else
${QEMU} ${COMMON_INSTALLER_ARGS} ${QEMU} ${COMMON_INSTALLER_ARGS} -drive format=raw,file=${BUILD_ROOT}/images/citadel-installer.img
fi fi
} }
# qemu-img create -f qcow2 qemu_disk/citadel_disk.qcow2 -o size=50G,preallocation=metadata
# mount -t 9p -o trans=virtio,version=9p2000.L shared /mnt/my9p
boot_to_install() {
if [ ! -f qemu_disk/citadel_disk.qcow2 ]; then
mkdir qemu_disk
qemu-img create -f qcow2 qemu_disk/citadel_disk.qcow2 -o size=50G,preallocation=metadata
fi
CITADEL_QEMU_ARGS+=" ${COMMON_INSTALLER_ARGS} -drive format=raw,file=${BUILD_ROOT}/images/citadel-installer.img -drive format=qcow2,file=${BUILD_ROOT}/../qemu_disk/citadel_disk.qcow2"
echo "${QEMU} ${CITADEL_QEMU_ARGS}"
${QEMU} ${CITADEL_QEMU_ARGS}
}
boot_installed() {
if [ ! -f qemu_disk/citadel_disk.qcow2 ]; then
printf "The qemu disk is not found on the drive. Please run boot-to-install\n"
fi
CITADEL_QEMU_ARGS+=" ${COMMON_INSTALLER_ARGS} -drive format=qcow2,file=${BUILD_ROOT}/../qemu_disk/citadel_disk.qcow2"
echo "${QEMU} ${CITADEL_QEMU_ARGS}"
${QEMU} ${CITADEL_QEMU_ARGS}
}
boot_kernel() { boot_kernel() {
EXTRA_OPTIONS="" EXTRA_OPTIONS=""
KERNEL_IMAGE="bzImage" KERNEL_IMAGE="bzImage"
@ -124,6 +158,10 @@ if [[ ${BOOT_TARGET} = "kernel" ]]; then
boot_kernel boot_kernel
elif [[ ${BOOT_TARGET} = "installer" ]]; then elif [[ ${BOOT_TARGET} = "installer" ]]; then
boot_installer boot_installer
elif [[ ${BOOT_TARGET} = "boot-to-install" ]]; then
boot_to_install
elif [[ ${BOOT_TARGET} = "boot-installed" ]]; then
boot_installed
else else
usage usage
fi fi