{"id":263,"date":"2009-07-20T12:33:23","date_gmt":"2009-07-20T19:33:23","guid":{"rendered":"http:\/\/www.actusa.net\/~stu\/blog\/?p=263"},"modified":"2009-07-20T22:56:49","modified_gmt":"2009-07-21T05:56:49","slug":"notes-from-my-kvm-kernel-virtual-machine-talk","status":"publish","type":"post","link":"https:\/\/www.stuartsheldon.org\/blog\/2009\/07\/notes-from-my-kvm-kernel-virtual-machine-talk\/","title":{"rendered":"Notes From My KVM (Kernel Virtual Machine) Talk."},"content":{"rendered":"<h2><em><strong>Notes From My KVM (Kernel Virtual Machine) Talk.<\/strong><\/em><\/h2>\n<p>First of all, thanks to all who attended the SCLug meeting on Saturday. I had fun talking with everyone there.<\/p>\n<p>I wanted to follow up with some written examples of the <a href=\"http:\/\/www.linux-kvm.org\" target=\"_blank\">KVM<\/a> command lines I demonstrated at the meeting. I know I seemed to go over this stuff kind of fast, so I wanted to elaborate a bit in text.<\/p>\n<p style=\"text-align: right;\"><!--more--><\/p>\n<h2><em><strong>Installing the Ubuntu packages:<\/strong><\/em><\/h2>\n<pre>stu@milo:~% sudo apt-get install kvm \\\r\n        uml-utilities \\\r\n        bridge-utils<\/pre>\n<h2><em><strong>Creating a disk image file.<\/strong><\/em><\/h2>\n<pre>stu@milo:~% qemu-img create \/home\/stu\/myhdisc.img 20G<\/pre>\n<p>This creates a hard disk image in my home directory named &#8220;myhdisc.img&#8221; that is 20Gbytes large.<\/p>\n<h2><em><strong>Booting a host off of an ISO image using SDL as your display.<\/strong><\/em><\/h2>\n<pre>stu@mio:~% kvm -m 512 -hda \/home\/stu\/myhdisc.img \\\r\n        -cdrom \/home\/stu\/ubuntu-install.iso -boot d \\\r\n        -net user -net nic \\\r\n        -daemonize<\/pre>\n<p>This starts a kvm guest with the following settings:<\/p>\n<ul>\n<li>It has 512Megs of Ram<\/li>\n<li>It&#8217;s hard drive is the drive image we created<\/li>\n<li>The ubuntu-install.iso file is mounted as the it&#8217;s CD drive<\/li>\n<li>It is using user mode networking<\/li>\n<li>It will be booting off it&#8217;s CD Rom<\/li>\n<li>It&#8217;s primary display will be an <a href=\"http:\/\/www.libsdl.org\/\" target=\"_blank\">SDL<\/a> window on the desktop<\/li>\n<\/ul>\n<p>This is by far, the easiest way to get your first virtual machine up. If you are running &#8220;X&#8221;, this is the easiest way to get started with KVM.<\/p>\n<h2><em><strong>Using VNC for your display.<\/strong><\/em><\/h2>\n<pre>stu@milo:~% kvm -m 512 -hda \/home\/stu\/myhdisc.img \\\r\n        -cdrom \/home\/stu\/ubuntu-install.iso -boot d \\\r\n        -vnc localhost:0 -usbdevice tablet \\\r\n        -net user -net nic \\\r\n        -daemonize<\/pre>\n<p>As you can see, we have added the additional settings &#8220;-vnc localhost:0 -usbdevice tablet&#8221; to our command. This uses a <a href=\"http:\/\/www.tightvnc.com\/\" target=\"_blank\">VNC<\/a> server instead of the SDL display used in the previous example. Note that we are specifying &#8220;localhost&#8221; as we do not want the server to allow every one to connect to it. You can also use 0:0 if you want to open it up to all hosts, but that probably is a bad idea.<\/p>\n<h2><em><strong>Setting up a bridged environment for your guests.<\/strong><\/em><\/h2>\n<p>Although user mode networking is much easier to setup, it has it&#8217;s limitations, the biggest of which is it doesn&#8217;t interact well on the network with other hosts. It&#8217;s great if all you are going to do is surf the web, or test out a new operating system, but it&#8217;s not good for much more.<\/p>\n<p>Some of these commands you will want to run as root, and some as your normal user. So to simplify things, I&#8217;ll put the sudo command in front of the stuff you need root access for. This should work on a Ubuntu based system running the default &#8220;Desktop&#8221; configuration.<\/p>\n<h2><em><strong>Here are the steps to setup your base bridging environment:<\/strong><\/em><\/h2>\n<pre>stu@milo:~% sudo \/etc\/init.d\/NetworkManager stop\r\n\r\nstu@milo:~% sudo \/etc\/init.d\/NetworkManager-Dispatcher stop\r\n\r\nstu@milo:~% sudo brctl addbr br0\r\n\r\nstu@milo:~% sudo pkill dhclient\r\n\r\nstu@milo:~% sudo ifconfig eth0 0.0.0.0\r\n\r\nstu@milo:~% sudo brctl addif br0 eth0\r\n\r\nstu@milo:~% sudo dhclient br0<\/pre>\n<p>If all goes well, you should have a bridge setup for this boot only. If you want to make it permanent, then go <a href=\"https:\/\/help.ubuntu.com\/community\/NetworkConnectionBridge\" target=\"_blank\">here<\/a> and read all about it.<\/p>\n<p>You will now need to create a tap adapter, and give your normal user account access to it. this is done with the tunctl program.<\/p>\n<h2><strong><em>Setting up your tap device:<\/em><\/strong><\/h2>\n<pre>stu@milo:~% sudo tunctl -u stu -t tap0<\/pre>\n<p>Now we are almost done. We need to create a script to add the tap adapter to the bridge that we created. Here is an example of my \/etc\/kvm-ifup-br0 script.<\/p>\n<h2><em><strong>The ifup script for kvm:<\/strong><\/em><\/h2>\n<pre>#!\/bin\/bash\r\nsudo \/sbin\/ifconfig $1 0.0.0.0 up\r\nsudo \/usr\/sbin\/brctl addif br0 $1\r\nexit 0<\/pre>\n<p>then, just make sure you change the rights on the file:<\/p>\n<pre>stu@milo:~% sudo chmod 755 \/etc\/kvm-ifup-br0<\/pre>\n<h2><em><strong>We are now ready to start the guest up in bridged network mode!<\/strong><\/em><\/h2>\n<pre>stu@milo:~% kvm -m 512 -hda \/home\/stu\/myhdisc.img \\\r\n        -cdrom \/home\/stu\/ubuntu-install.iso -boot d \\\r\n        -net nic,macaddr=52:54:00:12:55:01 \\\r\n        -net tap,ifname=tap0,script=\/etc\/kvm-ifup-br0 \\\r\n        -daemonize<\/pre>\n<p>If all your setttings are right, and you have your bridge and kvm-ifup file working correctly, your guest will come up on the network looking and acting like a regular host.<\/p>\n<p>Now, once you get your guest operating system installed, you can remove the &#8220;-cdrom \/home\/stu\/ubuntu-install.iso -boot d&#8221; settings and you will boot into your new guest system!<\/p>\n<p>I hope this helps those who were at the meeting, and ofcourse, it would be great if it helped someone googling that was struggling with kvm.<\/p>\n<p>&#8212; Stu<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notes From My KVM (Kernel Virtual Machine) Talk. First of all, thanks to all who attended the SCLug meeting on Saturday. I had fun talking with everyone there. I wanted to follow up with some written examples of the KVM command lines I demonstrated at the meeting. I know I seemed to go over this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,4,30,3],"tags":[45,44,48,28,47,46],"class_list":["post-263","post","type-post","status-publish","format-standard","hentry","category-desktop","category-linux","category-networking","category-open-source","tag-kernel-virtual-machine","tag-kvm","tag-lug-meeting","tag-presentation","tag-virtual","tag-virtual-machine"],"_links":{"self":[{"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/posts\/263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/comments?post=263"}],"version-history":[{"count":46,"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/posts\/263\/revisions"}],"predecessor-version":[{"id":309,"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/posts\/263\/revisions\/309"}],"wp:attachment":[{"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/media?parent=263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/categories?post=263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stuartsheldon.org\/blog\/wp-json\/wp\/v2\/tags?post=263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}