QEMU / KVM How To Manually Create Basic Virtual Machine VM

1.) Create Image using qemu-img

qemu-img create -f qcow2 skype.img 40G

2.) Start VM using flags

-m = memory in MB

-drive file=yourimagefile.img

-cdrom /path/to/the.iso

qemu-system-x86_64 -m 4096 -drive file=skype.img -cdrom ~/Downloads/SfB-E-9319.0-enUS.ISO
 

Enable Bridged Networking

First of all you need a bridged NIC, see this post on how to do that.

If you get this message it basically / usually means you have no networking eg. no NIC or it is not connected to anything.

qemu-system-x86_64: warning: vlan 0 is not connected to host network

Take the same qemu-system command from earlier one and add this:

The below assumes you have a bridged tap adapter called "tap2019".  You will also need to bring the tap adapter up:

ip link set dev tap2019 up

qemu-system-x86_64 -m 4096 -drive file=skype.img -cdrom ~/Downloads/SfB-E-9319.0-enUS.ISO -net nic,model=virtio -net tap,ifname=tap2019,script=no,downscript=no


You can change the model=virtio to something else like Intel's e1000.  The ifname=tap2019 is obviously going to be set to the tap device you have.

 

Nice Script To Tie Basic QEMU-KVM Usage Together:

tapdev=`tunctl -b`
macaddr=`openssl rand -hex 6 | sed 's/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1:\2:\3:\4:\5:\6/'`
iso=/mnt/vms/iso/linuxmint-19.1-mate-64bit.iso
drive="-drive somefile.img,if=virtio"
ram=4096
cores=8
qemubin="/usr/libexec/qemu-kvm"
vncport=5
cdrom="-cdrom $iso"
$qemubin -smp $cores $cdrom -boot once=d  -vnc :$vncport -m $ram $drive -net nic,macaddr=$macaddr,model=virtio -net tap,ifname=$tapdev,script=no,downscript=no&
ifconfig $tapdev up
#or
#brctl addif br0 $tapdev

# proxy arp only needed if you are not using a bridge

# if not using a bridge you need proxy_arp AND you need to do add the route of the VMs IP to the tapdev eg. ip route add 10.10.25.20 dev tap20194
echo 1 > /proc/sys/net/ipv4/conf/$tapdev/proxy_arp

tapdev= name of your tap device

tunctl -t $tapdev creates this device

iso= path of your iso

ram= ram in megabytes

cores=8 how many SMP/processors the VM gets

qemubin= the path to your qemu binary

vncport= your port number a number of 5 means port 5905

cdrom= the $iso is the path to the iso you specified above

the actual execution of the script is somewhat dynamic.  For example if you don't specifiy "$drive" in the command line there won't be any hard disk (useful for livecds).  Or commenting it out as shown above achieves the same result.
 

The "ifconfig" part actually puts up the tap device or is kind of the equivalent of plugging in a cable to the virtual NIC on the VM.

The echo 1 to proxy_arp makes it so your tap device can broadcast and receive arp requests.  This way you can assign any IP to it and have it work.

Now the caveat not listed here which is very important is the routing.

You need to statically assign an IP to your VM and then add the routing (assuming you don't have a bridge which in this case brctl add if br0 $tapdev will automatically make the route work

If you don't have a bridge then you will need to do a "ip route add yourip dev yournic"

This will need to be done each time you start the VM or restart the host machine.


Tags:

qemu, kvm, manually, virtual, vm, img, qcow, skype, flags, mb, yourimagefile, cdrom, iso, _, downloads, sfb, enus,

Latest Articles

  • Linux qemu-kvm How To Enable Soundcard in Guestl
  • QEMU-KVM Windows and Server Guest Installs Mouse Tracking Pointer Location Solution
  • SSH Keep Alive To stop Disconnections
  • Linux How To Disable SATA NCQ For Better Performance
  • the sign-in method you're trying to use isn't allowed. For more info, contact your network administrator - solution for active directory
  • gsmartcontrol for Windows to Check the SMART S.M.A.R.T status
  • WebRTC Vulnerability Shows Local IP Address Even When Using a Proxy or VPN Firefox Fix And Disable Solution
  • chroot in Linux Howto Simple and Easy Guide
  • qemu-kvm qemu-system Image format was not specified for '/mnt/space/cucm12.img' and probing guessed raw. Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted. Specify the 'ra
  • Linux Over VNC VMWare How To Switch Virtual Terminals Console Without Using Ctrl+Alt+F1
  • Skype For Business 2015 and 2019 Guide, Reference, Howto and Troubleshooting Solutions
  • Centos 6 or 7 no DHCP IP during startup on first boot or reboot solution
  • Debian / Mint / Ubuntu net-tools packages provides netstat, ifconfig, route, arp and other classic network admin tools
  • Linux Mint XWindows Ubuntu MATE or Cinnamon How To Restart The GUI / Graphics / Session if it freezes without losing current windows or programs
  • Linux bash prompt why does it not show username@host and the current directory?
  • Microsoft SQL Server Check What Version is Running
  • How to install and setup LXC Containers (OpenVZ alternative) on Centos 6 / 7
  • Cisco CUCM Unified Communication Manager Howto Guide and Tutorials
  • SSH persistent and automatic login script for proxy
  • SSH proxy/command in the background or from cron script