netneo I use VirtualBox on Windows machines at work, but on my Linux laptop, I've switched to QEMU.
Here is the script I use to start my VM, in case it could help you get started more easily with QEMU:
`#!/bin/sh
VM_DIR=/home/wrk/vm
ISO_DIR=/local/share/iso
SHARED_DIR=${VM_DIR}/shared-dir
DISK_FMT=qcow2
DEFAULT_DISK_SIZE=16
DEFAULT_MEM_SIZE=2560
DEFAULT_CPU_NBR=2
vmImage=
isoImage=
diskSize=
memSize=
cpuCount=
showUsage=
showList=
showIso=
if [ ! -d "${VM_DIR}" ]; then
mkdir -p ${VM_DIR}
fi
if [ ! -d "${VM_DIR}" ]; then
echo "FATAL: Failed to create directory ${VM_DIR}" 1>&2
exit 1
fi
daemonRuns() {
if [ -n "$(ps ax | grep $1 | grep -v grep)" ]; then
return 0
fi
return 1
}
getIsoPath() {
local isoPath="$1"
if [ "$(expr substr "${isoPath}" 1 1)" != '/' ]; then
isoPath="${ISO_DIR}/${isoPath}"
fi
if [ "$(expr substr "${isoPath}" $(expr $(expr length "${isoPath}") - 3) 4)" != '.iso' ]; then
isoPath="${isoPath}.iso"
fi
echo -n "${isoPath}"
}
getImagePath() {
local imgPath="${VM_DIR}/$1"
if [ -n "$DISK_FMT" ]; then
imgPath="${imgPath}.${DISK_FMT}"
fi
echo -n "${imgPath}"
}
getImageCfg() {
echo -n "${VM_DIR}/$1.cfg"
}
startVM_qemu() {
local vmName="$1"
local ramSize="$2"
local cpuNbr="$3"
local vmSize="$4"
local isoPath="$5"
local vmPath="$(getImagePath "${vmName}")"
local qemuOptions="${qemuOptions} \
-name ${vmName} \
-smp ${cpuNbr} \
-m ${ramSize} \
-hda ${vmPath}"
# OS-specific options
case $(uname -s) in
Linux)
qemuOptions="${qemuOptions} \
-enable-kvm"
;;
esac
# Use most recent hardware (2009) as machine type.
# Enable all CPU features available on current host.
qemuOptions="${qemuOptions} \
-machine q35 \
-cpu max"
# Configure display adapter.
# -display gtk has a VM control menu, not sdl.
# VGA 16:9 => -device virtio-vga,virgl=on,xres=1280,yres=720
# Non-VGA 16:9 => -device virtio-gpu,virgl=on,xres=1920,yres=1080
qemuOptions="${qemuOptions} \
-display gtk,gl=on \
-device virtio-vga,virgl=on,xres=1280,yres=720"
# Configure network adapter.
qemuOptions="${qemuOptions} \
-nic user,ipv6=off,model=virtio-net-pci"
# Configure sound hardware.
qemuOptions="${qemuOptions} \
-audiodev id=pa,driver=pa \
-device ich9-intel-hda -device hda-micro,audiodev=pa"
# Add USB support.
qemuOptions="${qemuOptions} \
-usb"
# Configure mouse.
qemuOptions="${qemuOptions} \
-device usb-mouse"
# Configure keyboard (Swiss French layout).
qemuOptions="${qemuOptions} \
-k fr_ch"
# Configure shared folder (only usable by Linux guests).
qemuOptions="${qemuOptions} \
-virtfs local,path=${SHARED_DIR},mount_tag=shared-dir,security_model=mapped-file,fmode=664,dmode=775"
if [ -n "${isoPath}" ]; then
# Create hard disk.
qemu-img create -f ${DISK_FMT} "${vmPath}" ${vmSize}G
cat <<EOF > $(getImageCfg "${vmName}")
memSize=${ramSize}
cpuCount=${cpuNbr}
EOF
Configure CDROM.
qemuOptions="${qemuOptions} \
-cdrom ${isoPath} \
-boot once=dc"
fi
qemu-system-x86_64 ${qemuOptions}
}
listISO() {
find ${ISO_DIR} -name '*.iso' -type f -printf '%f\n' | sed "s/.iso$//" | sort
}
listVM() {
find ${VM_DIR} -maxdepth 1 -name '*.cfg' -type f -printf '%f\n' | sed 's/.cfg$//' | sort
}
while [ -n "$1" ]; do
case "$1" in
--help | -h)
showUsage=yes
;;
--disk | -d)
shift
diskSize=$1
;;
--mem | -m)
shift
memSize=$1
;;
--cpu | -p)
shift
cpuCount=$1
;;
--iso | -i)
showIso=yes
;;
--list | -l)
showList=yes
;;
*)
if [ -z "${vmImage}" ]; then
vmImage="$1"
elif [ -z "${isoImage}" ]; then
isoImage="$(getIsoPath "$1")"
else
echo "WARNING: Ignoring unknown option $1" >&2
fi
;;
esac
shift
done
if [ -n "${isoImage}" -a ! -f "${isoImage}" ]; then
echo "ERROR: ISO image does not exist (${isoImage})" >&2
showUsage=yes
fi
if [ -z "${vmImage}" ]; then
if [ -z "${showList}${showIso}" ]; then
echo "ERROR: VM name must be specified" >&2
showUsage=yes
fi
elif [ -z "${isoImage}" -a ! -f "$(getImagePath "${vmImage}")" ]; then
echo "ERROR: VM does not exist (${vmImage})" >&2
showUsage=yes
fi
if [ -z "${showUsage}" ]; then
if [ -n "${showList}" ]; then
listVM
elif [ -n "${showIso}" ]; then
listISO
else
imageCfg="$(getImageCfg "${vmImage}")"
if [ -f "${imageCfg}" ]; then
. ${imageCfg}
fi
if [ -z "${diskSize}" ]; then
diskSize=${DEFAULT_DISK_SIZE}
fi
if [ -z "${memSize}" ]; then
memSize=${DEFAULT_MEM_SIZE}
fi
if [ -z "${cpuCount}" ]; then
cpuCount=${DEFAULT_CPU_NBR}
fi
if [ ! -d ${SHARED_DIR} ]; then
mkdir -p ${SHARED_DIR}
fi
startVM_qemu "${vmImage}" ${memSize} ${cpuCount} "${diskSize}" "${isoImage}"
fi
else
cat <<EOF
Usage:
$(basename "$0") [options1] VM_NAME
starts the specified VM.
$(basename "$0") [options1] [options2] VM_NAME ISO_IMAGE
creates the specified VM and boots the ISO image.
$(basename "$0") --iso / -i
lists available ISO images.
$(basename "$0") --list / -l
lists available VM.
$(basename "$0") --help / -h
displays this message.
options1 can be:
--mem / -m RAM_SIZE (in MB, default: ${DEFAULT_MEM_SIZE})
--cpu / -p CPU_NBR (default: ${DEFAULT_CPU_NBR})
options2 can be:
--disk / -d DISK_SIZE (in GB, default: ${DEFAULT_DISK_SIZE})
Notes:
- Options can be specified anywhere on the command line.
- VM disk images are created under ${VM_DIR}.
- VM disk images use the ${DISK_FMT} format.
Examples:
$(basename "$0") FreeBSD-12.1 FreeBSD-12.1-RELEASE-amd64-disc1.iso --disk 32
will create a 32G volume for the FreeBSD-12.1 VM and will boot the
./FreeBSD-12.1-RELEASE-amd64-disc1.iso ISO image for its installation.
$(basename "$0") FreeBSD-12.1
will run the FreeBSD-12.1 VM.
$(basename "$0") GhostBSD GhostBSD19.10.iso -m 2560 -p 4
will create a 16G volume for the GhostBSD VM and will boot the
GhostBSD19.10.iso ISO image using 2560 MB RAM and 4 CPU.
EOF
fi`