Score:0

How to disable output to console after launching QEMU VM?

mu flag

I have to run three VMs on QEMU.

for VM in ctrl-vm src-vm dst-vm
do
    case ${VM} in
        "ctrl-vm")
            mac_addr=00:00:00:00:00:01
            tap=tap0
            port=30020
            ;;
        "src-vm")
            mac_addr=00:00:00:00:00:02
            tap=tap1
            port=30021
            ;;  
        "dst-vm")
            mac_addr=00:00:00:00:00:03
            tap=tap2
            port=30022
            ;;
    esac
    
    DISTRO="debian-bullseye"
    IMAGE_NAME=${VM}
    MACHINE_NAME="qemuamd64"
    IMAGE_TYPE="wic.img"
    ROOTFS="/dev/sda2"

    FULL_IMAGE_NAME="${IMAGE_NAME}-${DISTRO}-${MACHINE_NAME}"
    ISAR_OUT_DIR="${KAS_WORK_DIR}/build/tmp/deploy/images/${MACHINE_NAME}"
    DISK_PATH="${ISAR_OUT_DIR}/${FULL_IMAGE_NAME}"
    KERNEL="${DISK_PATH}-vmlinuz"
    INITRD="${DISK_PATH}-initrd.img"

    if [ -n "${QEMU_PATH}" ]; then
        QEMU_PATH="${QEMU_PATH}/"
    fi

    QEMU=qemu-system-x86_64
    QEMU_EXTRA_ARGS=" \
        -s \
        -nographic \
        -cpu host -smp 4 \
        -enable-kvm -machine q35 \
        -device ide-hd,drive=disk \
        -device virtio-net-pci,netdev=vnet0,mac=${mac_addr}" 
    KERNEL_CMDLINE=" \
        root=${ROOTFS} console=ttyS0 debug \
        "
    ${QEMU_PATH}${QEMU} \
        -drive file=${DISK_PATH}.${IMAGE_TYPE},discard=unmap,if=none,id=disk,format=raw \
        -m 1G \
        -netdev tap,id=vnet0,ifname=${tap},script=no,downscript=no \
        -net user,hostfwd=tcp::30020-:22 \
        -kernel "${KERNEL}" \
        -append "${KERNEL_CMDLINE}" \
        -initrd "${INITRD}" ${QEMU_EXTRA_ARGS} "$@" &

done

I would like to run VMs in the background and connect them via ssh (IPs are already assigned in the image). But when I run the script, the VM console starts in the same terminal, and the other 2 VMs do not start. I already added "&" at the end of the command, but still does not work.

Grafana Alert avatar
mu flag
Found the answer: I should use -daemonize.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.