<?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</title>
	<atom:link href="http://blog.famzah.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.famzah.net</link>
	<description>Enthusiasm never stops</description>
	<lastBuildDate>Tue, 18 Jun 2013 14:56:24 +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</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>Google Reader alternative</title>
		<link>http://blog.famzah.net/2013/06/10/google-reader-alternative/</link>
		<comments>http://blog.famzah.net/2013/06/10/google-reader-alternative/#comments</comments>
		<pubDate>Mon, 10 Jun 2013 10:05:13 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[google reader]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[rss reader]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1320</guid>
		<description><![CDATA[Google announced that they are shutting down their online web RSS reader on July 1, 2013. What a shame, it was really useful and with a great web design. After short research, I decided to code one &#8212; for fun and education. It&#8217;s designed to operate in a multi-user way, so if you want to [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1320&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Google <a href="http://googleblog.blogspot.com/2013/03/a-second-spring-of-cleaning.html">announced</a> that they are shutting down their online web RSS reader on July 1, 2013. What a shame, it was really useful and with a great web design.</p>
<p>After short research, I decided to code one &#8212; for fun and education. It&#8217;s designed to operate in a multi-user way, so if you want to give it a try, go on!</p>
<p>My online implementation is named &#8220;<strong>xs RSS reader</strong>&#8220;, short for extra-simple RSS reader:</p>
<p><a href="http://www.famzah.net/xs-rss-reader/" rel="nofollow">http://www.famzah.net/xs-rss-reader/</a></p>
<p>Here is a sample demo screenshot:<br />
<a href="http://www.famzah.net/xs-rss-reader/"><img height='254' width='546' src="http://www.famzah.net/xs-rss-reader/img/demo/rss-reader-screenshot-thumbnail.jpg" alt="xs RSS reader -- demo screenshot" /></a></p>
<br />Filed under: <a href='http://blog.famzah.net/category/development/'>Development</a> Tagged: <a href='http://blog.famzah.net/tag/free/'>free</a>, <a href='http://blog.famzah.net/tag/google-reader/'>google reader</a>, <a href='http://blog.famzah.net/tag/rss/'>rss</a>, <a href='http://blog.famzah.net/tag/rss-reader/'>rss reader</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1320/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1320&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2013/06/10/google-reader-alternative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>

		<media:content url="http://www.famzah.net/xs-rss-reader/img/demo/rss-reader-screenshot-thumbnail.jpg" medium="image">
			<media:title type="html">xs RSS reader -- demo screenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>Nagios: Improve CPU performance with popen_noshell()</title>
		<link>http://blog.famzah.net/2013/05/28/nagios-improve-cpu-performance-with-popen_noshell/</link>
		<comments>http://blog.famzah.net/2013/05/28/nagios-improve-cpu-performance-with-popen_noshell/#comments</comments>
		<pubDate>Tue, 28 May 2013 12:07:15 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nagios]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[popen_noshell]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1300</guid>
		<description><![CDATA[Today I&#8217;ll share my real-world experience with popen_noshell() on the Nagios monitoring server which we run at work. We are actively monitoring 1166 hosts and 14250 services. The machine has 6 GB RAM and a single Intel Core i7-950 CPU with enabled multi-threading (8 total threads) and slight overclock. Besides running Nagios, this machine also [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1300&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Today I&#8217;ll share my real-world experience with <a href="https://code.google.com/p/popen-noshell/">popen_noshell()</a> on the Nagios monitoring server which we run at work. We are actively monitoring 1166 hosts and 14250 services. The machine has 6 GB RAM and a single Intel Core i7-950 CPU with enabled multi-threading (8 total threads) and slight overclock. Besides running Nagios, this machine also handles the incoming data from our custom monitoring systems, processes RRD database storage, and generates web interface status + charts output. So it&#8217;s a pretty busy machine which does a lot of network activity and where the Nagios daemon is just a part of the CPU load. For example, since boot the main &#8220;nagios3&#8243; process has used only 20% of the CPU. The other part has been used by the fork()&#8217;ed Perl scripts (we use a lot of them for the active checks), the Nagios standard network checks, and the Apache/PHP web server handling the incoming data.</p>
<p>Recently the machine started to exhaust its CPU resources. First we overclocked it a bit which gave us 10% more CPU idle time. Then we decided to try to compile Nagios with the <a href="https://code.google.com/p/popen-noshell/">popen-noshell</a> library. This gave us another 10% CPU idle and now the machine is working great again.</p>
<p>I&#8217;ll focus on the popen-noshell integration and results, since CPU overclocking is a well-known topic. Here is the chart which shows the CPU usage before and after we re-compiled Nagios with the popen-noshell library:<br />
<br />
<a href="http://famzah.files.wordpress.com/2013/05/nagios-popen-noshell-benchmark-results.jpg"><img src="http://famzah.files.wordpress.com/2013/05/nagios-popen-noshell-benchmark-results.jpg?w=450&#038;h=156" alt="nagios-popen-noshell-benchmark-results" width="450" height="156" class="aligncenter size-large wp-image-1301" /></a></p>
<p>As we can see, the system-CPU usage dropped from 38% to 31%, which is an 18% improvement. The user-CPU usage dropped from 44% to 41%, which is a 7% improvement. Overall, we gained a 12% speed-up for our workload by just re-compiling Nagios with the popen-noshell library. I&#8217;m stressing out that the speed-up depends a lot on your workload. If this machine was busy only with Nagios and the active checks were more CPU efficient (i.e. not written in Perl but in C), then the speed-up could have been much higher, since popen_noshell() is about <a href="http://blog.famzah.net/2009/11/20/a-much-faster-popen-and-system-implementation-for-linux/">10 times faster</a> than the standard popen().</p>
<p>A list with the other machine metrics which were also affected by the workload change:</p>
<ul>
<li>Used memory: 39% =&gt; 24% (38% less)</li>
<li>Load average: 39 =&gt; 46 (18% higher)</li>
<li>Forks rates: 8*61 =&gt; 8*61 (created processes/second &#8211; no change)</li>
</ul>
<p>Here are the steps that you need to perform, in order to re-compile the Nagios Debian package by integrating it with the popen-noshell library:</p>
<div class="sourcecode">
<pre class="brush: bash; title: ; notranslate">
apt-get install devscripts

apt-get build-dep nagios3-core
# No need to run as &quot;root&quot; from here on
apt-get source nagios3-core

svn checkout http://popen-noshell.googlecode.com/svn/trunk/ popen-noshell

cd nagios3-3.2.1/

# BEGIN: patch Nagios to use popen_noshell_compat()

cp ../popen-noshell/popen_noshell.* base/
vi base/Makefile.in
	OBJS=$(BROKER_O) popen_noshell.o 

vi base/utils.c
	#include &quot;popen_noshell.h&quot;
	
        /* run the command */
        struct popen_noshell_pass_to_pclose pclose_arg;
        fp=(FILE *)popen_noshell_compat(cmd,&quot;r&quot;,&amp;pclose_arg);

            /* close the command and get termination status */
            status=pclose_noshell(&amp;pclose_arg);

vi base/checks.c
	2x the same as above

# END: patch Nagios to use popen_noshell_compat()

EDITOR=vim dch -i
	# 3.2.1-2+squeeze1 -&gt; 3.2.1-2+squeeze1-noshell1
	# you must have a trailing number in the added version name
	# after exit, this renames the original directory name

cd ..
mv nagios3_3.2.1.orig.tar.gz nagios3_3.2.1-2+squeeze1.orig.tar.gz

# the source directory was renamed by &quot;dch&quot;
cd nagios3-3.2.1-2+squeeze1/
DEB_BUILD_OPTIONS=nocheck debuild -us -uc

cd ..
sudo dpkg -i nagios3-core_3.2.1-2+squeeze1-noshell1_i386.deb \
	nagios3-common_3.2.1-2+squeeze1-noshell1_all.deb \
	nagios3-cgi_3.2.1-2+squeeze1-noshell1_i386.deb \
	nagios3-doc_3.2.1-2+squeeze1-noshell1_all.deb \
	nagios3_3.2.1-2+squeeze1-noshell1_i386.deb
</pre>
</div>
<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/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/nagios/'>Nagios</a>, <a href='http://blog.famzah.net/tag/performance/'>performance</a>, <a href='http://blog.famzah.net/tag/popen_noshell/'>popen_noshell</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1300&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2013/05/28/nagios-improve-cpu-performance-with-popen_noshell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.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/2013/05/nagios-popen-noshell-benchmark-results.jpg?w=450" medium="image">
			<media:title type="html">nagios-popen-noshell-benchmark-results</media:title>
		</media:content>
	</item>
		<item>
		<title>An &#8220;xargs&#8221; alternative to GNU Parallel</title>
		<link>http://blog.famzah.net/2013/04/04/an-xargs-alternative-to-gnu-parallel/</link>
		<comments>http://blog.famzah.net/2013/04/04/an-xargs-alternative-to-gnu-parallel/#comments</comments>
		<pubDate>Thu, 04 Apr 2013 11:36:33 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[GNU Parallel]]></category>
		<category><![CDATA[parallel command execution]]></category>
		<category><![CDATA[xargs]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1280</guid>
		<description><![CDATA[I wanted to use GNU Parallel on my Ubuntu system, in order to process some data in parallel. It turned out that there is no official package for Ubuntu. As of Ubuntu Quantal released on April/2014, this has been corrected and the package is in the official repository. Reading a bit more brought me to [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1280&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I wanted to use <a href="http://www.gnu.org/software/parallel/man.html">GNU Parallel</a> on my Ubuntu system, in order to process some data in parallel. It turned out that there is <a href="http://askubuntu.com/questions/12764/where-do-i-get-a-package-for-gnu-parallel">no official package</a> for Ubuntu. As of Ubuntu Quantal released on April/2014, this has been corrected and the package is in the <a href="http://packages.ubuntu.com/search?keywords=parallel">official repository</a>.</p>
<p>Reading a bit more brought me to the astonishing fact that &#8220;<a href="http://linux.die.net/man/1/xargs">xargs</a>&#8221; can run commands in parallel. The &#8220;xargs&#8221; utility is something I use every day and this parallelism feature made it even more useful.</p>
<p>Let&#8217;s try it by running the following:</p>
<div class="sourcecode">
<pre class="brush: bash; title: ; notranslate">
famzah@vbox:~$ echo 10 20 30 40 50 60 | xargs -n 1 -P 4 sleep
</pre>
</div>
<p>The use of &#8220;-n 1&#8243; is vital if you want to pass only one command-line argument from the list to each parallel process.</p>
<p>Here is the result:</p>
<div class="sourcecode">
<pre class="brush: bash; title: ; notranslate">
# right after we launched &quot;xargs&quot;
famzah@vbox:~$ ps f -o pid,command
  PID COMMAND
 5068 /bin/bash
 7007  \_ xargs -n 1 -P 4 sleep
 7008      \_ sleep 10
 7009      \_ sleep 20
 7010      \_ sleep 30
 7011      \_ sleep 40

# 10 seconds later (the first &quot;sleep&quot; has just exited)
famzah@vbox:~$ ps f -o pid,command
  PID COMMAND
 5068 /bin/bash
 7007  \_ xargs -n 1 -P 4 sleep
 7009      \_ sleep 20
 7010      \_ sleep 30
 7011      \_ sleep 40
 7017      \_ sleep 50

# 20 seconds later (the second and third &quot;sleep&quot; commands have exited)
# we now have only 3 simultaneous processes (no more arguments to process)
famzah@vbox:~$ ps f -o pid,command
  PID COMMAND
 5068 /bin/bash
 7007  \_ xargs -n 1 -P 4 sleep
 7011      \_ sleep 40
 7017      \_ sleep 50
 7023      \_ sleep 60
</pre>
</div>
<p>It&#8217;s worth mentioning that if &#8220;xargs&#8221; fails to execute the binary, it prematurely terminates the failed parallel processing queue, which leaves some of the stdin arguments not processed:</p>
<div class="sourcecode">
<pre class="brush: bash; title: ; notranslate">
famzah@vbox:~$ echo 10 20 30 40 50 60 | xargs -n 1 -P 4 badexec-name
xargs: badexec-namexargs: badexec-name: No such file or directory: No such file or directory

xargs: badexec-namexargs: badexec-name: No such file or directory
: No such file or directory
</pre>
</div>
<p>The output is scrambled because all parallel processes write to the screen with no locking synchronization. This seems to be a <a href="http://savannah.gnu.org/bugs/?38356">known issue</a>. The point is that we could expect that &#8220;xargs&#8221; would try to execute &#8220;badexec-name&#8221; for every command-line argument (total of six attempts in our example). It turns out that &#8220;xargs&#8221; bails out the same way even if we don&#8217;t use the &#8220;-P&#8221; option:</p>
<div class="sourcecode">
<pre class="brush: bash; title: ; notranslate">
# standard usage of &quot;xargs&quot;
famzah@vbox:~$ echo 10 20 30 40 50 60 | xargs -n 1 badexec-name
xargs: badexec-name: No such file or directory
</pre>
</div>
<p>Not a very cool behavior. I&#8217;ve reported this as a <a href="https://savannah.gnu.org/bugs/index.php?38658">bug</a> to the GNU community. If you review the responses to the bug report, you will find out that this actually is an intended feature. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If the provided command to &#8220;xargs&#8221; is a valid one but it fails during the execution, there are no surprises and &#8220;xargs&#8221; continues with the next command-line argument by executing a new command:</p>
<div class="sourcecode">
<pre class="brush: bash; title: ; notranslate">
famzah@vbox:~$ echo 10 20 30 40 50 60 | xargs -n 1 -P 4 rm
rm: rm: cannot remove `10'cannot remove `40': No such file or directory
: No such file or directory
rm: cannot remove `20': No such file or directory
rm: cannot remove `30': No such file or directory
rm: cannot remove `60': No such file or directory
rm: cannot remove `50': No such file or directory
</pre>
</div>
<p>The output here is scrambled too because all parallel processes write to the screen with no locking synchronization. We see however that all command-line arguments from &#8220;10&#8243; to &#8220;60&#8243; were processed by executing a command for each of them.</p>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/gnu-parallel/'>GNU Parallel</a>, <a href='http://blog.famzah.net/tag/parallel-command-execution/'>parallel command execution</a>, <a href='http://blog.famzah.net/tag/xargs/'>xargs</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1280/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1280/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1280&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2013/04/04/an-xargs-alternative-to-gnu-parallel/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Bash: Split a string into columns by white-space without invoking sub-shells</title>
		<link>http://blog.famzah.net/2013/02/17/bash-split-a-string-into-columns-by-white-space-without-invoking-sub-shells/</link>
		<comments>http://blog.famzah.net/2013/02/17/bash-split-a-string-into-columns-by-white-space-without-invoking-sub-shells/#comments</comments>
		<pubDate>Sun, 17 Feb 2013 07:28:48 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1272</guid>
		<description><![CDATA[The classical approach is: Processing thousands of lines this way however fork()&#8217;s thousands of processes, which affects performance and makes your script CPU hungry. Here is the effective solution which I found with my colleagues at work: Here is an example: If you want to split not by white-space but by any other character, you [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1272&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The classical approach is:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
RESULT=&quot;$(echo &quot;$LINE&quot;| awk '{print $1}')&quot; # executes in a sub-shell 
</pre>
</div>
<p>Processing thousands of lines this way however fork()&#8217;s thousands of processes, which affects performance and makes your script CPU hungry.</p>
<p>Here is the effective solution which I found with my colleagues at work:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
COLS=( $LINE ); # parses columns without executing a sub-shell
RESULT=&quot;${COLS[0]}&quot;; # returns first column (0-based indexes)
</pre>
</div>
<p>Here is an example:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
LINE=&quot;col0 col1  col2     col3  col4      &quot; # white-space including tab chars
COLS=( $LINE ); # parses columns without executing a sub-shell

echo &quot;${COLS[0]}&quot;; # prints &quot;col0&quot;
echo &quot;${COLS[1]}&quot;; # prints &quot;col1&quot;
echo &quot;${COLS[2]}&quot;; # prints &quot;col2&quot;
echo &quot;${COLS[3]}&quot;; # prints &quot;col3&quot;
echo &quot;${COLS[4]}&quot;; # prints &quot;col4&quot;
</pre>
</div>
<p>If you want to split not by white-space but by any other character, you can temporarily change the <a href="http://tldp.org/LDP/abs/html/internalvariables.html">IFS</a> variable which determines how Bash recognizes fields and word boundaries.</p>
<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/awk/'>awk</a>, <a href='http://blog.famzah.net/tag/bash/'>bash</a>, <a href='http://blog.famzah.net/tag/fork/'>fork</a>, <a href='http://blog.famzah.net/tag/performance/'>performance</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1272/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1272/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1272&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2013/02/17/bash-split-a-string-into-columns-by-white-space-without-invoking-sub-shells/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Re-compile a Debian kernel as a .deb package</title>
		<link>http://blog.famzah.net/2012/10/07/re-compile-a-debian-kernel-as-a-deb-package/</link>
		<comments>http://blog.famzah.net/2012/10/07/re-compile-a-debian-kernel-as-a-deb-package/#comments</comments>
		<pubDate>Sun, 07 Oct 2012 10:09:04 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[.deb package]]></category>
		<category><![CDATA[build .deb]]></category>
		<category><![CDATA[ccache]]></category>
		<category><![CDATA[compile linux kernel]]></category>
		<category><![CDATA[custom linux kernel]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1256</guid>
		<description><![CDATA[Here is my success story on how to re-compile a Debian/Ubuntu kernel, in order to enable or tune kernel features which are not available as kernel modules: Filed under: Linux Tagged: .deb package, build .deb, ccache, compile linux kernel, custom linux kernel, debian, ubuntu<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1256&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Here is my success story on how to re-compile a Debian/Ubuntu kernel, in order to enable or tune kernel features which are not available as kernel modules:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
# Install required software for the kernel compilation
apt-get install fakeroot build-essential devscripts
apt-get build-dep linux-image-$(uname -r) # make sure you have the appropriate &quot;deb-src&quot; in &quot;sources.list&quot;
apt-get install libncurses5-dev # required for &quot;make menuconfig&quot;
apt-get install ccache # to re-compile the kernel faster (http://wiki.debian.org/OverridingDSDT)

# Prepare some environent variables for our architecture, for later use
ARCH=$(uname -r|cut -d- -f3)
CPUCNT=$(( $(cat /proc/cpuinfo |egrep ^processor |wc -l) * 2))

# Get the kernel sources
rm -rf /root/krebuild &amp;&amp; mkdir /root/krebuild
cd /root/krebuild
apt-get source linux-image-$(uname -r)
cd linux-$(uname -r|cut -d- -f1|cut -d. -f1-2)* # cd linux-3.2.20

# http://kernel-handbook.alioth.debian.org/ch-common-tasks.html # 4.2.5 Building packages for one flavour
# The target in this command has the general form of target_arch_featureset_flavour. Replace the featureset with none if you do not want any of the extra featuresets.

# Prepare a Debian kernel to compile
fakeroot make -f debian/rules.gen setup_${ARCH}_none_${ARCH} &gt;/dev/null
cd debian/build/build_${ARCH}_none_${ARCH}
make menuconfig # make any kernel config changes now
cd ../../..

# No debug info =&gt; faster kernel build
perl -pi -e 's/debug-info:\s+true/debug-info: false/' debian/config/$ARCH/defines
echo binary-arch_${ARCH}_none_${ARCH}
vi debian/rules.gen # find the Make target and change DEBUG and DEBUG_INFO to False/n respectively

# Bugfix: http://lists.debian.org/debian-user/2008/02/msg01455.html
vi debian/bin/buildcheck.py +51 # add &quot;return 0&quot; right after &quot;def __call__(self, out):&quot;

# Compile the kernel
time DEBIAN_KERNEL_USE_CCACHE=true DEBIAN_KERNEL_JOBS=$CPUCNT \
	fakeroot make -j$CPUCNT -f debian/rules.gen binary-arch_${ARCH}_none_${ARCH} &gt; compile-progress.log

# If needed, the linux-headers-version-common binary package (http://kernel-handbook.alioth.debian.org/ch-common-tasks.html -&gt; 4.2.5)
#fakeroot make -j$CPUCNT -f debian/rules.gen binary-arch_${ARCH}_none_real

# Install the newly compiled kernel
cd ..
dpkg -i linux-image-*.deb
#dpkg -i linux-headers-*.deb # only if you need them and/or have them installed already
</pre>
</div>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/deb-package/'>.deb package</a>, <a href='http://blog.famzah.net/tag/build-deb/'>build .deb</a>, <a href='http://blog.famzah.net/tag/ccache/'>ccache</a>, <a href='http://blog.famzah.net/tag/compile-linux-kernel/'>compile linux kernel</a>, <a href='http://blog.famzah.net/tag/custom-linux-kernel/'>custom linux kernel</a>, <a href='http://blog.famzah.net/tag/debian/'>debian</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/1256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1256/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1256&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2012/10/07/re-compile-a-debian-kernel-as-a-deb-package/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Perl Net::Ping not working properly with ICMP by default</title>
		<link>http://blog.famzah.net/2012/06/24/perl-netping-not-working-properly-with-icmp-by-default/</link>
		<comments>http://blog.famzah.net/2012/06/24/perl-netping-not-working-properly-with-icmp-by-default/#comments</comments>
		<pubDate>Sun, 24 Jun 2012 09:58:10 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[icmp ping]]></category>
		<category><![CDATA[Net::Ping]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[tcpdump]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1238</guid>
		<description><![CDATA[If you tried to ping a host with Perl Net::Ping using the ICMP protocol and that failed, even though the &#8220;ping&#8221; command-line utility can ping the host, you&#8217;re not alone I had the same problem and it turned out to be due to the fact that Net::Ping by default sends no DATA in the ICMP [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1238&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If you tried to <a href="http://en.wikipedia.org/wiki/Ping">ping</a> a host with Perl <a href="http://perldoc.perl.org/Net/Ping.html">Net::Ping</a> using the ICMP protocol and that failed, even though the &#8220;ping&#8221; command-line utility can ping the host, you&#8217;re not alone <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I had the same problem and it turned out to be due to the fact that Net::Ping by default sends no DATA in the ICMP request and thus its requests are rather short and non-standard. Here are some <a href="http://en.wikipedia.org/wiki/Tcpdump">tcpdump</a> examples:</p>
<ul>
<li>Net::Ping with ICMP protocol, everything else is defaults: &#8220;<strong>$p = new Net::Ping(&#8216;icmp&#8217;)</strong>&#8220;, no replies from remote host, note that the length is just 8 bytes:<br />
<code><br />
12:29:02.898083 IP source-addr &gt; source-addr: ICMP echo request, id 2194, seq 41, length 8<br />
12:29:03.711595 IP source-addr &gt; dest-addr: ICMP echo request, id 2194, seq 42, length 8<br />
</code>
</li>
<li>Linux &#8220;<strong>ping</strong>&#8221; command-line utility, remote host replies accordingly, the length is 64 bytes total:<br />
<code><br />
12:30:18.278865 IP source-addr &gt; dest-addr: ICMP echo request, id 2488, seq 1, length 64<br />
12:30:18.289922 IP dest-addr &gt; source-addr: ICMP echo reply, id 2488, seq 1, length 64<br />
12:30:18.790610 IP source-addr &gt; dest-addr: ICMP echo request, id 2488, seq 2, length 64<br />
12:30:18.811029 IP dest-addr &gt; source-addr: ICMP echo reply, id 2488, seq 2, length 64<br />
</code></li>
<li>Net::Ping with ICMP protocol with user-defined length, &#8220;<strong>$p = new Net::Ping(&#8216;icmp&#8217;, 1, 56)</strong>&#8220;, remote host replies accordingly, the length is 64 bytes total:<br />
<code><br />
12:30:48.377496 IP source-addr &gt; dest-addr: ICMP echo request, id 2488, seq 6, length 64<br />
12:30:48.433690 IP dest-addr &gt; source-addr: ICMP echo reply, id 2488, seq 6, length 64<br />
12:30:48.934310 IP source-addr &gt; dest-addr: ICMP echo request, id 2488, seq 7, length 64<br />
12:30:48.946152 IP dest-addr &gt; source-addr: ICMP echo reply, id 2488, seq 7, length 64<br />
</code>
</ul>
<p>Bottom line is that if you are going to use Net::Ping with ICMP, specify 56 for the &#8220;bytes&#8221; parameter when creating an instance of the Net::Ping object. This way you will be sending standard ICMP requests with total lenght of 64 bytes.</p>
<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/icmp-ping/'>icmp ping</a>, <a href='http://blog.famzah.net/tag/netping/'>Net::Ping</a>, <a href='http://blog.famzah.net/tag/perl/'>perl</a>, <a href='http://blog.famzah.net/tag/tcpdump/'>tcpdump</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1238/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1238&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2012/06/24/perl-netping-not-working-properly-with-icmp-by-default/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Securely avoid SSH warnings for changing IP addresses</title>
		<link>http://blog.famzah.net/2012/05/15/securely-avoid-ssh-warnings-for-changing-ip-addresses/</link>
		<comments>http://blog.famzah.net/2012/05/15/securely-avoid-ssh-warnings-for-changing-ip-addresses/#comments</comments>
		<pubDate>Tue, 15 May 2012 07:10:20 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[amazon aws]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[openssh]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1230</guid>
		<description><![CDATA[If you have servers that change their IP address, you&#8217;ve probably already been used to the following SSH warning: Besides from being annoying, it is also a security risk to blindly accept this warning and continue connecting. And be honest &#8212; almost none of us check the fingerprint in advance every time. A common scenario [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1230&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>If you have servers that change their IP address, you&#8217;ve probably already been used to the following SSH warning:</p>
<div class="sourcecode">
<pre class="brush: plain; gutter: false; title: ; notranslate">
The authenticity of host '176.34.91.245 (176.34.91.245)' can't be established.
...
Are you sure you want to continue connecting (yes/no)? yes
</pre>
</div>
<p>Besides from being annoying, it is also a security risk to blindly accept this warning and continue connecting. And be honest &#8212; almost none of us check the fingerprint in advance every time.</p>
<p>A common scenario for this use case is when you have an EC2 server in Amazon AWS which you temporarily stop and then start, in order to cut costs. I have a backup server which I use in this way.</p>
<p>In order to securely avoid this SSH warning and still be sure that you connect to your trusted server, you have to save the fingerprint in a separate file and update the IP address in it every time before you connect. Here are the connect commands, which you can also encapsulate in a Bash wrapper script:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
IP=176.34.91.245 # use an IP address here, not a hostname
FPFILE=~/.ssh/aws-backup-server.fingerprint

test -e &quot;$FPFILE&quot; &amp;&amp; perl -pi -e &quot;s/^\S+ /$IP /&quot; &quot;$FPFILE&quot;
ssh -o StrictHostKeyChecking=ask -o UserKnownHostsFile=&quot;$FPFILE&quot; root@$IP
</pre>
</div>
<p>Note that the FPFILE is not required to exist on the first SSH connect. The first time you connect to the server, the FPFILE will be created when you accept the SSH warning. Further connects will not show an SSH warning or ask you to accept the fingerprint again.</p>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/amazon-aws/'>amazon aws</a>, <a href='http://blog.famzah.net/tag/ec2/'>ec2</a>, <a href='http://blog.famzah.net/tag/openssh/'>openssh</a>, <a href='http://blog.famzah.net/tag/security/'>security</a>, <a href='http://blog.famzah.net/tag/ssh/'>ssh</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1230&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2012/05/15/securely-avoid-ssh-warnings-for-changing-ip-addresses/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>iSCSI-over-Internet performance notes</title>
		<link>http://blog.famzah.net/2012/04/17/iscsi-over-internet-performance-notes/</link>
		<comments>http://blog.famzah.net/2012/04/17/iscsi-over-internet-performance-notes/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 15:17:33 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[iSCSI]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1212</guid>
		<description><![CDATA[I recently played a bit with iSCSI over Internet, in order to design and implement the Locally encrypted secure remote backup over Internet. My initial impression was that iSCSI over Internet is not usable as a backup device even though my Internet connection is relatively fast &#8212; a simple ext4 file-system format took about 24 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1212&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I recently played a bit with <a href="http://en.wikipedia.org/wiki/ISCSI">iSCSI</a> over Internet, in order to design and implement the <a href="http://blog.famzah.net/2012/04/17/locally-encrypted-secure-remote-backup-over-internet-on-linux-iscsi-truecrypt/">Locally encrypted secure remote backup over Internet</a>.</p>
<p>My initial impression was that iSCSI over Internet is not usable as a backup device even though my Internet connection is relatively fast &#8212; a simple ext4 file-system format took about 24 minutes. I though that the connection latency is killing the performance. Well, I was wrong. Even after making latency two times lower by working on a server which was geographically closer, the ext4 format still took 24 minutes.</p>
<p>Eventually I did some tests and analysis, and finally started to use the iSCSI over Internet volume for backup purposes &#8212; and it works flawlessly so far.</p>
<h3>Ext4 format benchmark</h3>
<p>It turns out that it&#8217;s not the <strong>latency</strong> but my upload <strong>bandwidth</strong> which was slowing things down:</p>
<ul>
<li><strong>1 Mbit/s upload</strong> Internet connection and <a href="http://en.wikipedia.org/wiki/Ping">Ping</a> latency of 75 ms:
<ul>
<li>Time: 24 minutes.</li>
<li>Average transfer rates snapshot:
<ul>
<li>Total rates: 967.7 kbits/sec (212.6 packets/sec).</li>
<li>Incoming rates: 83.0 kbits/sec (92.8 packets/sec).</li>
<li>Outgoing rates: 884.6 kbits/sec (119.8 packets/sec).</li>
</ul>
</li>
<li>About 200 MBytes outgoing transfer; only 12 MBytes incoming transfer (no SSH tunnel compression).</li>
<li>About 200.000 packets sent and about 130.000 received.</li>
</ul>
</li>
<li><strong>3 Mbit/s upload</strong> Internet connection and <a href="http://en.wikipedia.org/wiki/Ping">Ping</a> latency of 75 ms:
<ul>
<li>Time: 8 minutes.</li>
<li>Average transfer rates snapshot:
<ul>
<li>Total rates: 2580.0 kbits/sec (417.8 packets/sec).</li>
<li>Incoming rates: 128.5 kbits/sec (149.6 packets/sec).</li>
<li>Outgoing rates: 2451.5 kbits/sec (268.2 packets/sec).</li>
</ul>
</li>
<li>About 160 MBytes outgoing transfer; only 9 MBytes incoming transfer (with SSH tunnel compression).</li>
<li>About 140.000 packets sent and about 80.000 received.</li>
</ul>
</li>
</ul>
<p>I know I&#8217;m missing two tests with and without SSH tunnel compression but it seems compression doesn&#8217;t make such a difference. It&#8217;s upload speed which affects the total completion time.</p>
<h3>File copy benchmark</h3>
<p>All tests were done without SSH compression and we make the same conclusion &#8212; it is bandwidth which affects the total completion time:</p>
<ul>
<li><strong>1 Mbit/s upload</strong> Internet connection and <a href="http://en.wikipedia.org/wiki/Ping">Ping</a> latency of 75 ms:
<ul>
<li>SSH direct file copy to server: 100 seconds (11 MBytes file).</li>
<li>File copy to an iSCSI mounted file-system: 105 seconds.</li>
</ul>
</li>
<li><strong>3 Mbit/s upload</strong> Internet connection and <a href="http://en.wikipedia.org/wiki/Ping">Ping</a> latency of 75 ms:
<ul>
<li>SSH direct file copy to server: 39 seconds (11 MBytes file).</li>
<li>File copy to an iSCSI mounted file-system: 39 seconds.</li>
</ul>
</li>
</ul>
<p>The SSH direct file copy (<a href="http://en.wikipedia.org/wiki/Secure_copy">SCP</a>) transfer command was &#8220;scp testf root@172.18.0.1:/tmp/&#8221;, and the file copy command was &#8220;cp testf /mnt/ ; sync&#8221;.</p>
<h3>Server and client load during transfer, other benchmarks</h3>
<p>During the transfer both the client and server machines were almost idle in regards to CPU. The iSCSI block storage device on the server was not saturated even at 1%.</p>
<p>Note that the iSCSI target was exported via an SSH tunnel, as described <a href="http://blog.famzah.net/2012/04/17/secure-iscsi-setup-via-an-ssh-tunnel-on-linux/">here</a>. Ping tests shown no difference between a direct server ping and a ping via the SSH tunnel.</p>
<p>The file copy tests were done on a regular iSCSI mounted volume, and on an iSCSI volume which was encrypted using <a href="http://www.truecrypt.org/">TrueCrypt</a>. The same speeds were achieved.</p>
<h3>Encountered problems</h3>
<p>During the backup runs, I got several of the following kernel messages in &#8220;dmesg&#8221;. This seems like a normal warning for the iSCSI use-case scenario:</p>
<blockquote><p>[13200.272157] INFO: task jbd2/dm-0-8:1931 blocked for more than 120 seconds.<br />
[13200.272164] &#8220;echo 0 &gt; /proc/sys/kernel/hung_task_timeout_secs&#8221; disables this message.<br />
[13200.272168] jbd2/dm-0-8     D f2abdc80     0  1931      2 0&#215;00000000
</p></blockquote>
<br />Filed under: <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/iscsi/'>iSCSI</a>, <a href='http://blog.famzah.net/tag/performance/'>performance</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1212/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1212&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2012/04/17/iscsi-over-internet-performance-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Locally encrypted secure remote backup over Internet on Linux (iSCSI / TrueCrypt)</title>
		<link>http://blog.famzah.net/2012/04/17/locally-encrypted-secure-remote-backup-over-internet-on-linux-iscsi-truecrypt/</link>
		<comments>http://blog.famzah.net/2012/04/17/locally-encrypted-secure-remote-backup-over-internet-on-linux-iscsi-truecrypt/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 13:55:17 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[iSCSI]]></category>
		<category><![CDATA[remote backup]]></category>
		<category><![CDATA[TrueCrypt]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1197</guid>
		<description><![CDATA[Recently I decided to start using Amazon AWS as my backup storage but my paranoid soul wasn&#8217;t satisfied until I figured it out how to secure my private data. It&#8217;s not that I don&#8217;t trust Amazon but a lot of bad things could happen if I decided that I just copy my data to a [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1197&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Recently I decided to start using Amazon <a href="http://aws.amazon.com/">AWS</a> as my backup storage but my paranoid soul wasn&#8217;t satisfied until I figured it out how to secure my private data. It&#8217;s not that I don&#8217;t trust Amazon but a lot of bad things could happen if I decided that I just copy my data to a remote server on Amazon:</p>
<ul>
<li>Amazon staff would have access to my data.</li>
<li>A breach in Amazon&#8217;s systems would expose my data.</li>
<li>A breach in my remote server OS would expose my data.</li>
</ul>
<p>One of the solutions which I considered was to encrypt my local file-system with <a href="https://launchpad.net/ecryptfs">eCryptfs</a> but it has some <a href="https://bugs.launchpad.net/ecryptfs/+bug/344878">issues with relatively long file names</a>.</p>
<p>Finally I came out with the following working backup solution which I currently use to backup both my Windows and Linux partitions. I share the Windows root directory with the VirtualBox Linux machine and run the backup scripts from there. Here is a short explanation of the properties and features of the backup setup:</p>
<ul>
<li><strong>Locally encrypted</strong> &#8212; all files which I store on the iSCSI volume are encrypted on my personal desktop, before being sent to the remote server. This ensures that the files cannot be read by anyone else.</li>
<li><strong>Secure</strong> &#8212; besides the local volume encryption, the whole communication is done over an SSH tunnel which secures the Internet point-to-point client-to-server communication.</li>
<li><strong>Remote</strong> &#8212; having a remote backup ensures that even if someone breached in my house and steals my laptop and my offline backup, I can still recover my data from the remote server. Furthermore, it is more convenient to frequently backup on a remote machine, because we have Internet access everywhere now. Note that remote backups are not a substitution for offline backups.</li>
<li><strong>Over Internet</strong> &#8212; very convenient. Of course, this backup scheme can be used in any TCP/IP network &#8212; private LAN, WAN, VPN networks, etc.</li>
</ul>
<p>The following two articles provide detailed instructions on how to setup the backup solution:</p>
<ul>
<li><a href="http://blog.famzah.net/2012/04/17/secure-iscsi-setup-via-an-ssh-tunnel-on-linux/">Secure iSCSI setup via an SSH tunnel on Linux</a></li>
<li><a href="http://blog.famzah.net/2012/04/17/locally-encrypt-an-iscsi-volume-with-truecrypt-on-linux/">Locally encrypt an iSCSI volume with TrueCrypt on Linux</a></li>
</ul>
<h3>Daily usage example</h3>
<p>Here are the commands which I execute, in order to make a backup of my laptop. Those can be further scripted and automated if a daily or more frequent backup is required:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
IP=23.21.98.10 # the public DNS IP address of the EC2 instance / server

## Execute the following, in order to mount the remote encrypted iSCSI volume:

sudo -E \
  ssh -F /dev/null \
  -o PermitLocalCommand=yes \
  -o LocalCommand=&quot;ifconfig tun0 172.18.0.2 pointopoint 172.18.0.1 netmask 255.255.255.0&quot; \
  -o ServerAliveInterval=60 \
  -w 0:0 root@&quot;$IP&quot; \
  'sudo ifconfig tun0 172.18.0.1 pointopoint 172.18.0.2 netmask 255.255.255.0; hostname; echo tun0 ready'

sudo iscsiadm -m node --targetname &quot;iqn.2012-03.net.famzah:storage.backup&quot; --portal &quot;172.18.0.1:3260&quot; --login
sudo truecrypt --filesystem=none -k &quot;&quot; --protect-hidden=no /dev/sdb
sudo mount /dev/mapper/truecrypt1 /mnt

## You can now work on /mnt -- make a backup, copy files, etc.

ls -la /mnt

## Execute the following, in order to unmount the encrypted iSCSI volume:

sync
sudo umount /mnt
sudo truecrypt -d /dev/sdb
sudo iscsiadm -m node --targetname &quot;iqn.2012-03.net.famzah:storage.backup&quot; --portal &quot;172.18.0.1:3260&quot; --logout
# stop the SSH tunnel
</pre>
</div>
<h3>Disaster recovery plan</h3>
<p>Any backup is useless if you cannot restore your data. If your main computer is totally out, you would need the following, in order to access your backed up data:</p>
<ul>
<li>The Amazon AWS login credentials to start the EC2 backup instance.</li>
<li>The root password for the EC2 backup instance, so that you can log in there and then access your backup data by <a href="http://blog.famzah.net/2012/04/17/locally-encrypt-an-iscsi-volume-with-truecrypt-on-linux/">mounting the encrypted iSCSI volume locally on the remote server</a>.</li>
</ul>
<p>In order to be able to log in to the remote server via SSH, you need to set up the following:</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
vi /etc/ssh/sshd_config # PasswordAuthentication yes
/etc/init.d/ssh restart
passwd root # set a very long password which you CAN remember
</pre>
</div>
<p>Make sure that you test if you can log in using an SSH client which does not have your SSH key and thus requires you to enter the root password manually.</p>
<p>I do not consider password authentication for the root account to be a security threat here. The backup server is online only during the time a backup is being made, after which I shut it down in order to save money from Amazon AWS. Furthermore, the backup has a new IP address on each new EC2 machine start, so an attacker cannot continue a brute-force attack easily, even if they started it.</p>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/aws/'>aws</a>, <a href='http://blog.famzah.net/tag/iscsi/'>iSCSI</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/remote-backup/'>remote backup</a>, <a href='http://blog.famzah.net/tag/truecrypt/'>TrueCrypt</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1197&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2012/04/17/locally-encrypted-secure-remote-backup-over-internet-on-linux-iscsi-truecrypt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Locally encrypt an iSCSI volume with TrueCrypt on Linux</title>
		<link>http://blog.famzah.net/2012/04/17/locally-encrypt-an-iscsi-volume-with-truecrypt-on-linux/</link>
		<comments>http://blog.famzah.net/2012/04/17/locally-encrypt-an-iscsi-volume-with-truecrypt-on-linux/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 13:13:16 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[iSCSI]]></category>
		<category><![CDATA[TrueCrypt]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=1189</guid>
		<description><![CDATA[While this article focuses on iSCSI volumes, it also applies for regular directly attached block devices. If you are in doubt on how to export and attach an iSCSI volume over Internet, you can review the &#8220;Secure iSCSI setup via an SSH tunnel on Linux&#8221; article. Locally encrypting a remote iSCSI volume with TrueCrypt has [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1189&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>While this article focuses on iSCSI volumes, it also applies for regular directly attached block devices. If you are in doubt on how to export and attach an iSCSI volume over Internet, you can review the &#8220;<a href="http://blog.famzah.net/2012/04/17/secure-iscsi-setup-via-an-ssh-tunnel-on-linux/">Secure iSCSI setup via an SSH tunnel on Linux</a>&#8221; article.</p>
<p>Locally encrypting a remote iSCSI volume with <a href="http://www.truecrypt.org/">TrueCrypt</a> has the following advantages:</p>
<ul>
<li>You don&#8217;t need to <strong>trust</strong> the administrators of the remote machine &#8212; they cannot see your files because you are using their storage in a locally encrypted format. Thus your private data is completely safe, as long as your encryption password/key is strong enough.</li>
<li>You have the option to temporarily mount the exported iSCSI volume on the remote server, if you are the owner of the remote server and know the encryption password/key. This is handy if you want to make a local copy of a file from the backup volume without storing the encryption password on the remote server.</li>
<li><a href="http://www.truecrypt.org/">TrueCrypt</a> is cross-platform (<em>Windows / Mac OS X / Linux</em>), fast, free, and open-source.</li>
</ul>
<h3>Download and install TrueCrypt</h3>
<p>You need to install TrueCrypt wherever you are going to use it &#8212; on the client machine and optionally on the server.</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
# Download the distribution file from the official page:
#   http://www.truecrypt.org/downloads
# Linux -&gt; Console-only (choose 32-bit or 64-bit depending on your local Linux installation)

tar -zxf truecrypt-7.1a-linux-console-x86.tar.gz # 32-bit in this example
sudo ./truecrypt-7.1a-setup-console-x86

truecrypt --version
#&gt;&gt; TrueCrypt 7.1a
</pre>
</div>
<h3>Encrypt an iSCSI volume with TrueCrypt</h3>
<p>The instructions below assume that the iSCSI volume is attached under &#8220;<strong>/dev/sdb</strong>&#8220;. The output of the commands is quoted with &#8220;#&gt;&gt;&#8221;.</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
# Encrypt the iSCSI volume
sudo truecrypt -t --create /dev/sdb --volume-type=normal --encryption=AES --hash=RIPEMD-160 --filesystem=ext4 --quick -k &quot;&quot;

# Mount the *volume* (there is no file-system, yet)
sudo truecrypt --filesystem=none -k &quot;&quot; --protect-hidden=no /dev/sdb

# Check that a new &quot;dm-0&quot; device with the same size appeared
cat /proc/partitions
#&gt;&gt; major minor  #blocks  name
#&gt;&gt; ...
#&gt;&gt; 8        16  83886080 sdb
#&gt;&gt; 252       0  83885824 dm-0

# Double-check that this is a TrueCrypt volume
ls -la /dev/mapper/truecrypt1
# /dev/mapper/truecrypt1 -&gt; ../dm-0

# Create a file-system.
# This takes about 30 min for a 80 GB volume @ 1 MBit Internet connection.
sudo mkfs.ext4 /dev/mapper/truecrypt1

# You can now mount and use /dev/mapper/truecrypt1 in any mount-point, as 
# this is a regular block device with an ext4 file-system.
# Remember to unmount it when you are done.
mount /dev/mapper/truecrypt1 /mnt
ls -la /mnt
umount /mnt

# Unmount the encrypted *volume*.
# Make sure that you have ALREADY unmounted the file-system!
sync
sudo truecrypt -d /dev/xvdf
</pre>
</div>
<h3>Mount an encrypted iSCSI volume locally on the remote server</h3>
<p>The output of the commands is quoted with &#8220;#&gt;&gt;&#8221;.</p>
<div class="sourcecode">
<pre class="brush: bash; gutter: false; title: ; notranslate">
# The local block device is &quot;/dev/xvdf&quot;
cat /proc/partitions 
#&gt;&gt; major minor  #blocks  name
#&gt;&gt; ...
#&gt;&gt;   202    80  83886080 xvdf

#
# MAKE SURE that no iSCSI clients are using the volume now
#

# Mount an encrypted volume (/dev/xvdf).
# The unencrypted volume will be presented under a different device name (/dev/mapper/truecrypt1).
sudo truecrypt --filesystem=none -k &quot;&quot; --protect-hidden=no /dev/xvdf

# Mount the file-system
sudo mount /dev/mapper/truecrypt1 /mnt
# Access the encrypted files
ls -la /mnt
# Unmount the file-system
sudo umount /mnt

# Unmount the encrypted volume (/dev/mapper/truecrypt1 -&gt; /dev/xvdf).
# Make sure that you have ALREADY unmounted the file-system!
sudo truecrypt -d /dev/xvdf
</pre>
</div>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/iscsi/'>iSCSI</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/truecrypt/'>TrueCrypt</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/1189/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/1189/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&#038;blog=10109730&#038;post=1189&#038;subd=famzah&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2012/04/17/locally-encrypt-an-iscsi-volume-with-truecrypt-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F2.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
	</channel>
</rss>
