Skip to content

Basic VM

Create the HDD.

qemu-img create -f raw centos.raw 20G

Launch the VM.

qemu-system-x86_64 -m 2G -enable-kvm -hda centos.raw -cdrom centos.iso -boot d

CTRL + ALT + G Release input.

qemu-system-x86_64 \
    -parallel none \
    -serial none \
    -enable-kvm \
    -m 4G \
    -cpu host \
    -smp 4,sockets=1,cores=2,threads=2 \
    -hda centos.raw \
    -cdrom centos.iso \
    -boot d

Launch the VM.

qemu-system-x86_64 \
    -nographic \
    -vga none \
    -parallel none \
    -serial none \
    -enable-kvm \
    -m 4G \
    -cpu host,kvm=off,hv_relaxed,hv_spinlocks=0x1fff,hv_time,hv_vapic,hv_vendor_id=0xDEADBEEFFF \
    -rtc clock=host,base=localtime \
    -smp 4,sockets=1,cores=2,threads=2 \
    -device virtio-scsi-pci,id=scsi0 \
    -drive id=rootfs,file=$HDD,id=disk,format=raw,if=none \
    -device scsi-hd,bus=scsi0.0,drive=rootfs \
    -net nic,macaddr=e0:d5:5e:65:a3:02 -net vde,sock=/tmp/switch1 \
    -vga qxl \
    -spice unix,addr=$1,disable-ticketing \
    -device virtio-serial-pci \
    -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
    -chardev spicevmc,id=spicechannel0,name=vdagent \
    -boot order=dc

Share a directory

The shared directory is /tmp/smb.

qemu-system-x86_64 \
    -enable-kvm \
    -m 4G \
    -hda centos.raw \
    -cpu host \
    -smp 4,sockets=1,cores=2,threads=2 \
    -net nic \
    -net user,smb=/tmp/smb

Configuration file is located in /tmp/qemu-smb.XXXXXX/

vim /tmp/qemu-smb.*/smb.conf

Mount it in CentOS. The IP is always x.x.x.4. There is no username/password.

sudo yum install -y cifs-utils
sudo mount -t cifs //10.0.2.4/qemu /mnt -o gid=1000,uid=1000