<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cauldron Development LLC</title>
	<atom:link href="http://cauldrondevelopment.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://cauldrondevelopment.com/blog</link>
	<description>Notes on tech tasks</description>
	<lastBuildDate>Fri, 27 Jan 2012 21:36:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dear Congressperson, if you take my hamburger. . .</title>
		<link>http://cauldrondevelopment.com/blog/2012/01/18/84/</link>
		<comments>http://cauldrondevelopment.com/blog/2012/01/18/84/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 10:21:38 +0000</pubDate>
		<dc:creator>jcoffland</dc:creator>
				<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://cauldrondevelopment.com/blog/?p=84</guid>
		<description><![CDATA[Dear Congressperson:
If you take my hamburger, I go hungry but if you copy my software, music or movie we can both benefit from them, discuss them and share ideas and experiences which enhance our mutual ownership.  This may sound like a bunch of hippy communist bull but it is capitalism in it&#8217;s truest form.
It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Dear Congressperson:</p>
<p>If you take my hamburger, I go hungry but if you copy my software, music or movie we can both benefit from them, discuss them and share ideas and experiences which enhance our mutual ownership.  This may sound like a bunch of hippy communist bull but it is capitalism in it&#8217;s truest form.</p>
<p>It&#8217;s as simple as the law of supply and demand.  When supply goes up relative to demand, with out artificial influences, such as unnecessary laws, price goes down.  We can copy digital works all day long at almost no cost so their supply is essentially limitless.  According to this most basic law of economics, in an unencumbered capitalist system, the price of digital works will naturally tend towards zero.</p>
<p>We have been duped into believing that you can steal an idea.  What a farce.  What a complete and utter wrong turn for humanity.  All because we made the mistake of forcing concepts we understand in the physical world, like stealing, on to the relatively new world of digital works where they do not apply.  Our society has built an economy around marketing and selling products but we&#8217;re still trying to pound that square peg in to a round hole.  The natural laws of physical goods simply do not apply to digital works.  If we, as an intelligent society, want to maximize the value of our creations then, when it comes to digital works, we must maximize sharing.  We must fight for our basic right to share in the limitless possibility of a free world of free digital works, free ideas, free music, free software, free art.</p>
<p>Freedom does not mean that artists are not to be compensated.  They must be compensated for the act of creation.  Not for sharing the fruits of their labor but for the labor itself.  The business model has to change.  We cannot sell music or movies like widgets.  Artists must sell the act of creating as a service not the results as a product.  The music and movie industry has to be turned on its head.  There is no denying that it will be painful for some in the short term but it&#8217;s better than heading down the dark road of draconian enforcement which is the only end to the path we are currently on.</p>
<p>A free system is more beneficial to creators anyway.  On the Internet, there is nothing more valuable than attention and unhindered sharing is the best way to get it.  This applies to creators now not in some distant utopian future.  For creators today this is the best bet not a vague hope that to win the record industry lottery.  Tell these middle who are asking you to artificially prop up an outdated system, &#8220;I&#8217;m sorry, you had a good run, you made a lot of money but now you must go the way of the wagon wheel maker.&#8221;</p>
<p>I am 35 year old software developer.  Internet freedoms are extremely important to me and many of my generation.  I write and distribute software and my entire livelihood depends on what is ultimately a copyrightable digital work.  Yet I believe in free and open sharing.  The RIAA and MPAA need to change their tactics if they want to survive.  They are wrong not the public.  And their billions of dollars do not justify their position.</p>
<p>I will likely vote in the next elections based solely on your stance on issues of Internet privacy and freedom.</p>
<p>I beg you to <strong>strongly</strong> oppose SOPA and PIPA and any other legislation which attempts to limit freedom on the Internet and instead fight to reverse the damage that has already been done by laws like the DMCA!</p>
<p>Most earnestly your constituent,</p>
<p>Joseph Coffland</p>
]]></content:encoded>
			<wfw:commentRss>http://cauldrondevelopment.com/blog/2012/01/18/84/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A &#8220;real&#8221; Ikea Dioder hack</title>
		<link>http://cauldrondevelopment.com/blog/2009/12/29/a-real-ikea-dioder-hack/</link>
		<comments>http://cauldrondevelopment.com/blog/2009/12/29/a-real-ikea-dioder-hack/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 12:02:57 +0000</pubDate>
		<dc:creator>jcoffland</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Tech Notes]]></category>

		<guid isPermaLink="false">http://cauldrondevelopment.com/blog/?p=39</guid>
		<description><![CDATA[The other day I was walking around Ikea for some reason or another and I noticed this cool LED thing called the Dioder.  It consists of 4 strips of 9 bright RGB LEDs (a.k.a. pretty color changing lights) with a control box and a bunch of cabling allowing you to arrange the LED strips [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was walking around <a href="http://www.ikea.com/">Ikea</a> for some reason or another and I noticed this cool LED thing called the <a href="http://www.ikea.com/us/en/catalog/products/50119407">Dioder</a>.  It consists of 4 strips of 9 bright RGB LEDs (a.k.a. pretty color changing lights) with a control box and a bunch of cabling allowing you to arrange the LED strips in many different configurations.  The Dioder has three modes.  The first lets you cycle through some preset colors with the button.  The second will automatically cycle through these colors.  The third fades colors.  The lights are not individually addressable so they are all the same color at any given time.  The modes are selected by holding down a single button for different lengths of time while a buzzer beeps to let you know what mode you are in.  At $50 its a little expensive but I immediately thought it looked hackable so I bought one.</p>
<p>It sat around the house for several days as I debated what to do with it and waited for a bit of leisure time.  I knew I couldn&#8217;t just install it as intended.  That wouldn&#8217;t justify the $50.  So like any good hacker I did some googling to see what others had done.  I did find some &#8220;hacks&#8221; but they consisted of &#8220;hey look I put these lights on my TV&#8221; or &#8220;here they are in a box, isn&#8217;t this cool.&#8221;  I&#8217;m sorry, I may be a geek snob but using something pretty much the way it was intended is not a very cool hack.</p>
<p>So the debate went on.  I cracked the control module open by removing the four screws and found a fairly simple circuit.  It consists of three transistor pairs which drive the red, green and blue LED lines, a piezo buzzer, a button, a 5v regulator and a <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/41190c.pdf">12F629 PIC microcontroller</a>.  The circuit has only the three LED driver channels and that is why the LEDs are always the same color.  I thought about building separate RGB drivers for each of the for LED strips so I could get four colors at once but in the end I decided that building new drivers circuits from scratch would take much more time than I wanted to invest in this project.  Finally, I decided the simplest thing I could do, that was still &#8220;cool&#8221;, was to interface the controller with my computer to control the LEDs.  Anything is cool when it&#8217;s connect to your computer right?</p>
<p>Unfortunately the PIC 12F629 does not have a serial port so I decided to piggy back one of my favorite little microcontrollers on top of the PIC, the <a href="http://www.atmel.com/dyn/resources/prod_documents/DOC2543.PDF">ATTiny2313</a>.  This chip has plenty of IO lines, PWM, a serial port, is pretty easy to use and I happened to have some lying around and some prototyping boards already made up for them.  Here is a picture of the prototyping boards I use:</p>
<div style="text-align:center"><img src="/pub/dioder-hack/2313-Proto-Board.png" alt="Atmel 2313 prototyping board" /></div>
<p>The picture shows a populated proto board from the top on the left and an unpopulated board from the bottom on the right.  You may notice that the picture shows an AT90S2313.  This is the predecessor to the ATTiny2313 and is pin compatible.  I did end up going with the ATTiny2313 for this project.  Here is the schematic in <a href="http://www.cadsoft.de/">Eagle CAD</a> format and images so you can make your own proto boards:</p>
<div style="text-align:center"><a href="/pub/dioder-hack/at90s2313.png"><img width="200px" src="/pub/dioder-hack/at90s2313.png" alt="AVR prototyping board PCB image" /></a></div>
<ul>
<li><a href="/pub/dioder-hack/at90s2313-2X4.png">2&#215;4 array</a></li>
<li><a href="/pub/dioder-hack/at90s2313-4X4.png">4&#215;4 array</a></li>
<li><a href="/pub/dioder-hack/at90s2313.brd">Eagle CAD board</a></li>
</ul>
<p>These images should be printed at 600 DPI for correct sizing.  I used a laser printer press and peel type method to get the pattern on to copper clad boards and then etched them.  Google it and you will find plenty of information on this.</p>
<p>Something like this could also work instead: <a href="http://www.ecrater.com/product.php?pid=2028440">AVR ATMEL PROTOTYPE BOARD</a>.</p>
<p>The proto board is populated with the following:</p>
<ul>
<li>1 x 10Mhz crystal clock</li>
<li>2 x 22pF capacitors</li>
<li>1 x 1uF capacitor</li>
<li>1 x 6 pin dual row .1&#8243; pitch ISP for in circuit programming</li>
<li>1 x 4 pin right angle header for logic level serial port connection</li>
<li>1 x small jumper wire connecting the two extra holes from the microcontroller to the 6-pin ISP</li>
<li>1 x ATTiny2313 Micro controller. I recommend you also socket it in a 20-pin socket.</li>
</ul>
<p>In this project, I also added a single row right angle 8-pin .1&#8243; pitch header to connect to the Dioder and a matching female header socket.</p>
<p>Here is a picture of the soldered proto board from the bottom.</p>
<div style="text-align:center"><img src="/pub/dioder-hack/proto-bottom.png" alt="Proto board from bottom" /></div>
<p>You will notice the serial send and receive wires and a ground wire connected to the 8-pin single row header.  I also had to cut the trace connecting that ground pin to the microcontroller.</p>
<p>After soldering and testing the proto board I soldered 7 small wires on to the pins of the PIC12F629.  The wires were connected to all but pin 3 of the microcontroller.  The diagram below shows how the PIC&#8217;s pins are used in the Dioder:</p>
<div style="text-align:center"><img src="/pub/dioder-hack/Dioder-Pinouts.png" alt="Pin-out of PIC in Dioder" /></div>
<p>Pin 3 is not used and is just pulled to ground.</p>
<p>Below is a picture of the Dioder&#8217;s circuit with wires attached.  In this picture there is one wire too many (pin 3).</p>
<div style="text-align:center"><img src="/pub/dioder-hack/Dioder-With-Wires.png" alt="Dioder with wires attached" /></div>
<p>Here is a close up:</p>
<div style="text-align:center"><img src="/pub/dioder-hack/Dioder-With-Wires-Closeup.png" alt="Dioder with wires attached closeup" /></div>
<p>The glossy stuff is solder flux.  You might also notice that I scraped off the green coating from the trace coming from the +5v input to the microcontroller.  This trace was later cut and another wire was attached to the end not on the microcontroller&#8217;s side.  This makes it possible to enable or disable the PIC from the AVR making all the functionality of the PIC still available.</p>
<p>Here is the final wiring with hot-glue to hold everything in place:</p>
<div style="text-align:center"><img src="/pub/dioder-hack/Dioder-With-Wires-Finished.png" alt="Dioder with wires attached closeup" /></div>
<p>The wires were connected as follows:</p>
<div style="text-align:center">
<table>
<tr>
<th>Signal</th>
<th>PIC pin</th>
<th>AVR pin</th>
<th>AVR function</th>
</tr>
<tr>
<td>+5v</td>
<td>NA</td>
<td>20</td>
<td>Vcc</td>
</tr>
<tr>
<td>PIC +5v</td>
<td>1</td>
<td>11</td>
<td>PD5</td>
</tr>
<tr>
<td>Buzzer</td>
<td>2</td>
<td>13</td>
<td>PB1</td>
</tr>
<tr>
<td>Button</td>
<td>4</td>
<td>12</td>
<td>PB0</td>
</tr>
<tr>
<td>Green</td>
<td>5</td>
<td>15</td>
<td>PB3</td>
</tr>
<tr>
<td>Blue</td>
<td>6</td>
<td>14</td>
<td>PB2</td>
</tr>
<tr>
<td>Red</td>
<td>7</td>
<td>16</td>
<td>PB4</td>
</tr>
<tr>
<td>Ground</td>
<td>8</td>
<td>10</td>
<td>GND</td>
</tr>
</table>
</div>
<p>Then to allow the wires to come out of the Dioder control box I cut a small hole in the upper part of the plastic shell with a box cutter.</p>
<p>Here is the cut shell:</p>
<div style="text-align:center"><img src="/pub/dioder-hack/Cut-Dioder-Shell.png" alt="Cut Dioder shell" /></div>
<p>After trimming and connecting the wires to the 8-pin female .1&#8243; pitch header here is the finished hardware:</p>
<div style="text-align:center"><img src="/pub/dioder-hack/Finished-Dioder-Hack.png" alt="Finished Dioder hack" /></div>
<p>Trust me I really did end up using an ATTiny2313.  The chip pictured above ended up being bad and had to be desoldered.  That&#8217;s one reason it is a good idea to use a chip socket.</p>
<p>Once the hardware was completed all that remained was the software.  There are two parts.  One the code that goes on the ATTiny2313 and two the PC side software.</p>
<p>The ATTiny2313 firmware is fairly simple.  It listens on the serial port at 38400 baud with no parity 1 stop bit and 8-bit data.  When it receives a command it recognizes it sets values for the red, green and blue PWM pulses.  The firmware uses the ATTiny2313&#8217;s built in hardware PWM in 8-bit mode.  The PWM is very fast an produces lighting which is much less jittery then the original Dioder.</p>
<p>You can check out the source from my <a href="http://subversion.tigris.org/">subversion</a> repository like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> https:<span style="color: #000000; font-weight: bold;">//</span>cauldrondevelopment.com<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">svn</span><span style="color: #000000; font-weight: bold;">/</span>dioder-hack<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>I built the software in Ubuntu Linux.  First install the following packages:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> gcc-avr avrdude build-essential</pre></div></div>

<p>Then in the <b>trunk</b> directory run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p>This will build <b>dioder.hex</b> and <b>set_color</b> as well as some other files.</p>
<p>You can also find the binaries here: <a href="/pub/dioder-hack/dioder.hex">dioder.hex</a>, <a href="/pub/dioder-hack/set_color">set_color</a></p>
<p>To program <b>dioder.hex</b> in to the AVR microcontroller I used Atmel&#8217;s <a href="http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3808">AVR ISP mkII</a>.  There are many AVR programmers out there and you can even build your own but the mkII is cheap and effective.  With the mkII plugged into the USB hole and the other end connected to the 6-pin ISP programming port on the proto board, oriented so that the little tab points down towards the 4 pin serial header, run the following to program the chip:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span> program</pre></div></div>

<p>This will run <b>avrdude</b> to program the AVR.  If you use a different programmer you may need to change the <b>Makefile</b>.  This can also be done in Windows but you are on your own there.</p>
<p>The 4-pin port on the proto board is a logic-level (i.e. 5v) serial port.  This can be connected to a <a href="http://www.acroname.com/robotics/parts/S22-USB-SERIAL-INT-CONN.html">Brainstem USB to serial converter</a> from Acroname.  There are other ways to do this.  For example, you could <a href="http://www.windmeadow.com/node/25">wire in your own MAX232 serial level converter</a> and a 9-pin serial port but many computers don&#8217;t have actual serial ports these days.</p>
<p>Once everything is connected you can open the USB serial port in a terminal program, set the parameters to 38400 baud N81 and start playing with the pretty lights.  Here are the keyboard commands:</p>
<div style="text-align:center">
<table>
<tr>
<th>r</th>
<td>Toggle red</td>
</tr>
<tr>
<th>g</th>
<td>Toggle green</td>
</tr>
<tr>
<th>b</th>
<td>Toggle blue</td>
</tr>
<tr>
<th>o</th>
<td>Turn everything off.</td>
</tr>
<tr>
<th>0</th>
<td>Disable the PIC. (default)</td>
</tr>
<tr>
<th>1</th>
<td>Enable the PIC (The Dioder will support all its normal functions).</td>
</tr>
</table>
</div>
<p>This is fun for a few minutes but then you&#8217;ll want to set other colors.  This is where the <b>set_color</b> program comes in.  It is not very smart.  It just opens <b>/dev/ttyUSB0</b> and sends color commands.  If your serial port is on another device then you will have to change the code and rebuild.  <b>set_color</b> also does not even try to configure the serial port.  You will have to make sure it is configured correctly first.  If you configure the port in a terminal program, such as <b>minicom</b>, and then exit it should leave the serial port in the correct state.</p>
<p><b>set_color</b> can be run as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>set_color <span style="color: #000000;">255</span> <span style="color: #000000;">100</span> <span style="color: #000000;">0</span></pre></div></div>

<p>The above command should make the lights a yellowish orange.  The numbers are color values from 0 to 255.  The order is red, green, blue.</p>
<p>With a little shell script you can fade the colors like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">seq</span> <span style="color: #000000;">1</span> <span style="color: #000000;">255</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">seq</span> <span style="color: #000000;">254</span> <span style="color: #660033;">-1</span> <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span> .<span style="color: #000000; font-weight: bold;">/</span>set_color <span style="color: #007800;">$i</span> <span style="color: #000000;">4</span> <span style="color: #000000;">64</span>; <span style="color: #000000; font-weight: bold;">done</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>This will fade the lights back and forth between light blue and light pink.  You can stop it with CTRL-C.</p>
<p>Here is another cool one that is very hacky:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0</pre></div></div>

<p>This one might leave the Dioder PIC enabled.</p>
<p>So where do we go from here?  Here are some ideas I have about improving this:</p>
<ul>
<li>Write a nice python program for controlling the hacked Dioder with a pretty GUI interface for selecting colors and choosing color change patterns.</li>
<li>Use the hacked Dioder to indicate events such as email arriving, <a href="twitter.com">twitter</a> tweets or certain tags in <a href="http://www.reuters.com/tools/rss">news feeds</a>.</li>
<li>Change colors based on the weather outside or somewhere else.</li>
<li>Build the four channel Dioder hack I decided I didn&#8217;t have time for.</li>
</ul>
<p>So in the end I was quite happy with the hack.  It was entertaining and now I have computer controlled color LED lighting to show off.  If you found this article useful, built this hack for yourself or have other ideas for the Dioder or other Ikea LED products for that matter, I&#8217;d love to hear about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://cauldrondevelopment.com/blog/2009/12/29/a-real-ikea-dioder-hack/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>How to deal with ls, vi and emacs colors on a dark background</title>
		<link>http://cauldrondevelopment.com/blog/2009/12/14/how-to-deal-with-ls-vi-and-emacs-colors-on-a-dark-background/</link>
		<comments>http://cauldrondevelopment.com/blog/2009/12/14/how-to-deal-with-ls-vi-and-emacs-colors-on-a-dark-background/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 23:11:39 +0000</pubDate>
		<dc:creator>jcoffland</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Tech Notes]]></category>

		<guid isPermaLink="false">http://cauldrondevelopment.com/blog/?p=32</guid>
		<description><![CDATA[I like to use a dark gray background with a light gray foreground for my command terminals and editors.  I don&#8217;t do this just to be uber-l33t.  If you&#8217;ve ever spent long hours in front of a screen you may have noticed that your eyes go blurry and you start to find it [...]]]></description>
			<content:encoded><![CDATA[<p>I like to use a dark gray background with a light gray foreground for my command terminals and editors.  I don&#8217;t do this just to be uber-l33t.  If you&#8217;ve ever spent long hours in front of a screen you may have noticed that your eyes go blurry and you start to find it difficult to focus.  This use to happen to me about 8 hours in but with the right color scheme and a good LCD monitor I no longer have this problem.</p>
<p>Many software systems these days are setup with a white background and black foreground.  This is not so terrible since you can usually change the defaults.  However, once you&#8217;ve changed them there is a further problem.  Programs, such as <strong>ls</strong>, <strong>vi</strong> and <strong>emacs</strong>, have color syntax highlighting which is a very handy feature but when the colors were chosen to match a white background some colors, like dark blue, are very difficult to see on a dark background.</p>
<p>Fortunately solutions to these problems exist and are simple but once I get everything configured all is fine for a few weeks or months until I logon to a new system which doesn&#8217;t have my settings.  I inevitability forget the magic incantations or where they are even supposed to go and have to re-google which can cost 15 minutes of digging through posts, flames and why-would-you-want-to-do-that responses to locate clear concise answers.  So for myself and other nerds around the world here are the answers minus the nonsense:</p>
<h2>vi</h2>
<p>Add the following to the file <strong>.vimrc</strong> in your home directory:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">set background=dark</pre></div></div>

<h2>ls</h2>
<p>On Linux (RedHat, Ubuntu, et.al.) run the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">eval</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">dircolors</span> -b<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>You can also add this to your <strong>.bashrc</strong> or whatever the startup file is for your shell.</p>
<p>And on Mac OS X:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CLICOLOR</span>=<span style="color: #000000;">1</span> <span style="color: #666666; font-style: italic;"># Enable color ls</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">LSCOLORS</span>=gxfxcxdxbxegedabagacad <span style="color: #666666; font-style: italic;"># Set sane colors for dark background</span></pre></div></div>

<p>You can add these to your <strong>.profile</strong></p>
<h2>emacs</h2>
<p>To get the low-contrast colors I like I use the following code in my <strong>.emacs</strong> file:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'default-frame-alist '<span style="color: #66cc66;">&#40;</span>cursor-color <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;red3&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'default-frame-alist '<span style="color: #66cc66;">&#40;</span>foreground-color <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;gray85&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'default-frame-alist '<span style="color: #66cc66;">&#40;</span>background-color <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;gray25&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>set-cursor-color <span style="color: #ff0000;">&quot;red3&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>set-face-background 'region <span style="color: #ff0000;">&quot;gray85&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>set-face-foreground 'region <span style="color: #ff0000;">&quot;gray25&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>There might be more to getting emacs syntax highlighting correct for dark backgrounds but this is all I seem to have in my config.</p>
<p>If you have any related tips or things to add to this please feel free to comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://cauldrondevelopment.com/blog/2009/12/14/how-to-deal-with-ls-vi-and-emacs-colors-on-a-dark-background/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resize QEMU NTFS image</title>
		<link>http://cauldrondevelopment.com/blog/2009/02/26/resize-qemu-ntfs-image/</link>
		<comments>http://cauldrondevelopment.com/blog/2009/02/26/resize-qemu-ntfs-image/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:54:29 +0000</pubDate>
		<dc:creator>jcoffland</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Tech Notes]]></category>

		<guid isPermaLink="false">http://cauldrondevelopment.com/blog/?p=7</guid>
		<description><![CDATA[I recently needed to increase the size of an NTFS partition used in a kvm virtual machine.  There are instructions in several places on the Internet but I found many of them to be incomplete.  One of the best sources I found is linked below but the instructions failed to work as written. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to increase the size of an NTFS partition used in a kvm virtual machine.  There are instructions in several places on the Internet but I found many of them to be incomplete.  One of the best sources I found is linked below but the instructions failed to work as written.  This may be due to updates in software or my particular configuration.</p>
<p>See the section:<span style="font-weight: bold;"> How to enlarge a QEMU qcow or raw image that contains an NTFS bootable partition</span><br />
<a href="http://qemu-forum.ipi.fi/viewtopic.php?p=12362">http://qemu-forum.ipi.fi/viewtopic.php?p=12362</a></p>
<p>Additionally, the above instructions do not use less disk space if your image is not already in raw format.</p>
<p>My Setup:</p>
<ul>
<li>Ubuntu 8.10</li>
<li>KVM 83</li>
<li>Intel(R) Core(TM)2 Duo CPU     T7500  @ 2.20GHz</li>
<li>Windows XP SP2 Corporate</li>
<li>A single NTFS partition</li>
</ul>
<p><span style="font-weight: bold;">Step 0: Install some pacakges</span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ntfsprogs gparted hexedit</pre></div></div>

<p>hexedit may not be needed.  See below.</p>
<p><span style="font-weight: bold;">Step 1: Convert to raw format</span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ qemu-img convert <span style="color: #660033;">-f</span> qcow hda.qcow <span style="color: #660033;">-O</span> raw hda.raw</pre></div></div>

<p><span style="font-weight: bold;">Step 2: Check the number of heads</span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> losetup <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0 hda.raw
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> fdisk <span style="color: #660033;">-ul</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0
Disk <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0: <span style="color: #000000;">10.7</span> GB, <span style="color: #000000;">10737418240</span> bytes
<span style="color: #000000;">255</span> heads, <span style="color: #000000;">63</span> sectors<span style="color: #000000; font-weight: bold;">/</span>track, <span style="color: #000000;">1305</span> cylinders, total <span style="color: #000000;">20971520</span> sectors
Units = sectors of <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">512</span> = <span style="color: #000000;">512</span> bytes
&nbsp;
Device Boot      Start         End      Blocks   Id  System
<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0p1   <span style="color: #000000; font-weight: bold;">*</span>          <span style="color: #000000;">63</span>     <span style="color: #000000;">8176895</span>     <span style="color: #000000;">4088416</span>+   <span style="color: #000000;">7</span>  HPFS<span style="color: #000000; font-weight: bold;">/</span>NTFS
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> losetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0</pre></div></div>

<p>Remember the number of heads and start sector listed above.  If heads are 255 you shouldn&#8217;t have any problems.  If it is some other value like 128 or 64 you will likely have to change the number of heads in your NTFS partition later.</p>
<p>As was noted in the comments below, you also need to remember the starting sector and sector size for the partition offset calculation below.  In this case it is 63.</p>
<p><span style="font-weight: bold;">Step 3: Increase the raw image&#8217;s physical size</span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">if</span></span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>zero <span style="color: #007800;">of</span>=hda.raw <span style="color: #007800;">bs</span>=1G <span style="color: #007800;">count</span>=<span style="color: #000000;">0</span> <span style="color: #007800;">seek</span>=<span style="color: #000000;">20</span></pre></div></div>

<p>The above command will increase your raw image size to 20GB.  Change the number in the <span style="font-weight: bold;">seek</span> calculation to change the target size.</p>
<p><span style="font-weight: bold;">Step 4: Recheck and possibly fix the number of heads</span><br />
Rerun the commands in step 2.  If the number of heads has changed then you will need to patch your NTFS partition.  Otherwise, don&#8217;t worry about it and go to step 5.</p>
<p>First calculate the hexadecimal offset of the number of heads in the NTFS partition header.  It will be <b>start sector</b><b> * </b><b>sector size</b> + <b>0&#215;1a</b>.  In my case, <b>0&#215;7e1a</b>.  Then run these commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> hexedit
$ hexedit hda.raw</pre></div></div>

<p>In hexedit hit <b>Enter 7e1a Enter</b> to move to <strong>the offset you calculated above</strong>.  This location should hold the current value in hex of the number of heads according to the NTFS partition.  If this does not match what you expect <strong>don&#8217;t edit it</strong>; you are in the wrong place.  Otherwise, type over this value with the new number of heads in hex.  For example <b>FF</b> for 255 heads.  Save with <b>Ctrl-X</b> then <b>y</b>.</p>
<p><span style="font-weight: bold;">Step 5: Resize NTFS</span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ntfs
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> losetup -o$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">63</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">512</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0 hda.raw
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> ntfsresize <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> losetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0</pre></div></div>

<p>If <span style="font-weight: bold;">ntfsresize</span> refuses to work you may need to boot Windows and run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">chkdsk <span style="color: #000000; font-weight: bold;">/</span>f</pre></div></div>

<p>As David points out in the comments below, if your offset or sector size are different then you will have to adjust the offset calculation.  The calculation is <b>start sector</b> * <b>sector size</b>.</p>
<p><span style="font-weight: bold;">Step 6: Resize the partition</span><br />
The above method skips over the partition table so <span style="font-weight: bold;">ntfsresize</span> can work.  Thus even though NTFS has increased in size the partition table has not been updated.  This will cause Windows not to boot.  The following procedure will fix.  However, <strong>you must recreate the partition at the same start offset</strong>.  The default is 63 but if your offset is something else you will need to enter it below instead of 63:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> losetup <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0 hda.raw
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> fdisk <span style="color: #660033;">-u</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0
The number of cylinders <span style="color: #000000; font-weight: bold;">for</span> this disk is <span style="color: #000000; font-weight: bold;">set</span> to 2610.
There is nothing wrong with that, but this is larger than <span style="color: #000000;">1024</span>,
and could <span style="color: #000000; font-weight: bold;">in</span> certain setups cause problems with:
<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> software that runs at boot <span style="color: #000000; font-weight: bold;">time</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>e.g., old versions of LILO<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> booting and partitioning software from other OSs
<span style="color: #7a0874; font-weight: bold;">&#40;</span>e.g., DOS FDISK, OS<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span> FDISK<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Command <span style="color: #7a0874; font-weight: bold;">&#40;</span>m <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: d
Selected partition <span style="color: #000000;">1</span>
&nbsp;
Command <span style="color: #7a0874; font-weight: bold;">&#40;</span>m <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: n
Command action
e   extended
p   primary partition <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span>-<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
p
Partition number <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span>-<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #000000;">1</span>
First sector <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">63</span>-<span style="color: #000000;">41943039</span>, default <span style="color: #000000;">63</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
Using default value <span style="color: #000000;">63</span>
Last sector, +sectors or +<span style="color: #c20cb9; font-weight: bold;">size</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>K,M,G<span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">63</span>-<span style="color: #000000;">41943039</span>, default <span style="color: #000000;">41943039</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>:
Using default value <span style="color: #000000;">41943039</span>
&nbsp;
Command <span style="color: #7a0874; font-weight: bold;">&#40;</span>m <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: a
Partition number <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span>-<span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #000000;">1</span>
&nbsp;
Command <span style="color: #7a0874; font-weight: bold;">&#40;</span>m <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: t
Selected partition <span style="color: #000000;">1</span>
Hex code <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">type</span> L to list codes<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #000000;">7</span>
Changed system <span style="color: #7a0874; font-weight: bold;">type</span> of partition <span style="color: #000000;">1</span> to <span style="color: #000000;">7</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>HPFS<span style="color: #000000; font-weight: bold;">/</span>NTFS<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Command <span style="color: #7a0874; font-weight: bold;">&#40;</span>m <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">help</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #c20cb9; font-weight: bold;">w</span>
The partition table has been altered<span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
Calling ioctl<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> to re-read partition table.
&nbsp;
WARNING: Re-reading the partition table failed with error <span style="color: #000000;">22</span>: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> losetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0</pre></div></div>

<p>The above steps will:</p>
<ol>
<li>Delete the old partition</li>
<li>Create a new one of the correct size</li>
<li>Set the partition type to NTFS</li>
<li>Mark it bootable</li>
<li>Write the new partition table</li>
</ol>
<p>Note that the &#8220;Last sector&#8221; default value will be different if your disk is a different size.  Don&#8217;t worry about the warning at the end.</p>
<p><span style="font-weight: bold;">Step 7: Boot Windows and let chkdsk run</span><br />
Now just boot in to windows.  chkdsk should run automatically.  Check your disk size from with in windows it should be correct.</p>
<p><span style="font-weight: bold;">Problem: UNMOUNTABLE_BOOT_VOLUME on windows boot</span><br />
Windows does not like it when NTFS and the partition table disagree on the partition size.  I got this problem when following instructions elsewhere which didn&#8217;t address the change in heads.  You can try the suggestions in step 6 above or follow this procedure below:</p>
<p>First boot from a windows install CD, go to the recovery prompt (F4) and then run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">C:\<span style="color: #000000; font-weight: bold;">&gt;</span> fixboot
C:\<span style="color: #000000; font-weight: bold;">&gt;</span> fixmbr</pre></div></div>

<p>Then reboot.  This should just reset your NTFS partion to its old size.</p>
]]></content:encoded>
			<wfw:commentRss>http://cauldrondevelopment.com/blog/2009/02/26/resize-qemu-ntfs-image/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>KVM/QEMU tun/tap network</title>
		<link>http://cauldrondevelopment.com/blog/2009/02/26/kvmqemu-tuntap-network/</link>
		<comments>http://cauldrondevelopment.com/blog/2009/02/26/kvmqemu-tuntap-network/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:52:54 +0000</pubDate>
		<dc:creator>jcoffland</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Tech Notes]]></category>

		<guid isPermaLink="false">http://cauldrondevelopment.com/blog/?p=5</guid>
		<description><![CDATA[The default user mode networking supported by kvm/qemu is pretty good.  However, if you want to easily be able to connect to your VM you might want to switch to tun/tap networking.
Here is a script which you can use to start and stop a tun/tap network for your kvm.  You should change the [...]]]></description>
			<content:encoded><![CDATA[<p>The default user mode networking supported by kvm/qemu is pretty good.  However, if you want to easily be able to connect to your VM you might want to switch to tun/tap networking.</p>
<p>Here is a script which you can use to start and stop a tun/tap network for your kvm.  You should change the TAPUSER to the user you use to run the VM.  You also need to install the <span style="font-weight: bold;">dnsmasq</span> package.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">HOSTIF</span>=kvmnet0
<span style="color: #007800;">TAPUSER</span>=nobody
<span style="color: #007800;">HOSTIP</span>=10.1.1.1
<span style="color: #007800;">NETWORK</span>=10.1.1.0
<span style="color: #007800;">NETMASK</span>=255.255.255.0
<span style="color: #007800;">DHCPRANGE</span>=10.1.1.2,10.1.1.32
<span style="color: #007800;">DHCPPID</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>dnsmasq-<span style="color: #007800;">$HOSTIF</span>.pid
<span style="color: #007800;">DHCPD</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>dnsmasq
<span style="color: #007800;">VERBOSE</span>=<span style="color: #c20cb9; font-weight: bold;">false</span>
&nbsp;
tabbed_print<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 <span style="color: #007800;">X</span>=$<span style="color: #000000;">1</span>
 <span style="color: #7a0874; font-weight: bold;">shift</span>
 <span style="color: #007800;">X</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$X</span> + <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000; font-weight: bold;">@</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -c<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$X</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">80</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot; &quot;</span>
   <span style="color: #007800;">X</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$X</span> + <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
 <span style="color: #000000; font-weight: bold;">done</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #000000; font-weight: bold;">@</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
action<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 <span style="color: #007800;">LEN</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> -c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 <span style="color: #007800;">MSG</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">shift</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #007800;">$VERBOSE</span>; <span style="color: #000000; font-weight: bold;">then</span>
     <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
 <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MSG</span>&quot;</span>
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #007800;">$VERBOSE</span>; <span style="color: #000000; font-weight: bold;">then</span>
     $<span style="color: #000000; font-weight: bold;">@</span>
 <span style="color: #000000; font-weight: bold;">else</span>
     $<span style="color: #000000; font-weight: bold;">@</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
 <span style="color: #000000; font-weight: bold;">fi</span>
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> == <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   tabbed_print <span style="color: #007800;">$LEN</span> OK
 <span style="color: #000000; font-weight: bold;">else</span>
   tabbed_print <span style="color: #007800;">$LEN</span> FAILED
 <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 action <span style="color: #ff0000;">&quot;Creating <span style="color: #007800;">$HOSTIF</span>&quot;</span>
 tunctl <span style="color: #660033;">-u</span> <span style="color: #007800;">$TAPUSER</span> <span style="color: #660033;">-t</span> <span style="color: #007800;">$HOSTIF</span>
&nbsp;
 action <span style="color: #ff0000;">&quot;Configuring <span style="color: #007800;">$HOSTIF</span>&quot;</span>
 <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$HOSTIF</span> <span style="color: #007800;">$HOSTIP</span> up
&nbsp;
 action <span style="color: #ff0000;">&quot;Adding <span style="color: #007800;">$NETWORK</span> route&quot;</span>
 route add <span style="color: #660033;">-net</span> <span style="color: #007800;">$NETWORK</span> netmask <span style="color: #007800;">$NETMASK</span> dev <span style="color: #007800;">$HOSTIF</span>
&nbsp;
 action <span style="color: #ff0000;">&quot;Starting dnsmasq&quot;</span>
 start-stop-daemon <span style="color: #660033;">-S</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$DHCPPID</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$DHCPD</span> <span style="color: #660033;">--</span>
 <span style="color: #660033;">-i</span> <span style="color: #007800;">$HOSTIF</span> <span style="color: #660033;">--dhcp-range</span>=<span style="color: #007800;">$DHCPRANGE</span> <span style="color: #660033;">-9</span> <span style="color: #660033;">--listen-address</span>=<span style="color: #007800;">$HOSTIP</span>
 <span style="color: #660033;">--bind-interfaces</span> <span style="color: #660033;">--except-interface</span> lo <span style="color: #660033;">--pid-file</span>=<span style="color: #007800;">$DHCPPID</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 action <span style="color: #ff0000;">&quot;Stopping dnsmasq&quot;</span>
 start-stop-daemon <span style="color: #660033;">-K</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$DHCPPID</span>
&nbsp;
 action <span style="color: #ff0000;">&quot;Deconfiguring <span style="color: #007800;">$HOSTIF</span>&quot;</span>
 <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$HOSTIF</span> down
&nbsp;
 action <span style="color: #ff0000;">&quot;Removing <span style="color: #007800;">$HOSTIF</span>&quot;</span>
 tunctl <span style="color: #660033;">-d</span> <span style="color: #007800;">$HOSTIF</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
status<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$DHCPPID</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #c20cb9; font-weight: bold;">ps</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$DHCPPID</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
 <span style="color: #000000; font-weight: bold;">else</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DHCP not running!&quot;</span>
 <span style="color: #000000; font-weight: bold;">fi</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span>
&nbsp;
 <span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #007800;">$HOSTIF</span>
&nbsp;
 route <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$HOSTIF</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$NETWORK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
       start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
           start
           <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
       stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
           stop
           <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
       restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
           stop
           start
           <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
       status<span style="color: #7a0874; font-weight: bold;">&#41;</span>
           status
           <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
       -v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
           <span style="color: #007800;">VERBOSE</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
           <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
       <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
           <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Syntax: $0 &lt;start&gt;&quot;</span>
           <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
           <span style="color: #000000; font-weight: bold;">;;</span>
   <span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
   <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>You should then change your kvm network config to:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">-net</span> nic <span style="color: #660033;">-net</span> tap,<span style="color: #007800;">ifname</span>=kvmnet0,<span style="color: #007800;">script</span>=no,<span style="color: #007800;">downscript</span>=no</pre></div></div>

<p>If you want your virtual machine to access the external network you will also need to masquerade the interface with these commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-o</span> eth0 <span style="color: #660033;">-j</span> MASQUERADE
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> eth0 <span style="color: #660033;">-o</span> kvmnet0 <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
iptables <span style="color: #660033;">-A</span> FORWARD <span style="color: #660033;">-i</span> kvmnet0 <span style="color: #660033;">-o</span> eth0 <span style="color: #660033;">-j</span> ACCEPT</pre></div></div>

<p>Assuming your external network interface is eth0.</p>
]]></content:encoded>
			<wfw:commentRss>http://cauldrondevelopment.com/blog/2009/02/26/kvmqemu-tuntap-network/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating a VMWare XP install to KVM</title>
		<link>http://cauldrondevelopment.com/blog/2009/02/26/migrating-a-vmware-xp-install-to-kvm/</link>
		<comments>http://cauldrondevelopment.com/blog/2009/02/26/migrating-a-vmware-xp-install-to-kvm/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:46:34 +0000</pubDate>
		<dc:creator>jcoffland</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Tech Notes]]></category>

		<guid isPermaLink="false">https://cauldrondevelopment.com/blog/?p=3</guid>
		<description><![CDATA[KVM seems to have gotten quite good.  I am a long time VMWare user and fan but I prefer Open-Source apps and KVM uses my CPU&#8217;s hardware visualization features.  And besides my VMWare setup has started to crash fairly regularly for no apparent reason.
But, I don&#8217;t want to reinstall Windows.  Here is [...]]]></description>
			<content:encoded><![CDATA[<p>KVM seems to have gotten quite good.  I am a long time VMWare user and fan but I prefer Open-Source apps and KVM uses my CPU&#8217;s hardware visualization features.  And besides my VMWare setup has started to crash fairly regularly for no apparent reason.</p>
<p>But, I don&#8217;t want to reinstall Windows.  Here is my setup:</p>
<p>Ubuntu 8.10<br />
KVM 83<br />
Intel(R) Core(TM)2 Duo CPU     T7500  @ 2.20GHz<br />
XP SP2 Corporate</p>
<p>You will need your XP install disk.</p>
<p>- Download kvm-83 from:</p>
<p><a href="http://sourceforge.net/project/showfiles.php?group_id=180599">http://sourceforge.net/project/showfiles.php?group_id=180599</a></p>
<p>- Install some packages:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span>  <span style="color: #c20cb9; font-weight: bold;">gcc</span> gcc-<span style="color: #000000;">3.4</span> gcc-<span style="color: #000000;">4.1</span> libsdl1.2-dev <span style="color: #c20cb9; font-weight: bold;">make</span> libz-dev uuid-dev libasound2-dev <span style="color: #c20cb9; font-weight: bold;">gcc</span> libc6-dev zlib1g-dev qemu bridge-utils</pre></div></div>

<p>- Build and install kvm</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf kvm-83.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> kvm-<span style="color: #000000;">83</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>- Load modules</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> modprobe kvm kvm_intel</pre></div></div>

<p>- Convert VMWare image.  This is not necessary but a good idea because it also backs up your XP image.  Your images are probably located in /var/lib/vmware/Virtual Machines</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">qemu-img convert WinXPPro.vmdk <span style="color: #660033;">-O</span> qcow2 WinXPPro.qcow2</pre></div></div>

<p>At this point you could try booting but I got an error on boot up &#8220;A problem has been detected&#8230;&#8221;  I used the following steps to fix this.</p>
<p>- Boot with Win XP disk.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">kvm <span style="color: #660033;">-m</span> <span style="color: #000000;">1024</span> <span style="color: #660033;">-hda</span> WinXPPro.qcow2 <span style="color: #660033;">-boot</span> d <span style="color: #660033;">-cdrom</span> Microsoft_Windows_XP_Professional_Corporate_SP2.iso</pre></div></div>

<p>- Go through the menus and run the repair existing installation option.</p>
<p>- Now boot for real</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">kvm <span style="color: #660033;">-m</span> <span style="color: #000000;">1024</span> <span style="color: #660033;">-hda</span> WinXPPro.qcow2 <span style="color: #660033;">-boot</span> c</pre></div></div>

<p>Notes:</p>
<ul>
<li>Network just worked</li>
<li>I can change screen size through Windows driver settings.</li>
<li>Adding &#8216;-usbdevice tablet&#8217; to my kvm command line let the mouse automatically switch between screens like in VMWare.</li>
<li>Haven&#8217;t figured out how to automatically adjust guess OS screen to fit like in VMWare</li>
<li>I have mouse tracking problems with VNC mode</li>
<li>Otherwise this setup is MUCH faster than my VMWare Server</li>
</ul>
<p>Let me know if it worked for you.  Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://cauldrondevelopment.com/blog/2009/02/26/migrating-a-vmware-xp-install-to-kvm/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

