<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>/contrib/famzah &#187; Linux</title>
	<atom:link href="http://blog.famzah.net/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.famzah.net</link>
	<description>Enthusiasm never stops</description>
	<lastBuildDate>Thu, 02 Feb 2012 15:36:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.famzah.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>/contrib/famzah &#187; Linux</title>
		<link>http://blog.famzah.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.famzah.net/osd.xml" title="/contrib/famzah" />
	<atom:link rel='hub' href='http://blog.famzah.net/?pushpress=hub'/>
		<item>
		<title>Bind a shell on Linux and reverse-connect to it through a firewall</title>
		<link>http://blog.famzah.net/2012/01/06/bind-a-shell-on-linux-and-reverse-connect-to-it-through-a-firewall/</link>
		<comments>http://blog.famzah.net/2012/01/06/bind-a-shell-on-linux-and-reverse-connect-to-it-through-a-firewall/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 08:50:49 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bind shell]]></category>
		<category><![CDATA[remote shell bind]]></category>
		<category><![CDATA[reverse shell]]></category>
		<category><![CDATA[ssh reverse tunnel]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1108</guid>
		<description><![CDATA[There are situations when a friend is in need of Linux help, and the only way for you to help them is to log in to their machine and fix the problem yourself, instead of trying to explain over the phone all the steps to your friend. Such a problem has two sub-problems: The remote [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=1108&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are situations when a friend is in need of Linux help, and the only way for you to help them is to log in to their machine and fix the problem yourself, instead of trying to explain over the phone all the steps to your friend.</p>
<p>Such a problem has two sub-problems:</p>
<ul>
<li>The remote machine must accept incoming connections and provide you with shell access. The obvious way to achieve this is an SSH daemon. Many Desktop Linux distributions don&#8217;t install an SSH server by default though, for security reasons. Setting up an SSH server in this moment is slow, and could even not be possible, if your friend messed up with the packaging system, for example. So we need to find an easy way to bind a network shell on the remote machine.</li>
<li>We must be able to connect to the remote machine. Usually desktop machines are protected behind a firewall or NAT, and we cannot connect to them directly. If this is not the case for you, you can skip this step and just connect to the remote machine IP address. A common approach to overcome this problem is that the remote machine connects to a machine of yours, which has an accessible real IP address and has a running SSH server. Most Desktop Linux distributions have an SSH client installed by default. So all you need to do is quickly and temporarily set up an account with password authentication for your friend on your machine. Then let them log in there which will create a reverse tunnel back to their machine.</li>
</ul>
<p><u><strong>Bind a shell</strong></u></p>
<p>Another useful tool which is usually available on Linux is the <a href="http://en.wikipedia.org/wiki/Netcat">Netcat</a>, the Swiss-army knife for TCP/IP. In order to bind a shell using the Netcat version available on Ubuntu/Debian, you need to execute the following:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false;">
mkfifo /tmp/mypipe
# user shell
cat /tmp/mypipe|/bin/bash 2&gt;&amp;1|nc -l 6000 &gt;/tmp/mypipe
</pre>
</div>
<p>I got this awesome idea from a <a href="http://www.gnucitizen.org/blog/reverse-shell-with-bash/#comment-127498">user comment</a>. I only extended it a bit by adding &#8220;2&gt;&amp;1&#8243; which redirects the STDERR error messages to the remote network client too.</p>
<p>Once the above has been executed on the remote machine, anyone can connect on TCP port 6000, assuming that there is no firewall. Note that you have to connect via Netcat again. A connection via Telnet adds an additional &#8220;\r&#8221; at every line end, which confuses Bash. If you need to perform actions as &#8220;root&#8221; on the remote machine, the shell needs to be executed as &#8220;root&#8221;:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false;">
mkfifo /tmp/mypipe
# root shell
cat /tmp/mypipe|sudo /bin/bash 2&gt;&amp;1|nc -l 6000 &gt;/tmp/mypipe
</pre>
</div>
<p>If you are worried that your friend will mistype something, save the commands to a text file on a web server, and let them download it using &#8220;wget&#8221; or &#8220;curl&#8221;. Example:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false;">
wget http://www.famzah.net/download/bind-shell.txt
# or
curl http://www.famzah.net/download/bind-shell.txt &gt; bind-shell.txt

chmod +x bind-shell.txt
./bind-shell.txt
</pre>
</div>
<p><u><strong>Reverse connect using an SSH tunnel</strong></u></p>
<p>The <a href="http://www.openbsd.org/cgi-bin/man.cgi?query=ssh&amp;sektion=1">ssh client</a> has the ability to forward a local port (review <a href="http://www.vdomck.org/2005/11/reversing-ssh-connection.html">Reversing an ssh connection</a> for a detailed example). Once you&#8217;ve set up an account for your friend, you ask them to connect to your machine:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false;">
ssh -R 6000:127.0.0.1:6000 $IP_OF_YOUR_MACHINE
</pre>
</div>
<p>Once your friend has connected to your machine, you can connect to theirs using the reverse SSH tunnel by executing the following:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false;">
nc 127.0.0.1 6000
</pre>
</div>
<p>The connection to 127.0.0.1 on TCP port 6000 is actually forwarded by SSH to the remote machine of your friend on their TCP port 6000.</p>
<p>Note that once you disconnect from the &#8220;nc&#8221; session, the Netcat server on the remote machine exists and needs to be restarted if you need to connect again.</p>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/bind-shell/'>bind shell</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/remote-shell-bind/'>remote shell bind</a>, <a href='http://blog.famzah.net/tag/reverse-shell/'>reverse shell</a>, <a href='http://blog.famzah.net/tag/ssh-reverse-tunnel/'>ssh reverse tunnel</a>, <a href='http://blog.famzah.net/tag/ubuntu/'>ubuntu</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/1108/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/1108/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/1108/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=1108&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2012/01/06/bind-a-shell-on-linux-and-reverse-connect-to-it-through-a-firewall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Boot Linux using Windows 7 boot loader</title>
		<link>http://blog.famzah.net/2011/11/12/boot-linux-using-windows-7-boot-loader/</link>
		<comments>http://blog.famzah.net/2011/11/12/boot-linux-using-windows-7-boot-loader/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 19:07:18 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[boot loader]]></category>
		<category><![CDATA[EasyBCD]]></category>
		<category><![CDATA[GRUB stage1]]></category>
		<category><![CDATA[GRUB2]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1059</guid>
		<description><![CDATA[Windows 7 and Linux live together on the same hard disk in perfect harmony. I had Windows 7 installed first, and a few GBytes of free space at the end of the hard drive which I left unpartitioned. Here is how to install Ubuntu: Download Ubuntu and burn the ISO on a CD. Boot from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=1059&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Windows 7 and Linux live together on the same hard disk in perfect harmony. I had Windows 7 installed first, and a few GBytes of free space at the end of the hard drive which I left unpartitioned. Here is how to install Ubuntu:</p>
<ol>
<li>Download <a href="http://www.ubuntu.com/download/ubuntu/download">Ubuntu</a> and burn the ISO on a CD.</li>
<li>Boot from the CD, and install it. Make sure that you choose an <strong>empty partition</strong>, and also make sure that you select to <strong>install the boot loader on the Linux partition</strong> (example: on &#8220;/dev/sda3&#8243;, and <strong>not</strong> on the main MBR &#8220;/dev/sda&#8221;).</li>
</ol>
<p>Until here you have an Ubuntu installation which you cannot boot, yet.</p>
<p>Here is how to configure the Windows 7 boot loader to include Ubuntu in the boot choice menu:</p>
<ol>
<li>Download <a href="http://neosmart.net/dl.php?id=1">EasyBCD</a> and install it. EasyBCD is free for non-commercial use and offers a nice GUI to edit the Windows 7 boot loader menu.</li>
<li>Do the following in EasyBCD &#8212; Add New Entry -&gt; Operating Systems -&gt; Linux/BSD:
<ul>
<li>Type: GRUB 2</li>
<li>Name: Ubuntu</li>
<li>Device: <em>(Automatically configured)</em></li>
</ul>
</li>
<li>Finally, click on &#8220;View Settings&#8221; in EasyBCD. You should see something similar to the following:<br />
<blockquote><p>Entry #2<br />
Name: Ubuntu<br />
BCD ID: {1d486d61-64cc-12a5-7d94-af2f5df01535}<br />
Drive: C:\<br />
Bootloader Path: \NST\AutoNeoGrub0.mbr</p></blockquote>
</li>
</ol>
<p>EasyBCD ships the &#8220;stage1&#8243; boot loader of <a href="http://en.wikipedia.org/wiki/GNU_GRUB">GRUB2</a> (\NST\AutoNeoGrub0.mbr), so you don&#8217;t have to do anything else. Just reboot your Windows 7, and the boot menu should present a choice between &#8220;Windows 7&#8243; and &#8220;Ubuntu&#8221;.</p>
<p><strong>A note of caution</strong>: It is highly recommended that you do a backup of your whole hard disk before you try to install Ubuntu or modify the boot loader options.</p>
<p>P.S. There is no &#8220;boot.ini&#8221; in Windows 7. You could <a href="http://bkpavan.wordpress.com/2008/04/02/how-to-boot-linux-using-windows-bootloader-xp/">modify &#8220;boot.ini&#8221; in Windows XP</a> to achieve the same result, but this does not apply for Windows 7.</p>
<hr />
<p>References:</p>
<ul>
<li><a href="http://www.dslreports.com/forum/r21741595-Windows-7-boot-manager-editing-questions">Windows 7 boot manager editing questions</a></li>
<li><a href="http://www.w7forums.com/windows-7-boot-ini-file-t1350.html">Windows 7 boot.ini file</a></li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/boot-loader/'>boot loader</a>, <a href='http://blog.famzah.net/tag/easybcd/'>EasyBCD</a>, <a href='http://blog.famzah.net/tag/grub-stage1/'>GRUB stage1</a>, <a href='http://blog.famzah.net/tag/grub2/'>GRUB2</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/ubuntu/'>ubuntu</a>, <a href='http://blog.famzah.net/tag/windows-7/'>windows 7</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/1059/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=1059&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2011/11/12/boot-linux-using-windows-7-boot-loader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Get default outgoing IP address and interface on Linux</title>
		<link>http://blog.famzah.net/2011/09/06/get-default-outgoing-ip-address-and-interface-on-linux/</link>
		<comments>http://blog.famzah.net/2011/09/06/get-default-outgoing-ip-address-and-interface-on-linux/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 09:57:34 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[default gateway]]></category>
		<category><![CDATA[default outgoing IP]]></category>
		<category><![CDATA[route]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1049</guid>
		<description><![CDATA[Suppose you have one or more network interfaces, and they have one or more assigned IP addresses, also called aliases. If you need to find out which IP address and interface will be used as a default &#8220;source&#8221; by your Linux box, you need to execute the following: This, of course, assumes that 8.8.8.8 is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=1049&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Suppose you have one or more network interfaces, and they have one or more assigned IP addresses, also called aliases. If you need to find out which IP address and interface will be used as a default &#8220;source&#8221; by your Linux box, you need to execute the following:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false;">
ip route get 8.8.8.8
</pre>
</div>
<p>This, of course, assumes that 8.8.8.8 is not directly connected on your networks somehow. Since this is one of the Public Name Servers of Google, I think it is safe to assume so.</p>
<p>A sample output of the <a href="http://linux.die.net/man/8/ip">ip command</a> follows:</p>
<div class="sourcecode">
<pre class="brush: plain; gutter: false;">
8.8.8.8 via 10.0.2.2 dev eth0  src 10.0.2.15
    cache 
</pre>
</div>
<p>The output is pretty much self-explanatory &#8212; the route to &#8220;8.8.8.8&#8243; will originate from device &#8220;eth0&#8243;, the used source IP address will be &#8220;10.0.2.15&#8243;, and the next hop, the (default) gateway, will be &#8220;10.0.2.2&#8243;.</p>
<p>This method is 100% reliable. The man page of &#8220;ip&#8221; says that &#8220;this command gets a single route to a destination and prints its contents exactly as the kernel sees it&#8221;.</p>
<hr />
<p>References:</p>
<ul>
<li><a href="http://serverfault.com/questions/12285/when-ip-aliasing-how-does-the-os-determine-which-ip-address-will-be-used-as-sourc">When IP aliasing how does the OS determine which IP address will be used as source for outbound TCP/IP connections?</a></li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/default-gateway/'>default gateway</a>, <a href='http://blog.famzah.net/tag/default-outgoing-ip/'>default outgoing IP</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/route/'>route</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1049/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1049/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/1049/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/1049/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/1049/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/1049/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/1049/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/1049/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/1049/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/1049/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/1049/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/1049/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/1049/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/1049/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=1049&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2011/09/06/get-default-outgoing-ip-address-and-interface-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>sudo hangs and leaves the executed program as &#8220;zombie&#8221;</title>
		<link>http://blog.famzah.net/2010/11/01/sudo-hangs-and-leaves-the-executed-program-as-zombie/</link>
		<comments>http://blog.famzah.net/2010/11/01/sudo-hangs-and-leaves-the-executed-program-as-zombie/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 21:07:24 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[sudo]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=934</guid>
		<description><![CDATA[Today I discovered a non-security bug in sudo &#8211; the executed program finishes successfully, but sudo hangs forever waiting for something. The executed program is left in a &#8220;zombie&#8221; process state. Here is how the process list looks like, for example: root 6368 0.0 0.0 2808 1592 pts/6 Ss 18:39 0:00 &#124; \_ -bash root [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=934&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I discovered a non-security bug in <a href="http://www.sudo.ws/">sudo</a> &#8211; the executed program finishes successfully, but sudo hangs forever waiting for something. The executed program is left in a &#8220;zombie&#8221; process state. Here is how the process list looks like, for example:</p>
<blockquote><p>root      6368  0.0  0.0   2808  1592 pts/6    Ss   18:39   0:00  |   \_ -bash<br />
root      1103  0.0  0.0   2200  1000 pts/6    S+   21:45   0:00  |       \_ ./sudo -u root sleep 5<br />
root      1104  0.0  0.0      0     0 pts/6    Z+   21:45   0:00  |           \_ [sleep] &lt;defunct&gt;</p></blockquote>
<p>If we try to trace the system calls of the sudo command, here is what we get:</p>
<blockquote><p>[root@tester2 ~]# strace -fF -p 1103<br />
select(4, [3], [], NULL, NULL</p></blockquote>
<p>The sudo process waits endlessly in a select() system call which waits for file descriptor #3. So we quickly check what corresponds to file descriptor #3:</p>
<blockquote><p>[root@tester2 ~]# ls -la /proc/1103/fd<br />
total 0<br />
dr-x&#8212;&#8212;    2 root     root            0 Nov  1 21:45 .<br />
dr-xr-xr-x    5 root     root            0 Nov  1 21:45 ..<br />
lrwx&#8212;&#8212;    1 root     root           64 Nov  1 21:45 0 -&gt; /dev/pts/6<br />
lrwx&#8212;&#8212;    1 root     root           64 Nov  1 21:46 1 -&gt; /dev/pts/6<br />
lrwx&#8212;&#8212;    1 root     root           64 Nov  1 21:45 2 -&gt; /dev/pts/6<br />
lrwx&#8212;&#8212;    1 root     root           64 Nov  1 21:46 3 -&gt; socket:[1136261781]
</p></blockquote>
<p>Socket &#8220;socket:[1136261781]&#8221; is already closed tough (blinking in red on my console). Thus sudo is waiting in a blocked select() for a change on file descriptor #3, which is already closed and will never change its state. Sudo will therefore wait forever.</p>
<p>In order to understand why this happens, we will look at the <a href="http://www.sudo.ws/repos/sudo/">source code of sudo</a>. Here is snippet from &#8220;<a href="http://www.sudo.ws/repos/sudo/file/tip/src/exec.c">exec.c</a>&#8221; &#8211; only the relevant code is left for clarity:</p>
<div class="sourcecode">
<pre class="brush: cpp; collapse: true; light: false; toolbar: true; wrap-lines: false;">
int
sudo_execve(path, argv, envp, uid, cstat, dowait, bgmode)
{
    int sv[2];

    if (socketpair(PF_UNIX, SOCK_DGRAM, 0, sv) != 0)
    error(1, &quot;cannot create sockets&quot;);

    zero_bytes(&amp;sa, sizeof(sa));
    sigemptyset(&amp;sa.sa_mask);

    /* Note: HP-UX select() will not be interrupted if SA_RESTART set */
    sa.sa_flags = SA_INTERRUPT; /* do not restart syscalls */
    sa.sa_handler = handler;
    sigaction(SIGCHLD, &amp;sa, NULL);
    sigaction(SIGHUP, &amp;sa, NULL);
    sigaction(SIGINT, &amp;sa, NULL);
    sigaction(SIGPIPE, &amp;sa, NULL);
    sigaction(SIGQUIT, &amp;sa, NULL);
    sigaction(SIGTERM, &amp;sa, NULL);

    /* Max fd we will be selecting on. */
    maxfd = sv[0];

    child = fork()
    close(sv[1]);

    fdsr = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));
    fdsw = (fd_set *)emalloc2(howmany(maxfd + 1, NFDBITS), sizeof(fd_mask));

    for (;;) {

    zero_bytes(fdsw, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));
    zero_bytes(fdsr, howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask));

    FD_SET(sv[0], fdsr);

    if (recvsig[SIGCHLD])
        continue;
    nready = select(maxfd + 1, fdsr, fdsw, NULL, NULL);
    if (nready == -1) {
        if (errno == EINTR)
        continue;
        error(1, &quot;select failed&quot;);
    }

    }
}

/*
 * Generic handler for signals passed from parent -&gt; child.
 * The recvsig[] array is checked in the main event loop.
 */
void
handler(s)
    int s;
{
    recvsig[s] = TRUE;
}
</pre>
</div>
<p>The race-condition happens right before the select() on line #40, and just after the &#8220;if&#8221; on lines #38 and #39. If the parent process gets re-scheduled after the &#8220;if&#8221; was executed, and at this very time the child process finishes and SIGCHLD is sent to the parent process, sudo gets in trouble. The SIGCHLD handler accounts in the variable &#8220;recvsig[]&#8221; that the signal was received, and then the parent process calls select(). This select will never be interrupted, as the author had it in mind. In 99% of the cases, the parent process will enter in the select() blocking state before the child process ended. The child would then send SIGCHLD, which will be accounted in the handler procedure, and will also interrupt select() which will return -1 in &#8220;nready&#8221;, and &#8220;errno&#8221; will be set to EINTR.</p>
<p>Here is an easy way to reproduce the bug. We add a sleep() of 10 seconds between the &#8220;if&#8221; and select(), thus simulating that the system was very busy and re-scheduled the parent sudo process right between these two operations. Here is the source diff:</p>
<div class="sourcecode">
<pre class="brush: diff; collapse: true; light: false; toolbar: true; wrap-lines: false;">
--- sudo-orig/sudo-1.7.4p4/exec.c       Sat Sep  4 00:40:19 2010
+++ sudo-1.7.4p4/exec.c Mon Nov  1 21:48:24 2010
@@ -307,6 +307,10 @@
 
        if (recvsig[SIGCHLD])
            continue;
+       printf(&quot;debug: Missed the check for SIGCHLD, the child is still running. SIGCHLD status: %d\n&quot;, recvsig[SIGCHLD]);
+       sleep(10); // this will be interrupted by SIGCHLD, because the child exists at some time here (we run &quot;sudo sleep 5&quot;)
+       printf(&quot;debug: We should have got SIGCHLD by now. SIGCHLD status: %d\n&quot;, recvsig[SIGCHLD]);
+       printf(&quot;debug: Entering the endless select()...\n&quot;);
        nready = select(maxfd + 1, fdsr, fdsw, NULL, NULL);
        if (nready == -1) {
            if (errno == EINTR)
</pre>
</div>
<p>After that we execute sudo, and observe the bug every time:</p>
<blockquote><p>[root@tester2 sudo-1.7.4p4]# make &gt;/dev/null &amp;&amp; ./sudo -u root sleep 5<br />
debug: Missed the check for SIGCHLD, the child is still running. SIGCHLD status: 0<br />
debug: We should have got SIGCHLD by now. SIGCHLD status: 1<br />
debug: Entering the endless select()&#8230;<br />
&#8230;(this never finishes)&#8230;
</p></blockquote>
<p>The sudo author actually tried to avoid this potential race condition if SIGCHLD is received immediately<br />
before we call select() &#8211; <a href="http://www.sudo.ws/repos/sudo/rev/99adc5ea7f0a">changeset 5334:99adc5ea7f0a</a>. The proper way to fix this is to use a timeout in the select() call:</p>
<div class="sourcecode">
<pre class="brush: diff; collapse: false; wrap-lines: false;">
--- sudo-orig/sudo-1.7.4p4/exec.c       Sat Sep  4 00:40:19 2010
+++ sudo-1.7.4p4/exec.c Mon Nov  1 21:50:26 2010
@@ -307,7 +307,11 @@
 
        if (recvsig[SIGCHLD])
            continue;
-       nready = select(maxfd + 1, fdsr, fdsw, NULL, NULL);
+       struct timeval timeout;
+       timeout.tv_sec = 1; // Linux resets this, so set it everytime
+       timeout.tv_usec = 0;
+       nready = select(maxfd + 1, fdsr, fdsw, NULL, &amp;timeout);
        if (nready == -1) {
            if (errno == EINTR)
                continue;
</pre>
</div>
<p>The select() mechanism and this bug were introduced somewhere between sudo versions 1.7.2 and 1.7.3. At least that is what I managed to see from the <a href="http://www.sudo.ws/sudo/changes.html">Changelog</a>:</p>
<div class="sourcecode">
<pre class="brush: diff; collapse: true; light: false; toolbar: true; wrap-lines: false;">
2010-06-29  Todd C. Miller  &lt;Todd.Miller@courtesan.com&gt;
	[72fd1f510a08] [SUDO_1_7_3] &lt;1.7&gt;
...
2009-11-15  Todd C. Miller  &lt;Todd.Miller@courtesan.com&gt;
	* script.c, sudo.c, sudo.h, sudoreplay.c, term.c, tgetpass.c:
	Use a socketpair to pass signals from parent to child.
...
2009-07-12  Todd C. Miller  &lt;Todd.Miller@courtesan.com&gt;
	[f5ad45f69f05] [SUDO_1_7_2]
</pre>
</div>
<p>I&#8217;ve reported this bug (<a href="http://www.gratisoft.us/bugzilla/show_bug.cgi?id=447">#447</a>) to the sudo maintainer, and I&#8217;m sure he will fix it when time permits. Because we all depend on sudo and love it. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/sudo/'>sudo</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/934/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/934/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/934/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=934&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/11/01/sudo-hangs-and-leaves-the-executed-program-as-zombie/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Linux Cached/Buffers memory</title>
		<link>http://blog.famzah.net/2010/09/14/linux-cached-buffers-memory/</link>
		<comments>http://blog.famzah.net/2010/09/14/linux-cached-buffers-memory/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 09:27:13 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[/proc/sys/vm/drop_caches]]></category>
		<category><![CDATA[buffers memory]]></category>
		<category><![CDATA[cached memory]]></category>
		<category><![CDATA[cached/buffers memory]]></category>
		<category><![CDATA[filesystem cache hit/miss ratio]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=905</guid>
		<description><![CDATA[I won&#8217;t try to explain in details what Linux Cached/Buffers memory is. In a nutshell, it shows how much of your memory is used for the read cache and for the write cache. Usually when you look at your system memory usage and see that almost all of the unused memory is allocated for Cached/Buffers, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=905&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I won&#8217;t try to explain in details what Linux Cached/Buffers memory is. In a nutshell, it shows how much of your memory is used for the read cache and for the write cache.</p>
<p>Usually when you look at your system memory usage and see that almost all of the unused memory is allocated for Cached/Buffers, you are happy, because this memory is used for file-system cache, thus your system is running faster.</p>
<p>Today however I observed quite an interesting fact &#8211; what I said above is still correct, however you don&#8217;t know how often these cache entries are used by the system. After all, it&#8217;s <strong>not</strong> the cache memory <strong>usage</strong> (or size) which makes the system run faster, but the <strong>cache hit ratio</strong>. If the file operations get satisfied by the cache (cache hit), then your system is running faster. If the system needs to make a physical disk I/O (cache miss), then you&#8217;d need to wait for a good few milliseconds.</p>
<p>What are your options, in order to know if your file cache is actually being used or is just sitting there allocated, giving you a false feeling that your system is running faster thanks to the used cache memory:</p>
<ol>
<li>(hard) In order to actually know the Cache Hit/Miss ratios for block devices, you&#8217;ll need to dig deep into the kernel, as I already explained in the &#8220;<a href="http://serverfault.com/questions/157612/is-there-a-way-to-get-cache-hit-miss-ratios-for-block-devices-in-linux/157724">Is there a way to get Cache Hit/Miss ratios for block devices in Linux</a>&#8221; article.</li>
<li>(easy) You can clear the Cached/Buffers memory regularly, see how fast and how much the cache memory grows back, and draw some conclusions about the actual Cache Hit/Miss ratios.</li>
</ol>
<p>The latter is not a perfect solution, but in all cases gives you a better idea of your file-system cache usage, than just watching the totally used memory in Cached/Buffers, and never actually knowing if it is used/accessed at all.</p>
<p>Therefore, you can run the following every hour in a cron job:</p>
<blockquote><p>sync ; echo 3 &gt; /proc/sys/vm/drop_caches<br />
sync ; echo 0 &gt; /proc/sys/vm/drop_caches</p></blockquote>
<p>The commands are safe (see reference for &#8220;<a href="http://linux-mm.org/Drop_Caches">drop_caches</a>&#8220;), and you won&#8217;t lose any data, just your caches will be zeroed. The disadvantage of this approach is that if the caches were very actively used indeed, Linux would need to read the data back from the disk.</p>
<h1>A real-world example</h1>
<h2>&nbsp;</h2>
<p>Here is how the Cached/Buffers graphics of a server of mine looks for the following few days:<br />
<div id="attachment_906" class="wp-caption aligncenter" style="width: 460px"><a href="http://famzah.files.wordpress.com/2010/09/memory-usage.png"><img src="http://famzah.files.wordpress.com/2010/09/memory-usage.png?w=450&#038;h=255" alt="" title="Linux memory usage" width="450" height="255" class="size-full wp-image-906" /></a><p class="wp-caption-text">Linux memory usage</p></div></p>
<p>Pay attention to the points of interest which are marked. Here is the explanation and motivation to write this article:</p>
<ol>
<li>(Point <strong>A</strong>) The beginning of the graph shows my system after it just booted, and I did some small administrative tasks on it. After that, one script runs regularly on the machine, and as we see, it doesn&#8217;t use much file-system cache, as it doesn&#8217;t do many file operations.
</li>
<li>Then every day at <strong>06:25</strong> the &#8220;/etc/cron.daily&#8221; scripts are run and some of them read all files on the file-system. Such a script is the <a href="http://en.wikipedia.org/wiki/Updatedb">updatedb</a> cron job. Because of the great disk activity, the Buffers/Cache usage gets maximal, as all possible files and meta data are being cached in memory.</li>
<li>(see &#8220;<strong>Updatedb cron</strong>&#8221; markers on the graphics) After <strong>one hour</strong>, the scripts finish and no significant disk activity is done on the system any more.</li>
<li>(Point <strong>B</strong>) But the <strong>Cached/Buffers usage never drops down</strong>. The file cache doesn&#8217;t seem to expire, and is therefore giving us the false feeling that it is being used by our system all the time, thus making it faster. But it isn&#8217;t!</li>
<li>On <strong>Sat 15:08</strong> the Cached/Buffers cache is cleared manually by the command I provided above, and I installed it as an hourly crontab too.</li>
<li>As you can see, right after the cache was cleared, we see the sad reality &#8211; the Cached/Buffers cache was filled with data that nobody needed or accessed, and the high memory usage by Cached/Buffers actually didn&#8217;t speed up our system. I grieve for a while and accept the reality, and also understand why so many I/O requests are issued to my <a href="http://aws.amazon.com/ebs/">EBS storage</a>, even though the cache was so huge.</li>
<li>(Point <strong>C</strong>) That&#8217;s how the actual daily usage pattern of this machine looks like. The Cached/Buffers memory cache is heavily underused on my system, as it doesn&#8217;t do much I/O work. This wouldn&#8217;t be visible if I don&#8217;t clear the cache every hour.</li>
</ol>
<hr />
<p>References:</p>
<ul>
<li><a href="http://www.westnet.com/~gsmith/content/linux-pdflush.htm">The Linux Page Cache and pdflush: Theory of Operation and Tuning for Write-Heavy Loads</a>.</li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/procsysvmdrop_caches/'>/proc/sys/vm/drop_caches</a>, <a href='http://blog.famzah.net/tag/buffers-memory/'>buffers memory</a>, <a href='http://blog.famzah.net/tag/cached-memory/'>cached memory</a>, <a href='http://blog.famzah.net/tag/cachedbuffers-memory/'>cached/buffers memory</a>, <a href='http://blog.famzah.net/tag/filesystem-cache-hitmiss-ratio/'>filesystem cache hit/miss ratio</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/905/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/905/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/905/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/905/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/905/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/905/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/905/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/905/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/905/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/905/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/905/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/905/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/905/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/905/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=905&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/09/14/linux-cached-buffers-memory/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>

		<media:content url="http://famzah.files.wordpress.com/2010/09/memory-usage.png" medium="image">
			<media:title type="html">Linux memory usage</media:title>
		</media:content>
	</item>
		<item>
		<title>USB: rejected 1 configuration due to insufficient available bus power</title>
		<link>http://blog.famzah.net/2010/08/11/usb-rejected-1-configuration-due-to-insufficient-available-bus-power/</link>
		<comments>http://blog.famzah.net/2010/08/11/usb-rejected-1-configuration-due-to-insufficient-available-bus-power/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 09:10:10 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Bifferboard]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[usb]]></category>
		<category><![CDATA[usb external power]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=851</guid>
		<description><![CDATA[If your USB device is not being recognized, execute the command &#8220;dmesg&#8221; and check if the following output is there: usb 1-1.4: rejected 1 configuration due to insufficient available bus power The &#8220;1-1.4&#8243; ID may be different for your configuration. If, and only if, you are absolutely sure that your USB hub and/or hardware configuration [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=851&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If your USB device is not being recognized, execute the command &#8220;<a href="http://en.wikipedia.org/wiki/Dmesg">dmesg</a>&#8221; and check if the following output is there:</p>
<blockquote><p>usb 1-1.4: rejected 1 configuration due to insufficient available bus power</p></blockquote>
<p>The &#8220;1-1.4&#8243; ID may be different for your configuration.</p>
<p>If, and only if, you are absolutely sure that your USB hub and/or hardware configuration have a safe way to actually supply enough power, you can override this barrier and force the device to be activated despite of the error message. A possible situation is where you manually applied 5V external power on your USB device and/or USB hub, like I did on my <a href="http://bifferos.bizhat.com/">Bifferboard</a>.</p>
<p>Here is how you can override the power safety mechanism:</p>
<blockquote><p>echo 1 &gt; /sys/bus/usb/devices/1-1.4/bConfigurationValue</p></blockquote>
<p>Replace &#8220;1-1.4&#8243; with your USB device ID. Be careful and have fun!</p>
<hr />
<p>Resources:</p>
<ul>
<li><a href="http://rt2x00.serialmonkey.com/phpBB/viewtopic.php?f=5&amp;t=5459">Error insufficient available bus power RT2573</a>.</li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/bifferboard/'>Bifferboard</a>, <a href='http://blog.famzah.net/category/hardware/'>Hardware</a>, <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/usb/'>usb</a>, <a href='http://blog.famzah.net/tag/usb-external-power/'>usb external power</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/851/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=851&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/11/usb-rejected-1-configuration-due-to-insufficient-available-bus-power/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Speed up RRDtool database manipulations via RRDs (Perl)</title>
		<link>http://blog.famzah.net/2010/08/01/speed-up-rrdtool-database-manipulations-via-rrds-perl/</link>
		<comments>http://blog.famzah.net/2010/08/01/speed-up-rrdtool-database-manipulations-via-rrds-perl/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 14:09:56 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[rrd]]></category>
		<category><![CDATA[rrdtool]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=795</guid>
		<description><![CDATA[Use case You are doing a lot of data operations on your RRD files (create, update, fetch, last), and every update is done by a separate Perl process which lives a very short time &#8211; the process is launched, it updates or reads the data, does something else, and then exits. The problem If you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=795&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><u>Use case</u><br />
You are doing a lot of data operations on your RRD files (create, update, fetch, last), and every update is done by a separate Perl process which lives a very short time &#8211; the process is launched, it updates or reads the data, does something else, and then exits.</p>
<p><u>The problem</u><br />
If you are using <a href="http://oss.oetiker.ch/rrdtool/">RRDtool</a> and Perl as described, you surely have noticed that running many of these processes wastes <strong>a lot of CPU resources</strong>. The question is &#8211; can we do some performance optimizations, and lessen the performance hit of loading the <a href="http://oss.oetiker.ch/rrdtool/prog/RRDs.en.html">RRDs</a> library into Perl? We know that launching often Perl itself is quite expensive, but after all, if we chose to work with Perl, this is a price we should be ready to pay.</p>
<p>The RRDtool shared library is a monolithic piece of code which provides <a href="http://oss.oetiker.ch/rrdtool/doc/index.en.html">ALL functions of the RRDtool suite</a> &#8211; data manipulation, graphics and import/export tools. The last two components bring huge dependencies in regards to other shared libraries. <strong>The library from RRDtool version 1.4.4 depends on 34 other libraries</strong> on my Linux box! This must add up to the loading time of the RRDtool library into Perl.</p>
<p><u>Resolution and benchmarks</u><br />
In order to prove my theory (actually, it was more a theory of <a href="http://blog.lifepattern.org/">zImage</a>, and I just followed, enhanced and tried it), I commented out the implementation of the &#8220;graphics&#8221; and &#8220;import/export tools&#8221; modules from the source code of RRDtool. Then I re-compiled the library and did some performance benchmarks. I also re-implemented the RRDs.pm module by replacing the <a href="http://search.cpan.org/~jesse/perl-5.12.1/ext/DynaLoader/DynaLoader_pm.PL">DynaLoader</a> module with the <a href="http://search.cpan.org/~saper/XSLoader-0.10/XSLoader.pm">XSLoader</a> one. This made no difference in performance whatsoever. The re-compiled RRD library depends on only 4 other libraries &#8211; linux-gate.so.1, libm.so.6, libc.so.6, and /lib/ld-linux.so.2. I think this is the most we can cut down. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So here are the benchmark results. They show the accumulated time for 1000 invocations of the Perl interpreter with three different configurations:</p>
<ul>
<li>Only Perl (baseline): <strong>5.454s</strong>.</li>
<li>With RRDs, no graphics or import/export functions: <strong>9.744s</strong> (+4.290s) <strong>+78%</strong>.</li>
<li>With standard RRDs: <strong>11.647s</strong> (+6.192s) <strong>+113%</strong>.</li>
</ul>
<p>As you can see, you can make Perl + RRDs start <strong>35% faster</strong>. The speed up for RRDs itself is 44%.</p>
<hr />
<p>Here are the commands I used for the benchmarks:</p>
<ul>
<li>Only Perl (baseline): time ( i=1000 ; while [ "$i" -gt 0 ]; do perl -Mwarnings -Mstrict -e &#8221; ; i=$(($i-1)); done )</li>
<li>Perl + RRDs: time ( i=1000 ; while [ "$i" -gt 0 ]; do perl -Mwarnings -Mstrict -MRRDs -e &#8221; ; i=$(($i-1)); done )</li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/development/'>Development</a>, <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/benchmark/'>benchmark</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/performance/'>performance</a>, <a href='http://blog.famzah.net/tag/perl/'>perl</a>, <a href='http://blog.famzah.net/tag/rrd/'>rrd</a>, <a href='http://blog.famzah.net/tag/rrdtool/'>rrdtool</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/795/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=795&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/01/speed-up-rrdtool-database-manipulations-via-rrds-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Firefox crashes with &#8220;terminate called after throwing an instance of &#8216;std::bad_alloc&#8217;&#8221;</title>
		<link>http://blog.famzah.net/2010/02/08/firefox-crashes-with-terminate-called-after-throwing-an-instance-of-std-bad_alloc/</link>
		<comments>http://blog.famzah.net/2010/02/08/firefox-crashes-with-terminate-called-after-throwing-an-instance-of-std-bad_alloc/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 13:27:52 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[e-signature]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[infonotary]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=424</guid>
		<description><![CDATA[If you are here, you probably are as desperate as I was. Though your system has plenty of memory, Firefox keeps crashing with the following error message: You can see the above error either by starting &#8220;firefox&#8221; in your console terminal manually, or by reviewing the file &#8220;~/.xsession-errors&#8221;, if you are running KDE. I ran [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=424&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are here, you probably are as desperate as I was. Though your system has plenty of memory, Firefox keeps crashing with the following error message:</p>
<div class="sourcecode">
<pre class="brush: plain; light: true;">
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted
</pre>
</div>
<p>You can see the above error either by starting &#8220;firefox&#8221; in your console terminal manually, or by reviewing the file &#8220;~/.xsession-errors&#8221;, if you are running KDE.</p>
<p>I ran Firefox several times in debug mode via &#8220;<a href="http://linux.die.net/man/1/gdb">gdb</a>&#8221; and every time the debug output lead me to the wrong direction. Here is a sample full backtrace output:</p>
<div class="sourcecode">
<pre class="brush: plain; collapse: true; light: false; toolbar: true;">
[New Thread 0xadbfeb70 (LWP 3763)]
[Thread 0xadbfeb70 (LWP 3763) exited]
[New Thread 0xadbfeb70 (LWP 3764)]
[Thread 0xadbfeb70 (LWP 3764) exited]
[New Thread 0xadbfeb70 (LWP 3765)]
[New Thread 0xae3ffb70 (LWP 3766)]
[Thread 0xadbfeb70 (LWP 3765) exited]
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Program received signal SIGABRT, Aborted.
0x00227422 in ?? ()
(gdb) bt full
#0  0x00227422 in ?? ()
No symbol table info available.
#1  0x002524d1 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
        resultvar = &lt;value optimized out&gt;
        pid = 3575796
        selftid = 3708
#2  0x00255932 in *__GI_abort () at abort.c:92
        act = {__sigaction_handler = {sa_handler = 0x7a3ff4, sa_sigaction = 0x7a3ff4}, sa_mask = {__val = {3221183748, 3086869600, 3221183704, 7933961,
              3221183688, 1154680, 3221183676, 8013772, 0, 3086866344, 5, 0, 1, 3221183640, 0, 3221183716, 1356543, 3577255, 3221183636, 3035204, 1,
              3086869160, 0, 3221183748, 3221183676, 3221183688, 0, 4294967295, 1359583, 3086869160, 3221183680, 4294967295}}, sa_flags = 8011764,
          sa_restorer = 0x14b2ff}
        sigs = {__val = {32, 0 &lt;repeats 31 times&gt;}}
#3  0x001cc4df in __gnu_cxx::__verbose_terminate_handler () at ../../../../src/libstdc++-v3/libsupc++/vterminate.cc:93
        terminating = true
        t = &lt;value optimized out&gt;
#4  0x001ca415 in __cxxabiv1::__terminate (handler=0x1cc390 &lt;__gnu_cxx::__verbose_terminate_handler()&gt;)
    at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:38
No locals.
#5  0x001ca452 in std::terminate () at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:48
No locals.
#6  0x001ca591 in __cxa_throw (obj=0xad2f9700, tinfo=0x1f97fc, dest=0x1caaf0 &lt;~bad_alloc&gt;) at ../../../../src/libstdc++-v3/libsupc++/eh_throw.cc:83
        header = &lt;value optimized out&gt;
#7  0x001cac0f in operator new (sz=2) at ../../../../src/libstdc++-v3/libsupc++/new_op.cc:58
        handler = &lt;value optimized out&gt;
        p = &lt;value optimized out&gt;
#8  0x001caced in operator new[] (sz=2) at ../../../../src/libstdc++-v3/libsupc++/new_opv.cc:32
No locals.
#9  0x012ead5c in gfxSkipChars::TakeFrom (this=0xbfff5f1c, aSkipCharsBuilder=0xbfff6f60) at ../../dist/include/thebes/gfxSkipChars.h:152
No locals.
#10 0x012e48fe in BuildTextRunsScanner::BuildTextRunForFrames (this=0xbfff8320, aTextBuffer=0xbfff7280) at nsTextFrameThebes.cpp:1713
        anySmallcapsStyle = 0
        textBreakPoints = {&lt;nsTArray&lt;int&gt;&gt; = {&lt;nsTArray_base&gt; = {static sEmptyHdr = {mLength = 0, mCapacity = 0, mIsAutoArray = 0},
              mHdr = 0xbfff7150}, &lt;No data fields&gt;},
          mAutoBuf = &quot;&#92;&#48;01&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;62&#92;&#48;00&#92;&#48;00\200&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\220z\377\277\354x\377\277&#92;&#48;65&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;66&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\b&#92;&#48;00&#92;&#48;00&#92;&#48;00\260q\377\277\254q\377\277\220q\377\277&#92;&#48;00\202&#92;&#48;66\260&#92;&#48;30V\241\265\b@q\267&#92;&#48;66&#92;&#48;00&#92;&#48;00&#92;&#48;00\240\321\377\263\270\321\377\263&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\b&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;01&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\b&#92;&#48;00&#92;&#48;00&#92;&#48;00\b&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\304i&#92;&#48;05\255\b&#92;&#48;00&#92;&#48;00&#92;&#48;00$\301 \255\364&#92;&#48;17\274&#92;&#48;01\240\321\377\263\b&#92;&#48;00&#92;&#48;00&#92;&#48;00\254y\377\277\201E\225&#92;&#48;01\354x\377\277\240\321\377\263&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;36\352\216&#92;&#48;01&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\200g/\255\220z\377\277xr\377\277\256\371\247&#92;&#48;01&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\220z\377\277(;\260&#92;&#48;01&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\354x\377\277\254r\377\277\364&#92;&#48;17\274&#92;&#48;01tr\377\277&#92;&#48;02&#92;&#48;00&#92;&#48;00&#92;&#48;00&lt;r\377\277&quot;}
        currentTransformedTextOffset = 1
        finalUserData = 0xad2037cc
        userDataToDestroy = 0x0
        nextBreakIndex = 2904569804
        firstFrame = 0xad2037cc
        builder = {mBuffer = {&lt;nsTArray&lt;unsigned char&gt;&gt; = {&lt;nsTArray_base&gt; = {static sEmptyHdr = {mLength = 0, mCapacity = 0, mIsAutoArray = 0},
                mHdr = 0xbfff6f64}, &lt;No data fields&gt;},
            mAutoBuf = &quot;&#92;&#48;02&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;01&#92;&#48;00\200&#92;&#48;01&#92;&#48;01\377\277\223\200\223&#92;&#48;01&#92;&#48;27m\271&#92;&#48;00#&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;31\201\271&#92;&#48;00\364&#92;&#48;17\274&#92;&#48;01&lt;&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\274p\377\277\347&#92;&#48;63\225&#92;&#48;01&#92;&#48;27m\271&#92;&#48;00\324\302\355\267&#92;&#48;31\201\271&#92;&#48;00\256^&#92;&#48;05\b@\300\355\267\240\246z\267&#92;&#48;04&#92;&#48;00&#92;&#48;00&#92;&#48;00\364\257&#92;&#48;05\b&#92;&#48;00@&#92;&#48;06\255&#92;&#48;00&#92;&#48;00&#92;&#48;00\255\fp\377\277&#92;&#48;64u&#92;&#48;05\b@\300\355\267&#92;&#48;00&#92;&#48;00&#92;&#48;02&#92;&#48;00\320o\377\277&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;62&#92;&#48;00&#92;&#48;00\200&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00[]&#92;&#48;05\b\225\351\216&#92;&#48;01\240D&#92;&#48;06\255\374\301\355\267 &#92;&#48;00&#92;&#48;00&#92;&#48;00\217\350\216&#92;&#48;01$p\377\277&#92;&#48;02&#92;&#48;00&#92;&#48;00&#92;&#48;00\274p\377\277\225\351\216&#92;&#48;01\f\203\377\277\370\202\377\277,p\377\277&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\f\203\377\277\370\202\377\277lp\377\277&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\370\202\377\277&#92;&#48;04&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;02&#92;&#48;00&#92;&#48;00&#92;&#48;00\364&#92;&#48;17\274&#92;&#48;01,\203\377\277&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00lp\377\277_\256.&#92;&#48;01,\203\377\277&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00&#92;&#48;00\225\351\216&#92;&#48;01&#92;&#48;04&quot;, '&#92;&#48;00' &lt;repeats 11 times&gt;&quot;\217, \350\216&#92;&#48;01\240\201\37---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---
</pre>
</div>
<p>After much try-and-error attempts, and also thoughts if my laptop&#8217;s memory wasn&#8217;t faulty or if the shared libraries on my disk weren&#8217;t somehow corrupted, I was finally able to track down the cause of this abnormal behavior:</p>
<p><strong>BUG: The Security Device which the Siemens HiPath SIcurity Card API provided.</strong> You can <a href="http://blog.famzah.net/2009/10/30/infonotary-e-signature-with-cardman-6121-on-kubuntu-karmic/">read here why I use it</a>.</p>
<p>The problem started somewhere around Firefox version 3.5.5 and later. If the security device dongle/card is not plugged in your computer, Firefox crashes at random pages.</p>
<p><u>The resolution</u><br />
Create a second Firefox profile and install the Security Device only there, leaving the default Firefox profile with no Security Device capabilities. Thus if you want to use your online banking, you would need to close Firefox and then start it using the second profile. It&#8217;s not that bad, if you are a personal user like me who performs bank transactions relatively rarely.</p>
<p>The MozillaZine Knowledge Base has an excellent article about <a href="http://kb.mozillazine.org/Profile_Manager">Firefox Profile Manager</a>.</p>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/e-signature/'>e-signature</a>, <a href='http://blog.famzah.net/tag/firefox/'>firefox</a>, <a href='http://blog.famzah.net/tag/infonotary/'>infonotary</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/424/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=424&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/02/08/firefox-crashes-with-terminate-called-after-throwing-an-instance-of-std-bad_alloc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;dd&#8221; sequential write performance tests on a raw block device may be incorrect</title>
		<link>http://blog.famzah.net/2010/02/05/dd-sequential-write-performance-tests-on-a-raw-block-device-may-be-incorrect/</link>
		<comments>http://blog.famzah.net/2010/02/05/dd-sequential-write-performance-tests-on-a-raw-block-device-may-be-incorrect/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 12:23:36 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[block device block size]]></category>
		<category><![CDATA[dd benchmark]]></category>
		<category><![CDATA[disk write performance benchmark]]></category>
		<category><![CDATA[iostat]]></category>
		<category><![CDATA[linux performance]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=407</guid>
		<description><![CDATA[&#8230;if you use the inappropriate bytes size (bs) option. See the man page of dd for details on this option. Hard disks have a typical block size of 512 bytes. LVM on the other hand creates its block devices with a block size of 4096 bytes. So it&#8217;s easy to get confused &#8211; even if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=407&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230;if you use the inappropriate bytes size (bs) option. See the <a href="http://linux.die.net/man/1/dd">man page of dd</a> for details on this option.</p>
<p>Hard disks have a typical block size of 512 bytes. <a href="http://sourceware.org/lvm2/">LVM</a> on the other hand creates its block devices with a block size of 4096 bytes. So it&#8217;s easy to get confused &#8211; even if you know that disks should be tested with blocks of 512 bytes, you shouldn&#8217;t test LVM block devices with a 512-bytes but with a 4096-bytes block size.</p>
<p><u>What happens if you make a write performance test by writing directly on the raw block device and you use the wrong bytes size (bs) option?</u></p>
<p>If you look at the &#8220;<a href="http://linux.die.net/man/1/iostat">iostat</a>&#8221; statistics, they will show lots of read requests too, when you are only writing. This is not what is expected when you do <strong>only</strong> writing.<br />
The problem comes by the fact that when you are not using the proper block size for the raw block device, instead of writing whole blocks, you are writing partial blocks. This is however physically not possible &#8211; the block device can only write one <strong>whole</strong> block at a time. In order to update the data in only a part of a block, this block needs to be read back first, then modified with the new partial data in memory and finally written back as a whole block.</p>
<p>The <strong>total performance drop</strong> is about 3 times on the systems I tested. I&#8217;ve tested this on some hard disks and on an <a href="http://www.areca.com.tw/">Areca</a> RAID-6 volume.</p>
<p><u>So what&#8217;s the lesson here?</u></p>
<p>When you do sequential write performance tests with &#8220;dd&#8221; directly on the raw block device, make sure that you use the proper bytes size option, and verify that during the tests you see <strong>only</strong> write requests in the &#8220;<a href="http://linux.die.net/man/1/iostat">iostat</a>&#8221; statistics.</p>
<p><u>Physical hard disk example:</u></p>
<div class="sourcecode">
<pre class="brush: bash; light: true;">
# Here is a bad example for a hard disk device
dd if=/dev/zero of=/dev/sdb1 bs=256 count=5000000

# Here is the proper usage, because /dev/sda physical block size is 512 bytes
dd if=/dev/zero of=/dev/sdb1 bs=512 count=5000000 
</pre>
</div>
<p><u>LVM block device example:</u></p>
<div class="sourcecode">
<pre class="brush: bash; light: true;">
# Another bad example, this time for an LVM block device
dd if=/dev/zero of=/dev/sdb-vol/test bs=512 count=1000000

# Here is the proper usage, because the LVM block size is 4096 bytes
dd if=/dev/zero of=/dev/sdb-vol/test bs=4k count=1000000
</pre>
</div>
<p><u>Understanding the &#8220;<a href="http://linux.die.net/man/1/iostat">iostat</a>&#8221; output during a &#8220;dd&#8221; test:</u></p>
<p>Here is what &#8220;<a href="http://linux.die.net/man/1/iostat">iostat</a>&#8221; displays when you are <strong>not</strong> using the proper bytes size option (lots of read &#8220;r/s&#8221; and &#8220;rsec/s&#8221; requests):</p>
<div class="sourcecode">
<pre class="brush: plain; light: true; wrap-lines: false;">
Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sdb               0.00  5867.40 3573.20   46.40 28585.60 47310.40 20.97   110.38   30.61   0.28 100.00
sdb1              0.00     0.00    0.00    0.00     0.00     0.00 0.00     0.00    0.00   0.00   0.00
sdb2              0.00  5867.40 3572.80   46.40 28582.40 47310.40 20.97   110.38   30.61   0.28 100.00
dm-2              0.00     0.00 3572.80 5913.80 28582.40 47310.40 8.00 13850.92 1465.43   0.11 100.00 
</pre>
</div>
<p>Here is what it should display (no read &#8220;r/s&#8221; or &#8220;rsec/s&#8221; requests at all):</p>
<div class="sourcecode">
<pre class="brush: plain; light: true; wrap-lines: false;">
Device:         rrqm/s   wrqm/s     r/s     w/s   rsec/s   wsec/s avgrq-sz avgqu-sz   await  svctm  %util
sdb               0.00 16510.00    0.00  128.60     0.00 131686.40 1024.00   107.82  840.32   7.78 100.00
sdb1              0.00     0.00    0.00    0.00     0.00     0.00 0.00     0.00    0.00   0.00   0.00
sdb2              0.00 16510.00    0.00  128.60     0.00 131686.40 1024.00   107.82  840.32   7.78 100.00
dm-2              0.00     0.00    0.00 16640.00     0.00 133120.00 8.00 13674.86  823.73   0.06 100.00 
</pre>
</div>
<p><u>How to be safe?</u></p>
<p>Fortunately, file systems are smart enough and pay attention to the block size of the block devices they were mounted on. So if you do a &#8220;<a href="http://linux.die.net/man/1/dd">dd</a>&#8221; write performance test and write to a file, you should be fine. Though in this case there are some other complications like journaling, commit intervals, barriers, mount options, etc.</p>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/block-device-block-size/'>block device block size</a>, <a href='http://blog.famzah.net/tag/dd-benchmark/'>dd benchmark</a>, <a href='http://blog.famzah.net/tag/disk-write-performance-benchmark/'>disk write performance benchmark</a>, <a href='http://blog.famzah.net/tag/iostat/'>iostat</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/linux-performance/'>linux performance</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/407/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/407/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/407/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=407&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/02/05/dd-sequential-write-performance-tests-on-a-raw-block-device-may-be-incorrect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Why /sys/block/dm-0/queue/scheduler exists on my Linux system?</title>
		<link>http://blog.famzah.net/2010/01/25/why-sys-block-dm-0-queue-scheduler-exists-on-my-linux-system/</link>
		<comments>http://blog.famzah.net/2010/01/25/why-sys-block-dm-0-queue-scheduler-exists-on-my-linux-system/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 11:01:23 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[device-mapper]]></category>
		<category><![CDATA[dm]]></category>
		<category><![CDATA[I/O scheduler]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=359</guid>
		<description><![CDATA[The device-mapper (DM) traditionally didn&#8217;t have its own I/O scheduler. Then why suddenly my DM devices have such a scheduler and what does it control? A new type of device-mapper was introduced recently in the Linux kernel 2.6.31 &#8211; the request-based device-mapper. According to the Linux Kernel Newbies changelog for 2.6.31, there is a commit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=359&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The device-mapper (DM) traditionally didn&#8217;t have its own I/O scheduler. Then why suddenly my DM devices have such a scheduler and what does it control?</p>
<hr />
<p>A new type of device-mapper was introduced recently in the Linux kernel 2.6.31 &#8211; the <strong>request-based device-mapper</strong>. According to the <a href="http://kernelnewbies.org/Linux_2_6_31">Linux Kernel Newbies changelog for 2.6.31</a>, there is a <a href="http://git.kernel.org/linus/cec47e3d4a861e1d942b3a580d0bbef2700d2bb2">commit</a> which does &#8220;Prepare for request based option&#8221;.</p>
<p>The issue is actually not in the new request-based DM option, which is to be used <strong>only for <a href="http://www.redhat.com/docs/manuals/csgfs/browse/4.6/DM_Multipath/MPIO_description.html">multipath block devices</a></strong>. The problem is that when you create a regular LVM device on kernels 2.6.31+, the DM device itself has I/O scheduler parameters. So does the underlying block device on top of which you created the LVM. Thus we are having <strong>two</strong> I/O schedulers in the path from the LVM device to the physical storage. </p>
<p>According to the author of the kernel patches for the request-based DM device, Kiyoshi Ueda, for a bio-based DM device, only the underlying device&#8217;s scheduler should affect performance. This is what my tests shown too, therefore there is no discrepancy.</p>
<p>Let me summarize this:</p>
<ul>
<li>If you are *not* using multipath block devices in your DM/LVM setup, then only the underlying device&#8217;s scheduler (i.e. &#8220;/sys/block/sda/queue/scheduler&#8221;) takes effect. This applies for the trivial LVM setup which many of us used for years.</li>
<li>If you are using a multipath DM/LVM setup, then only the DM device&#8217;s scheduler (i.e. &#8220;/sys/block/dm-0/queue/scheduler&#8221;) takes effect.</li>
</ul>
<hr />
<p>References:</p>
<ul>
<li><a href="http://www.kernel.org/doc/ols/2007/ols2007v2-pages-235-244.pdf">Request-based Device-mapper multipath and Dynamic load balancing</a> PDF paper by Kiyoshi Ueda, Jun&#8217;ichi Nomura, and Mike Christie. You can also <a href="http://famzah.files.wordpress.com/2010/02/ols2007v2-pages-235-244.pdf">download my copy of this PDF</a>.
<li><a href="http://www.redhat.com/docs/manuals/csgfs/browse/4.6/DM_Multipath/index.html">Using Device-Mapper Multipath</a> by RedHat.</li>
</ul>
<br />Posted in Linux Tagged: device-mapper, dm, I/O scheduler, Linux, lvm, performance <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/359/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/359/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/359/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/359/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/359/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/359/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/359/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/359/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/359/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/359/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/359/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/359/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/359/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/359/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=359&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/01/25/why-sys-block-dm-0-queue-scheduler-exists-on-my-linux-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
	</channel>
</rss>
