<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>Fun with ones and zeros - kvm</title>
<description><![CDATA[Barry's notes on computer software and hardware]]></description>
<link>/blog/tags/kvm</link>
<lastBuildDate>Wed, 20 May 2026 03:46:46 -0700</lastBuildDate>
<item>
<title>VM Serial Console part 2</title>
<link>/blog/entries/vm-serial-console-part-2</link>
<pubDate>Wed, 09 Nov 2011 08:18:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>Fooling around a bit more with accessing a VM's serial console from a KVM hypervisor with</p>
<pre><code>virsh console mymachine</code></pre>
<p>I found one thing that doesn't carry over from the host to the VM is the terminal window size, so if you try to use something like <code>vim</code> through the console connection, it seems to assume a 80x25 or so window, and when <code>vim</code> exits your console is all screwed up.</p>
<p>It looks like a serial connection doesn't have an out-of-band way of passing that info the way telnet or ssh does, so you have set it manually.   You can discover your settings on the host machine with</p>
<pre><code>stty size</code></pre>
<p>which should show something like:</p>
<pre><code>60 142</code></pre>
<p>on the VM, the same command probably shows</p>
<pre><code>0 0</code></pre>
<p>zero rows and columns, no wonder it's confused.  Fix it by setting the VM to have the same rows and columns as the host with something like:</p>
<pre><code>stty rows 60 columns 142</code></pre>
<p>and you're in business.</p>]]></description>
</item>
<item>
<title>Enabling VM serial console on stock Ubuntu 10.04 server</title>
<link>/blog/entries/enabling-serial-console-stock-ubuntu-1004-server</link>
<pubDate>Wed, 02 Nov 2011 07:00:00 -0700</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>So I've been running Ubuntu 10.04 server virtual machines on a host running KVM as the hypervisor, and thought I should take a look at accessing the VM's console from the host, in case there's a problem with the networking on the VM.</p>
<p>The hosts's VM libvirt definition shows a serial port and console defined with</p>
<pre><code>&lt;serial type='pty'&gt;
  &lt;source path='/dev/pts/1'/&gt;
  &lt;target port='0'/&gt;
  &lt;alias name='serial0'/&gt;
&lt;/serial&gt;
&lt;console type='pty' tty='/dev/pts/1'&gt;
  &lt;source path='/dev/pts/1'/&gt;
  &lt;target type='serial' port='0'/&gt;
  &lt;alias name='serial0'/&gt;
&lt;/console&gt;</code></pre>
<p>and within the stock Ubuntu 10.04 server VM, <code>dmesg | grep ttyS0</code> shows:</p>
<pre><code>[    0.174722] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[    0.175027] 00:05: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A</code></pre>
<p>So the virtual hardware is all setup on both ends, but <code>ps aux | grep ttyS0</code> doesn't show anything</p>
<p>We need to have a process listening to that port.  To do that, create a file named <code>/etc/init/ttyS0.conf</code> with these contents:</p>
<pre><code># ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -L 38400 ttyS0 xterm-color</code></pre>
<p>and then run</p>
<pre><code>initctl start ttyS0</code></pre>
<p>back in the host machine run <code>virsh list</code> to find the name or id number of your VM, and then </p>
<pre><code>virsh console &lt;your-vm-name-or-number&gt;</code></pre>
<p>to connect, hit return and you should see a login prompt.</p>]]></description>
</item>
<item>
<title>Customizing cloned Ubuntu VMs</title>
<link>/blog/entries/customizing-cloned-ubuntu-vms</link>
<pubDate>Sun, 30 Oct 2011 18:53:00 -0700</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<body><p>I was playing with creating and cloning Ubuntu virtual machines the other day, and got to the point where I had a nicely setup reference image that I could just copy to fire up additional VMs that would be in a pretty usable state.</p>
<p>There are a few things within a cloned VM that you'd want to change if you were going to keep the new instance around, such as the hostname, SSH host keys, and disk UUIDs.  I threw together a simple shell script to take care of these things automatically.</p>
<div class="source"><pre><span></span><span class="ch">#!/bin/sh</span>
<span class="c1">#</span>
<span class="c1"># Updates for cloned Ubuntu VM</span>
<span class="c1">#</span>

<span class="c1">#</span>
<span class="c1"># Some initial settings cloned from the master</span>
<span class="c1">#</span>
<span class="nv">ROOT</span><span class="o">=</span>/dev/vda1
<span class="nv">SWAP</span><span class="o">=</span>/dev/vdb1
<span class="nv">LONG_HOSTNAME</span><span class="o">=</span>ubuntu.local
<span class="nv">SHORT_HOSTNAME</span><span class="o">=</span>ubuntu

<span class="k">if</span> <span class="o">[</span> -z <span class="nv">$1</span> <span class="o">]</span>
<span class="k">then</span>
    <span class="nb">echo</span> <span class="s2">"Usage: </span><span class="nv">$0</span><span class="s2"> &lt;new-hostname&gt;"</span>
    <span class="nb">exit</span> <span class="m">1</span>
<span class="k">fi</span>

<span class="c1"># </span>
<span class="c1"># Update hostname</span>
<span class="c1">#</span>
<span class="nv">shorthost</span><span class="o">=</span><span class="sb">`</span><span class="nb">echo</span> <span class="nv">$1</span> <span class="p">|</span> cut -d . -f <span class="m">1</span><span class="sb">`</span>
<span class="nb">echo</span> <span class="nv">$1</span> &gt;/etc/hostname
hostname <span class="nv">$1</span>
sed -i -e <span class="s2">"s/</span><span class="nv">$LONG_HOSTNAME</span><span class="s2">/</span><span class="nv">$1</span><span class="s2">/g"</span> /etc/hosts
sed -i -e <span class="s2">"s/</span><span class="nv">$SHORT_HOSTNAME</span><span class="s2">/</span><span class="nv">$shorthost</span><span class="s2">/g"</span> /etc/hosts

