Run virtual machines on a laptop

Last edited
The use of virtual machines is an awsome way of doing things.

Multiple solutions to run virtual machines on your laptop

Linux offers more then one way to run virtual machines on your laptop. Here are the ones I prefer:

  • kvm
    KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware. In order to run kvm the processor has to support virtualization extensions (Intel VT or AMD-V). The BIOS of your laptop must make this extension available to your system.
  • openvz
    OpenVZ is container-based virtualization for Linux.
  • LXC Linux Containers
    LXC Linux Containers is container-based virtualization for Linux and is part of the standard kernel.

Running virtual machines on a laptop is not allways easy. This is because the wireless network interface often fails to become a bridge.

Here is how I do it.

KVM with VDE

kvm banner

The following examples are based on these presumptions:

  • home network: range
  • ip-number of the laptop:
  • ip-number of the kvm virtual machines: in the range

Use the virtual switch VDE. I run the following script before starting kvm virtual machines:


modprobe kvm_intel
modprobe tun

vde_switch -tap tap0 -d

ifconfig tap0

echo "1" > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

This script is run as root on the laptop (the host). In the last line of the script wlan0 is used. This is the network-interface of my laptop.

After this, as a user I start the kvm virtual machine with the following command:

sudo vdeq kvm -net nic -net vde,vlan=0 <name-of-image> -m 512

Inside the virtual machine, choose an ip-address in the range and set the gateway to

Example 1: setting the virtual machine to

In the kvm virtual machine do as root:

ifconfig eth0 up
route add default gw

The address of the nameserver in /etc/resolv.conf can be your "normal" nameserver.

This way the kvm virtual machines have a link to the outside world. This means you can do a netinstall this way or do something like an apt-get update && apt-get upgrade.

From the laptop (the host) there is a network-connection to the virtual machines (so pointing your webbrowser to on your laptop will show the website on the webserver of the virtual machine off example 1 above).

Other machines on the network can't connect to the virtual machine without adding a routing. This can be added in the following way:

route add -net netmask gw <ip-number of the laptop (host)>

Do this on other machines in your network in order to reach your kvm virtual machines in the ip-range on your laptop.

Multiple kvm virtual machines

In order to run multiple virtual machines ,the machines do have to have different mac addresses. It is easy to change the mac address of a virtual machine.

In the kvm virtual machine do the following:

ifconfig eth0 down
ifconfig eth0 hw ether <mac-address>
ifconfig eth0 up

When everything works, put the mac address in the network startup script to make the change permanent (in Debian, this is in /etc/network/interfaces).

When starting multiple kvm virtual machines this way, they have a network-connection to each other. So this way you can test some kind of client-server model with two kvm virtual machines.

Running openvz on a laptop

openvz banner

It is fascinating that networking with openvz works right out the box. When you give your openvz virtual machine an ip address in your "normal" network range, then both from your laptop (the host) as well as from other machines in the network (and within the same range) the openvz virtual machine can be accessed.

Running LXC Linux Containers on a laptop

LXC Linux Containers are also great on a laptop. See the Running LXC Linux Containers on a laptop page.

Last updated: $Date: 2010-12-17 18:35:01 $