Installing LXC with Libvirt and Dnsmasq in Debian

  1. Configure a domain mapping for your new container in dnsmasq (/etc/dnsmasq.d/<vmname>.conf)
    local=/<domain>/
    address=/<domain>/192.168.122.2
  2. Install lxc and libvirt
    apt-get update
    apt-get install lxc libvirt-bin
  3. Create a container
    lxc-create -n vm1 -t debian — -r jessie
    # note the password given to the new root user
  4. Start the virtual machine
    lxc-start -n vm1
  5. At the login promt login as root and enter the password of the new root user
  6. Change the root password
  7. Create a user and install sudo
    apt-get install sudo
    adduser <you-user> sudo
    # remember the password you gave here
  8. Edit the networking section in /var/lib/lxc/vm1/config to look like this:
    lxc.network.type = veth
    lxc.network.flags = up
    lxc.network.link = virbr0
    lxc.network.hwaddr = 00:FF:AA:00:00:01
    lxc.network.ipv4 = 192.168.122.2/24
    # You might need to change the IP.
  9. Start the libvirt network:
    virsh net-start default
  10. SSH to the VM:
    ssh <your-user>@<domain>
  11. Have fun…
  12. For shutdown try:
    halt; poweroff