<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fun with ones and zeros - kvm</title>
<subtitle>Barry&#039;s notes on computer software and hardware</subtitle>
<link href="/blog/tags/kvm"></link>
<updated>2026-05-20T03:46:46-07:00</updated>
<id>urn:uuid:43f9ac9d-c3c2-30f1-99c9-f1ff1c7d9e60</id>
<entry>
<title>VM Serial Console part 2</title>
<link href="/blog/entries/vm-serial-console-part-2"></link>
<id>urn:uuid:429c9248-2eb6-4e8a-047f-27d91c681b95</id>
<updated>2011-11-09T08:18:00-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;p&gt;Fooling around a bit more with accessing a VM&#039;s serial console from a KVM hypervisor with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;virsh console mymachine&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I found one thing that doesn&#039;t carry over from the host to the VM is the terminal window size, so if you try to use something like &lt;code&gt;vim&lt;/code&gt; through the console connection, it seems to assume a 80x25 or so window, and when &lt;code&gt;vim&lt;/code&gt; exits your console is all screwed up.&lt;/p&gt;
&lt;p&gt;It looks like a serial connection doesn&#039;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&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;stty size&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which should show something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;60 142&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;on the VM, the same command probably shows&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0 0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;zero rows and columns, no wonder it&#039;s confused.  Fix it by setting the VM to have the same rows and columns as the host with something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;stty rows 60 columns 142&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and you&#039;re in business.&lt;/p&gt;</content>
</entry>
<entry>
<title>Enabling VM serial console on stock Ubuntu 10.04 server</title>
<link href="/blog/entries/enabling-serial-console-stock-ubuntu-1004-server"></link>
<id>urn:uuid:0036d502-6450-9bf9-cb33-0fb2436222f0</id>
<updated>2011-11-02T07:00:00-07:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;p&gt;So I&#039;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&#039;s console from the host, in case there&#039;s a problem with the networking on the VM.&lt;/p&gt;
&lt;p&gt;The hosts&#039;s VM libvirt definition shows a serial port and console defined with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;serial type=&#039;pty&#039;&amp;gt;
  &amp;lt;source path=&#039;/dev/pts/1&#039;/&amp;gt;
  &amp;lt;target port=&#039;0&#039;/&amp;gt;
  &amp;lt;alias name=&#039;serial0&#039;/&amp;gt;
&amp;lt;/serial&amp;gt;
&amp;lt;console type=&#039;pty&#039; tty=&#039;/dev/pts/1&#039;&amp;gt;
  &amp;lt;source path=&#039;/dev/pts/1&#039;/&amp;gt;
  &amp;lt;target type=&#039;serial&#039; port=&#039;0&#039;/&amp;gt;
  &amp;lt;alias name=&#039;serial0&#039;/&amp;gt;
&amp;lt;/console&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and within the stock Ubuntu 10.04 server VM, &lt;code&gt;dmesg | grep ttyS0&lt;/code&gt; shows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[    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&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So the virtual hardware is all setup on both ends, but &lt;code&gt;ps aux | grep ttyS0&lt;/code&gt; doesn&#039;t show anything&lt;/p&gt;
&lt;p&gt;We need to have a process listening to that port.  To do that, create a file named &lt;code&gt;/etc/init/ttyS0.conf&lt;/code&gt; with these contents:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# 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&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then run&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;initctl start ttyS0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;back in the host machine run &lt;code&gt;virsh list&lt;/code&gt; to find the name or id number of your VM, and then &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;virsh console &amp;lt;your-vm-name-or-number&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to connect, hit return and you should see a login prompt.&lt;/p&gt;</content>
</entry>
<entry>
<title>Customizing cloned Ubuntu VMs</title>
<link href="/blog/entries/customizing-cloned-ubuntu-vms"></link>
<id>urn:uuid:f011130c-8644-9afc-708f-ba48bf0fa2b0</id>
<updated>2011-10-30T18:53:00-07:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;body&gt;&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;There are a few things within a cloned VM that you&#039;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.&lt;/p&gt;
&lt;div class=&quot;source&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;ch&quot;&gt;#!/bin/sh&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Updates for cloned Ubuntu VM&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Some initial settings cloned from the master&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;ROOT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/dev/vda1
&lt;span class=&quot;nv&quot;&gt;SWAP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/dev/vdb1
&lt;span class=&quot;nv&quot;&gt;LONG_HOSTNAME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ubuntu.local
&lt;span class=&quot;nv&quot;&gt;SHORT_HOSTNAME&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;ubuntu

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

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

&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Generate new SSH host keys&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server

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

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

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

&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;UUID and hostname updated, udev nic lines removed,  be sure to reboot&quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I&#039;d then run it on the cloned machine with something like&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;update_clone.sh mynewmachine.foobar.com&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This somewhat particular to my specific master VM, in that it&#039;s expecting one disk dedicated to root and one disk dedicated to swap, and the VM was created with &lt;code&gt;ubuntu.local&lt;/code&gt; as the hostname.  Hopefully though it&#039;ll give some ideas about what to look for and how to script those changes.&lt;/p&gt;&lt;/body&gt;</content>
</entry>
<entry>
<title>Make sure virtualization is enabled in the BIOS</title>
<link href="/blog/entries/make-sure-virtualization-enabled-bios"></link>
<id>urn:uuid:b05d1931-96b4-3904-30cf-8fcfe497d93a</id>
<updated>2011-10-13T13:24:53-07:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;p&gt;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 &lt;code&gt;virsh version&lt;/code&gt; it was telling me among other things&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;internal error Cannot find suitable emulator for x86_64
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All the appropriate packages such as qemu-kvm were installed, but it just didn&#039;t seem to want to work.   Finally as I was about to try reinstalling RHEL, I remoted into the actual console and saw:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;kvm: disabled by bios
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Doh!, and looking back in &lt;code&gt;/var/log/messages&lt;/code&gt; the same thing was buried deep within all the boot noise.  While trying to figure this out I managed to just be looking for &lt;code&gt;virt&lt;/code&gt; or &lt;code&gt;qemu&lt;/code&gt; in the logs and somehow didn&#039;t search for &lt;code&gt;kvm&lt;/code&gt;.   Enabled virtualization in the BIOS and everything&#039;s gravy now.&lt;/p&gt;
&lt;p&gt;So there you go, if you&#039;re Googling that first error message and get lots of other nonsense, look for the message about the BIOS.&lt;/p&gt;</content>
</entry>
<entry>
<title>KVM Networking</title>
<link href="/blog/entries/kvm-networking"></link>
<id>urn:uuid:818eb3f7-adce-9780-81c9-498c672bac77</id>
<updated>2008-12-05T07:16:45-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">
&lt;p&gt;Still playing with KVM (Kernel-based Virtual Machine), this time checking out some networking features.  I&#039;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.  &lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;KVM offers different emulated NICs, I took a quick look at running &lt;code&gt;iperf&lt;/code&gt; between the VM and the host, and got these speeds for a few select NIC models:
&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
     RTL-8139C+ (the default): ~210 Mb/sec
 &lt;/li&gt;

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

 &lt;li&gt;
     virtio: ~ 700Mb/sec
 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The thing about virtio though is that it doesn&#039;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.
&lt;/p&gt;


</content>
</entry>
</feed>