Create a KVM guest

From LSDevLinux
Revision as of 12:07, 21 January 2010 by Mayhewn (talk | contribs) (Categorize)

Jump to: navigation, search

These steps will create a KVM Ubuntu Server JeOS 9.04 Jaunty machine.

"host" is the machine hosting the guest. MACHINE the hostname of the guest.

Prepare host

  • Install packages:
$ sudo aptitude install kvm virt-manager
  • Download the Ubuntu Server 9.04 ISO image from
  • Set up bridging on your workstation:

Assuming you have an "auto eth0" in /etc/network/interfaces, append to that file

auto br0
iface br0 inet dhcp
  bridge_ports eth0

This creates a bridge that your guests can join to access the external network through eth0. (I assume this is what is happening.)

host:$ sudo /etc/init.d/networking restart

Create guest

  • In Virtual Machine Manager, click the "localhost (System)", and click New. Name the virtual machine as $MACHINE. Use Fully virtualized. Select CPU architecture. Choose ISO to install from. Storage should be a File. Set size to around 50GiB but don't pre-allocate. Click Shared physical device, and choose "eth0 (Bridge br0)". Set Max and Startup memory to 1024MiB. Let it boot into the Ubuntu Server ISO install CD.
  • On the Ubuntu Server boot menu, press F4 and choose "Install a minimal virtual machine". Choose Install Ubuntu Server. Choose English, Canada, select the USA keyboard, enter hostname as $MACHINE, select Mountain time zone. In the Partition disks window, choose Manual partitioning, and make an ext4 slash partition to use the entire disk, set it reserve 0% of the filesystem for super-user, set slash bootable flag on, and don't make any swap partition. Name the user "boss", and give him a password. Don't encrypt your home directory. For proxy enter something like "". Choose "Install security updates automatically". In the Software selection window, select "OpenSSH server". Reboot after installation and log in as "boss". At this point the VM image is 1.3GiB, and the guest itself reports 530MiB used. (This is a JeOS, not the full Ubuntu Server, which probably impacts that.)

Configure guest

  • Apply all security and bug-fix updates to date:
$ sudo aptitude update
$ sudo aptitude safe-upgrade
  • Set guest to start at host boot: In the "$MACHINE Virtual Machine" window, with the Console tab that lets you see your guest's console, click the Hardware tab, click Build Options, select "Start virtual machine on host boot up", and click Apply.
  • Configure dhclient to register itself by name with our dhcp server to enable looking up this guest's IP by name.

$ sudo aptitude install vim Determine MAC address using ifconfig (look for HWaddr). Edit /etc/dhcp3/dhclient.conf and put $MACHINE into the line: send host-name "<hostname>"; Then insert the 2 lines:

send dhcp-client-identifier <YOUR MAC ADDR>;
append domain-name "";
guest:$ sudo /etc/init.d/networking restart
  • Enable authentication from the host's user, and start manipulating the system from ssh:
host:$ ssh-copy-id boss@$MACHINE
host:$ ssh boss@$MACHINE
  • Set up swap:
$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 # 1GiB
$ sudo chmod 600 /swapfile # Protect memory from being read
$ sudo mkswap /swapfile
$ sudo swapon /swapfile

Append to /etc/fstab :

/swapfile none swap sw 0 0
  • Optionally enable passwordless sudo:
$ sudo visudo

Append the 2 lines:

# Enable passwordless sudo for all admins
  • Set up others to be able to authenticate:
theiruser@their-workstation:$ ssh-copy-id boss@$MACHINE
  • Optionally install packages to make a FieldWorks build node

Mono build dependencies:

$ sudo aptitude install bison mono-devel

FieldWorks build dependencies:

$ sudo aptitude install build-essential tofrodos unixodbc-dev libgtkmm-2.4-dev \
  uuid-dev libmagick++-dev mono-1.0-devel libmono-winforms1.0-cil \
  libgraphite-dev mono-gmcs libmono-winforms2.0-cil firebird2.0-dev \
  g++ automake mono-2.0-devel gawk libtool gtk-sharp2 libmono-cairo2.0-cil \
  libenchant-dev subversion xutils-dev libmono-dev
$ sudo aptitude install openjdk-6-jre

Other things for building or tools:

$ sudo aptitude install xserver-xephyr xvfb metacity subversion-tools links2 git-core gdb wget

Perforce client:

$ cd /usr/local/bin
$ sudo wget ''
$ sudo chmod +x p4
  • Host reports guest image at 2.6GiB. Guest reports slash usage at 1.8GiB.
  • Reboot guest to use new kernel and verify system returns to a good state after rebooting.