2024-07-18 20:03:29 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-01-07 19:19:59 +00:00
|
|
|
|
2019-01-15 19:36:29 +00:00
|
|
|
EXTRA_KERNEL_CMDLINE=""
|
2019-01-07 19:19:59 +00:00
|
|
|
|
|
|
|
SCRIPT=$(realpath ${BASH_SOURCE})
|
|
|
|
BUILD_ROOT=$(realpath $(dirname ${SCRIPT})/../build)
|
2024-07-18 20:03:29 +00:00
|
|
|
SYSROOT=${BUILD_ROOT}/tmp-glibc/work/x86_64-linux/qemu-helper-native/1.0/recipe-sysroot-native
|
|
|
|
QEMU=qemu-system-x86_64
|
2019-01-07 19:19:59 +00:00
|
|
|
|
|
|
|
ENABLE_KVM="--enable-kvm -cpu host"
|
|
|
|
|
|
|
|
if [[ ! -c "/dev/kvm" ]]; then
|
|
|
|
printf "Disabling KVM because /dev/kvm is not available\n"
|
|
|
|
ENABLE_KVM=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
EFI_BIOS="-bios /usr/share/qemu/OVMF.fd"
|
2024-07-18 20:03:29 +00:00
|
|
|
if [[ -f "/usr/share/qemu/OVMF.fd" ]]; then
|
|
|
|
printf "Using EFI boot because OVMF.fd found in /usr/share/qemu/\n"
|
|
|
|
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"
|
2019-01-07 19:19:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat <<-EOF
|
|
|
|
USAGE: qemu-boot [options] installer Boot build/images/citadel-installer.img
|
|
|
|
qemu-boot [options] kernel Boot build/images/bzImage
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
|
|
|
|
--no-efi Do not use OVMF UEFI bios
|
|
|
|
--memory size Set custom guest RAM size
|
2019-01-07 23:55:57 +00:00
|
|
|
--debug Boot installer with console and journald dumped to terminal
|
2019-01-07 19:19:59 +00:00
|
|
|
|
|
|
|
To exit kernel boot type 'ctrl-a x' (See escape sequences in qemu-system man page)
|
|
|
|
|
|
|
|
EOF
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOT_TARGET=""
|
2024-07-18 20:03:29 +00:00
|
|
|
MEMORY_ARG="-m 8G"
|
2019-01-15 19:36:29 +00:00
|
|
|
DEBUG_MODE=0
|
2019-01-07 19:19:59 +00:00
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
key=${1}
|
|
|
|
case $key in
|
|
|
|
--no-efi)
|
|
|
|
EFI_BIOS=""
|
|
|
|
shift
|
|
|
|
;;
|
2019-01-07 23:55:57 +00:00
|
|
|
--debug)
|
2019-01-15 19:36:29 +00:00
|
|
|
DEBUG_MODE=1
|
2019-01-07 23:55:57 +00:00
|
|
|
shift
|
|
|
|
;;
|
2019-01-07 19:19:59 +00:00
|
|
|
--memory)
|
|
|
|
MEMORY_ARG="-m ${2}"
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
kernel)
|
|
|
|
BOOT_TARGET="kernel"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
installer)
|
|
|
|
BOOT_TARGET="installer"
|
|
|
|
shift
|
|
|
|
;;
|
2024-07-18 20:03:29 +00:00
|
|
|
boot-to-install)
|
|
|
|
BOOT_TARGET="boot-to-install"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
boot-installed)
|
|
|
|
BOOT_TARGET="boot-installed"
|
|
|
|
shift
|
|
|
|
;;
|
2019-01-07 19:19:59 +00:00
|
|
|
--help)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "Unknown option ${key}\n"
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2019-01-07 23:55:57 +00:00
|
|
|
COMMON_INSTALLER_ARGS="\
|
|
|
|
${ENABLE_KVM} \
|
|
|
|
${MEMORY_ARG} \
|
|
|
|
${EFI_BIOS} \
|
2024-07-18 20:03:29 +00:00
|
|
|
-device virtio-vga-gl \
|
|
|
|
-display sdl,gl=on \
|
|
|
|
-vga none \
|
2019-01-07 23:55:57 +00:00
|
|
|
-usb -device usb-tablet,id=input0 \
|
2024-07-18 20:03:29 +00:00
|
|
|
-nic user,model=virtio-net-pci \
|
2019-01-07 23:55:57 +00:00
|
|
|
-smp 2"
|
|
|
|
|
2019-01-07 19:19:59 +00:00
|
|
|
boot_installer() {
|
2019-01-15 19:36:29 +00:00
|
|
|
if [[ ${DEBUG_MODE} -eq 1 ]]; then
|
2024-07-18 20:03:29 +00:00
|
|
|
${QEMU} ${COMMON_INSTALLER_ARGS} \
|
2019-01-07 23:55:57 +00:00
|
|
|
-serial stdio \
|
|
|
|
-kernel ${BUILD_ROOT}/images/bzImage \
|
2024-07-18 20:03:29 +00:00
|
|
|
-drive format=raw,file=${BUILD_ROOT}/images/citadel-installer.img \
|
2019-01-15 19:36:29 +00:00
|
|
|
-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}"
|
2019-01-07 23:55:57 +00:00
|
|
|
else
|
2024-07-18 20:03:29 +00:00
|
|
|
${QEMU} ${COMMON_INSTALLER_ARGS} -drive format=raw,file=${BUILD_ROOT}/images/citadel-installer.img
|
2019-01-07 23:55:57 +00:00
|
|
|
fi
|
2019-01-07 19:19:59 +00:00
|
|
|
}
|
|
|
|
|
2024-07-18 20:03:29 +00:00
|
|
|
# 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}
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:19:59 +00:00
|
|
|
boot_kernel() {
|
2019-01-15 19:36:29 +00:00
|
|
|
EXTRA_OPTIONS=""
|
|
|
|
KERNEL_IMAGE="bzImage"
|
|
|
|
if [[ ${DEBUG_MODE} -eq 1 ]]; then
|
|
|
|
EXTRA_OPTIONS="-s -S"
|
|
|
|
KERNEL_IMAGE="bzImage-intel-corei7-64.bin"
|
|
|
|
fi
|
|
|
|
|
2019-01-07 19:19:59 +00:00
|
|
|
${QEMU} \
|
|
|
|
${ENABLE_KVM} \
|
|
|
|
${MEMORY_ARG} \
|
2019-01-15 19:36:29 +00:00
|
|
|
${EXTRA_OPTIONS} \
|
2019-01-07 19:19:59 +00:00
|
|
|
-nographic \
|
2019-01-15 19:36:29 +00:00
|
|
|
-no-reboot \
|
2019-01-07 19:19:59 +00:00
|
|
|
-smp 2 \
|
2019-01-15 19:36:29 +00:00
|
|
|
-append "rd.emergency console=ttyS0 earlyprintk=ttyS0 ${EXTRA_KERNEL_CMDLINE}" \
|
|
|
|
-kernel ${BUILD_ROOT}/images/${KERNEL_IMAGE}
|
2019-01-07 19:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ ${BOOT_TARGET} = "kernel" ]]; then
|
|
|
|
boot_kernel
|
|
|
|
elif [[ ${BOOT_TARGET} = "installer" ]]; then
|
|
|
|
boot_installer
|
2024-07-18 20:03:29 +00:00
|
|
|
elif [[ ${BOOT_TARGET} = "boot-to-install" ]]; then
|
|
|
|
boot_to_install
|
|
|
|
elif [[ ${BOOT_TARGET} = "boot-installed" ]]; then
|
|
|
|
boot_installed
|
2019-01-07 19:19:59 +00:00
|
|
|
else
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|