The QEMU command creates a virtual machine with a Windows 10 ISO file, enables VirtIO drivers and networking, and configures various device settings. The command also allocates 6144 MB of memory and synchronizes the VM's clock with the host system's clock.
#!/bin/sh
WINIMG=~/vm/Win10_1803_English_x64.iso
VIRTIMG=~/vm/virtio-win-0.1.149.iso
qemu-system-x86_64 --enable-kvm -drive driver=raw,file=~/vm/win10.img,if=virtio -m 6144 \
-net nic,model=virtio -net user -cdrom ${WINIMG} \
-drive file=${VIRTIMG},index=3,media=cdrom \
-rtc base=localtime,clock=host -smp cores=4,threads=8 \
-usb -device usb-tablet \
-net user,smb=$HOME
#!/bin/bash
# Define VM configuration constants
declare -A VM_CONFIG
VM_CONFIG[IMG_DIR]="/home/user/vm"
VM_CONFIG[WIN10_IMG_NAME]="win10.img"
VM_CONFIG[WIN10_ISO]="Win10_1803_English_x64.iso"
VM_CONFIG[VIRTIO_WIN_ISO]="virtio-win-0.1.149.iso"
VM_CONFIG[QEMU_SYSTEM_X86_64_BIN]="qemu-system-x86_64"
# Set paths to disk images and ISO files
VM_CONFIG[IMG_PATH]="${VM_CONFIG[IMG_DIR]}/${VM_CONFIG[WIN10_IMG_NAME]}"
VM_CONFIG[WIN10_ISO_PATH]="${VM_CONFIG[IMG_DIR]}/${VM_CONFIG[WIN10_ISO]}"
VM_CONFIG[VIRTIO_WIN_ISO_PATH]="${VM_CONFIG[IMG_DIR]}/${VM_CONFIG[VIRTIO_WIN_ISO]}"
# Define QEMU command
QEMU_CMD="${VM_CONFIG[QEMU_SYSTEM_X86_64_BIN]}"
# Add VM configuration options
QEMU_CMD+=" --enable-kvm"
QEMU_CMD+=" -drive driver=raw,file=${VM_CONFIG[IMG_PATH]},if=virtio -m 6144"
QEMU_CMD+=" -net nic,model=virtio"
QEMU_CMD+=" -net user"
QEMU_CMD+=" -cdrom ${VM_CONFIG[WIN10_ISO_PATH]}"
QEMU_CMD+=" -drive file=${VM_CONFIG[VIRTIO_WIN_ISO_PATH]},index=3,media=cdrom"
QEMU_CMD+=" -rtc base=localtime,clock=host"
QEMU_CMD+=" -smp cores=4,threads=8"
QEMU_CMD+=" -usb"
QEMU_CMD+=" -device usb-tablet"
QEMU_CMD+=" -net user,smb=${HOME}"
# Execute QEMU command
echo "Starting VM..."
echo "$QEMU_CMD"
"$QEMU_CMD" &
# TODO: Implement VM shutdown on exit
QEMU Command Breakdown
This is a QEMU system command that sets up a virtual machine (VM) environment. Here's a breakdown of the command:
WINIMG
: Path to the Windows 10 ISO file (~/vm/Win10_1803_English_x64.iso
)VIRTIMG
: Path to the VirtIO ISO file (~/vm/virtio-win-0.1.149.iso
)--enable-kvm
: Enables KVM acceleration-drive
: Specifies a drive to attach to the VM
driver=raw
: Drives are raw filesfile=~/vm/win10.img
: Points to the disk image file (win10.img
)if=virtio
: Uses VirtIO interface-m
: Allocates 6144 MB of memory to the VM-net nic,model=virtio
: Configures a VirtIO network interface-net user
: Enables user-mode networking-cdrom ${WINIMG}
: Attaches the Windows 10 ISO file as a CD-ROM drive-drive file=${VIRTIMG},index=3,media=cdrom
: Attaches the VirtIO ISO file as a CD-ROM drive (index 3)-rtc base=localtime,clock=host
: Synchronizes the VM's clock with the host system's clock-smp cores=4,threads=8
: Configures the VM to use 4 cores and 8 threads-usb
: Enables USB support-device usb-tablet
: Attaches a USB tablet device-net user,smb=$HOME
: Maps the host's $HOME
directory to a SMB share in the VMThis command sets up a Windows 10 VM with VirtIO drivers and networking, and configures various device settings.