<span class="c1">#</span>
<span class="c1"># Generate new SSH host keys</span>
<span class="c1">#</span>
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server

<span class="c1">#</span>
<span class="c1"># Change root partition UUID</span>
<span class="c1">#</span>
<span class="nv">OLD_UUID</span><span class="o">=</span><span class="sb">`</span>blkid -o value <span class="nv">$ROOT</span> <span class="p">|</span> head -n <span class="m">1</span><span class="sb">`</span>
<span class="nv">NEW_UUID</span><span class="o">=</span><span class="sb">`</span>uuidgen<span class="sb">`</span>
tune2fs -U <span class="nv">$NEW_UUID</span> <span class="nv">$ROOT</span>
sed -i -e <span class="s2">"s/</span><span class="nv">$OLD_UUID</span><span class="s2">/</span><span class="nv">$NEW_UUID</span><span class="s2">/g"</span> /etc/fstab /boot/grub/grub.cfg

<span class="c1">#</span>
<span class="c1"># Change swap partition UUID</span>
<span class="c1">#</span>
<span class="nv">OLD_UUID</span><span class="o">=</span><span class="sb">`</span>blkid -o value <span class="nv">$SWAP</span> <span class="p">|</span> head -n <span class="m">1</span><span class="sb">`</span>
<span class="nv">NEW_UUID</span><span class="o">=</span><span class="sb">`</span>uuidgen<span class="sb">`</span>
swapoff <span class="nv">$SWAP</span>
mkswap -U <span class="nv">$NEW_UUID</span> <span class="nv">$SWAP</span>
swapon <span class="nv">$SWAP</span>
sed -i -e <span class="s2">"s/</span><span class="nv">$OLD_UUID</span><span class="s2">/</span><span class="nv">$NEW_UUID</span><span class="s2">/g"</span> /etc/fstab

<span class="c1">#</span>
<span class="c1"># Remove udev lines forcing new MAC address to probably show up as eth1</span>
<span class="c1">#</span>
sed -i -e <span class="s2">"/PCI device/d"</span>     /etc/udev/rules.d/70-persistent-net.rules
sed -i -e <span class="s2">"/SUBSYSTEM==/d"</span> /etc/udev/rules.d/70-persistent-net.rules

<span class="nb">echo</span> <span class="s2">"UUID and hostname updated, udev nic lines removed,  be sure to reboot"</span>
</pre></div>
<p>I'd then run it on the cloned machine with something like</p>
<pre><code>update_clone.sh mynewmachine.foobar.com</code></pre>
<p>This somewhat particular to my specific master VM, in that it's expecting one disk dedicated to root and one disk dedicated to swap, and the VM was created with <code>ubuntu.local</code> as the hostname.  Hopefully though it'll give some ideas about what to look for and how to script those changes.</p></body>]]></description>
</item>
<item>
<title>Make sure virtualization is enabled in the BIOS</title>
<link>/blog/entries/make-sure-virtualization-enabled-bios</link>
<pubDate>Thu, 13 Oct 2011 13:24:53 -0700</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>I just wasted a fair amount of time on a RedHat 6.1 box being setup to be a hypervisor with KVM, trying to figure how why when I ran <code>virsh version</code> it was telling me among other things</p>
<pre><code>internal error Cannot find suitable emulator for x86_64
</code></pre>
<p>All the appropriate packages such as qemu-kvm were installed, but it just didn't seem to want to work.   Finally as I was about to try reinstalling RHEL, I remoted into the actual console and saw:</p>
<pre><code>kvm: disabled by bios
</code></pre>
<p>Doh!, and looking back in <code>/var/log/messages</code> the same thing was buried deep within all the boot noise.  While trying to figure this out I managed to just be looking for <code>virt</code> or <code>qemu</code> in the logs and somehow didn't search for <code>kvm</code>.   Enabled virtualization in the BIOS and everything's gravy now.</p>
<p>So there you go, if you're Googling that first error message and get lots of other nonsense, look for the message about the BIOS.</p>]]></description>
</item>
<item>
<title>KVM Networking</title>
<link>/blog/entries/kvm-networking</link>
<pubDate>Fri, 05 Dec 2008 07:16:45 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[
<p>Still playing with KVM (Kernel-based Virtual Machine), this time checking out some networking features.  I've been running Ubuntu 8.04 LTS Server (Hardy Heron), both as the host and as a VM on that host.  Networking is setup to use a bridge.  <br />
</p>
<p>KVM offers different emulated NICs, I took a quick look at running <code>iperf</code> between the VM and the host, and got these speeds for a few select NIC models:
</p>
<ul>
 <li>
     RTL-8139C+ (the default): ~210 Mb/sec
 </li>

 <li>
     Intel e1000 (somewhat recommended <a href="http://www.linux-kvm.com/content/how-do-you-use-e1000-option-windows-guest">here</a>): ~ 330Mb/sec
 </li>

 <li>
     virtio: ~ 700Mb/sec
 </li>
</ul>
<p>The thing about virtio though is that it doesn't work when the VMs RAM is set to 4GB.  So I guess you can have fast networking, or lots of memory, but not both.
</p>


]]></description>
</item>
</channel>
</rss>