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

<channel>
	<title>Blogging Linux</title>
	<atom:link href="http://linux.blogs.com.np/feed/" rel="self" type="application/rss+xml" />
	<link>http://linux.blogs.com.np</link>
	<description></description>
	<lastBuildDate>Sat, 29 May 2010 11:04:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Copying with CPIO</title>
		<link>http://linux.blogs.com.np/2010/05/29/copying-with-cpio/</link>
		<comments>http://linux.blogs.com.np/2010/05/29/copying-with-cpio/#comments</comments>
		<pubDate>Sat, 29 May 2010 11:04:15 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[File system]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[cpio]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=108</guid>
		<description><![CDATA[Create a cpio archive:

localhost% find path/ -depth -print &#124; cpio -oaV &#62; archive.cpio
localhost% find path/ -depth -print &#124; cpio -oaV -O archive.cpio
Create a cpio archive and compress it:

localhost% find path/ -depth -print &#124; cpio -oaV &#124; gzip -c &#62; archive.cpio.gz
Extract a cpio archive:

localhost% cpio -imVd &#60; archive.cpio
localhost% cpio -imVd -I archive.cpio
List the contents of a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Create a cpio archive:<br />
</strong><br />
localhost% find path/ -depth -print | cpio -oaV &gt; archive.cpio<br />
localhost% find path/ -depth -print | cpio -oaV -O archive.cpio</p>
<p><strong>Create a cpio archive and compress it:<br />
</strong><br />
localhost% find path/ -depth -print | cpio -oaV | gzip -c &gt; archive.cpio.gz</p>
<p><strong>Extract a cpio archive:<br />
</strong></p>
<p>localhost% cpio -imVd &lt; archive.cpio<br />
localhost% cpio -imVd -I archive.cpio</p>
<p><strong>List the contents of a cpio archive:<br />
</strong></p>
<p>localhost% cpio -it &lt; archive.cpio<br />
localhost% cpio -it -I archive.cpio</p>
<p><strong>Use cpio copy-pass to copy a directory structure to another location:<br />
</strong></p>
<p>localhost% find path/ -depth -print | cpio -pamVd /new/parent/dir</p>
<p><strong>cpio over SSH</strong></p>
<p>To cpio a local directory, send the output to ssh and feed it to cpio on a remote host:</p>
<p>localhost% find path/ -depth -print | cpio -oaV | ssh user@host &#8216;cpio -imVd&#8217;<br />
Ssh to a remote host, cpio a remote directory, and get its output locally:<br />
localhost% ssh user@host &#8220;find path/ -depth -print | cpio -oaV&#8221; | cpio -imVd</p>
<p><strong>cpio and rpm<br />
</strong><br />
Ever wanted to extract files from an RPM package without installing it? It&#8217;s easy. RPMv4 includes a utility called &#8220;rpm2cpio&#8221;, which creates a cpio stream of files from a given RPM. You can pipe this into cpio just like a regular archive or stream.</p>
<p><strong>List the included files:<br />
</strong><br />
localhost% rpm2cpio foo.rpm | cpio -it<br />
./usr/bin/foo<br />
./usr/share/man/man1/foo.1.gz</p>
<p><strong>Extract all files:</strong></p>
<p>localhost% rpm2cpio foo.rpm | cpio -imVd</p>
<p><strong>Extract only the manpage from that package:<br />
</strong><br />
localhost% rpm2cpio foo.rpm | cpio -imVd ./usr/share/man/man1/foo.1.gz</p>
<p>Source: <a href="http://bradthemad.org/tech/notes/cpio_directory.php">http://bradthemad.org/tech/notes/cpio_directory.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2010/05/29/copying-with-cpio/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to move a Virtual Machine From EC2 to VirtualBox or KVM</title>
		<link>http://linux.blogs.com.np/2010/04/05/how-to-move-a-virtual-machine-from-ec2-to-virtualbox-or-kvm/</link>
		<comments>http://linux.blogs.com.np/2010/04/05/how-to-move-a-virtual-machine-from-ec2-to-virtualbox-or-kvm/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 13:42:34 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Xen]]></category>
		<category><![CDATA[Amazon EC2]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=104</guid>
		<description><![CDATA[There have been quite a few requests on forums and blog posts on a few  sites we frequent asking someone to figure out how to move a virtual  machine from EC2 to VirtualBox or KVM. We’ve got quite a bit of experience working with KVM so we  figured why not try our [...]]]></description>
			<content:encoded><![CDATA[<p>There have been quite a few requests on forums and blog posts on a few  sites we frequent asking someone to figure out how to move a virtual  machine from EC2 to <a href="http://www.virtualbox.org/">VirtualBox</a> or <a href="http://www.linux-kvm.org/">KVM</a>. We’ve got quite a bit of <a href="http://layerboom.com/">experience working</a> with KVM so we  figured why not try our hand at importing a virtual machine template  from the Amazon AMI repository so that developers or sysadmins could run  them in their local environments. We’ve already <a href="http://blog.layerboom.com/2008/10/03/how-to-move-servers-between-xen-and-amazon/">written  a howto</a> on importing an AMI from Amazon, so you may want to read  that first, but this howto also applies to just creating a KVM or  VirtualBox image from a linux filesystem of any kind. Right now this  particular method only works with Linux but there are more OS agnostic  (and much slower) methods for transposing virtual machines. So without  further delay, let’s get started.</p>
<p><span id="more-104"></span>You’ll need at least 15 gigs of free space to make this work.</p>
<h4>1) Download and unpack an AMI from Amazon</h4>
<p>You can <a href="http://blog.layerboom.com/2008/10/03/how-to-move-servers-between-xen-and-amazon">learn  how to do that here</a>, or if you have sufficient knowledge you can  build a full linux filesystem</p>
<h4>2) Prepare a new raw drive file</h4>
<p>We’ll create a file backed drive, set it up so we can partition it  and create a new filesystem.</p>
<p>Create the file by using the ‘dd’ command.</p>
<div>
<div>
<pre style="font-family: monospace"><span style="color: #c20cb9;font-weight: bold"><span style="background-color: #2cfe51;color: #000000">dd</span></span> <span style="color: #007800"><span style="color: #000000;font-weight: bold"><span style="background-color: #2cfe51;color: #000000">if</span></span></span><span style="background-color: #2cfe51;color: #000000">=</span><span style="color: #000000;font-weight: bold"><span style="background-color: #2cfe51;color: #000000">/</span></span><span style="background-color: #2cfe51;color: #000000">dev</span><span style="color: #000000;font-weight: bold"><span style="background-color: #2cfe51;color: #000000">/</span></span><span style="background-color: #2cfe51;color: #000000">zero </span><span style="color: #007800"><span style="background-color: #2cfe51;color: #000000">of</span></span><span style="background-color: #2cfe51;color: #000000">=newimage.raw </span><span style="color: #007800"><span style="background-color: #2cfe51;color: #000000">bs</span></span><span style="background-color: #2cfe51;color: #000000">=1M </span><span style="color: #007800"><span style="background-color: #2cfe51;color: #000000">count</span></span><span style="background-color: #2cfe51;color: #000000">=</span><span style="color: #000000"><span style="background-color: #2cfe51;color: #000000">10240</span></span></pre>
</div>
</div>
<p>Add it to a loopback device</p>
<div>
<div>
<pre style="font-family: monospace">losetup <span style="color: #660033">-fv</span> newimage.raw</pre>
</div>
</div>
<p>Partition the file backed loopback device. For this we’ll just create  one partition which is the whole disk. Make sure its bootable.</p>
<div>
<div>
<pre style="font-family: monospace">cfdisk <span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop0</pre>
</div>
</div>
<p>Write the partition and exit</p>
<p>Now we’re going to create a filesystem on the partition we just  created. Please note that there’s a problem with the way mfks works.  When trying to automatically determine filesystem sizes on loopback  devices it makes a mistake. So for this we need to do a few things.</p>
<p>Find the partition beginning, ending, number of blocks, number of  cylinders, and blocksize</p>
<div>
<div>
<pre style="font-family: monospace">fdisk <span style="color: #660033">-l</span> <span style="color: #660033">-u</span> <span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop0

Disk <span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop0: <span style="color: #000000">10.7</span> GB, <span style="color: #000000">10737418240</span> bytes
<span style="color: #000000">255</span> heads, <span style="color: #000000">63</span> sectors<span style="color: #000000;font-weight: bold">/</span>track, <span style="color: #000000">1305</span> cylinders, total <span style="color: #000000">20971520</span> sectors
Units = sectors of <span style="color: #000000">1</span> <span style="color: #000000;font-weight: bold">*</span> <span style="color: #000000">512</span> = <span style="color: #000000">512</span> bytes
Disk identifier: 0x00000000

      Device Boot      Start         End      Blocks   Id  System
<span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop0p1   <span style="color: #000000;font-weight: bold">*</span>          <span style="color: #000000">63</span>    <span style="color: #000000">20964824</span>    <span style="color: #000000">10482381</span>   <span style="color: #000000">83</span>  Linux</pre>
</div>
</div>
<p>Create a new loopback device for the partition. We do this by  calculating the beginning of the partition x blocksize</p>
<p>In this case that’s 512 * 63 (actually in most cases thats what it  is)</p>
<div>
<div>
<pre style="font-family: monospace">losetup <span style="color: #660033">-fv</span> <span style="color: #660033">-o</span> $<span style="color: #7a0874;font-weight: bold">(</span><span style="color: #7a0874;font-weight: bold">(</span><span style="color: #000000">512</span> <span style="color: #000000;font-weight: bold">*</span> <span style="color: #000000">63</span><span style="color: #7a0874;font-weight: bold">)</span><span style="color: #7a0874;font-weight: bold">)</span> newimage.raw
Loop device is <span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop1</pre>
</div>
</div>
<p>Remember those numbers we grabbed earlier using fdisk? Plunk them  into this formula. For our example:</p>
<p>( END – START ) x Units / Block Size<br />
If you don’t know the block size use 4096. That’s “standard” and usually  the size configured on most ext2/3 filesystems.</p>
<p>So for us it’s this:</p>
<div>
<div>
<pre style="font-family: monospace"><span style="color: #7a0874;font-weight: bold">echo</span> $<span style="color: #7a0874;font-weight: bold">(</span><span style="color: #7a0874;font-weight: bold">(</span><span style="color: #7a0874;font-weight: bold">(</span><span style="color: #000000">20964824</span> - <span style="color: #000000">63</span><span style="color: #7a0874;font-weight: bold">)</span> <span style="color: #000000;font-weight: bold">*</span> <span style="color: #000000">512</span> <span style="color: #000000;font-weight: bold">/</span> <span style="color: #000000">4096</span> <span style="color: #7a0874;font-weight: bold">)</span><span style="color: #7a0874;font-weight: bold">)</span></pre>
</div>
</div>
<p>This gives is the number of blocks we need to use in our next  command, which is used to create a filesystem with a blocksize of 4096  on /dev/loop1 of block count 2620595. You have to specify the blocksize,  otherwise mkfs will try and automatically determine a bunch of things  for you which will just break things.</p>
<div>
<div>
<pre style="font-family: monospace">mkfs.ext3 <span style="color: #660033">-b</span> <span style="color: #000000">4096</span> <span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop1 <span style="color: #000000">2620595</span></pre>
</div>
</div>
<h4>3) Copy &amp; Prepare New Root Filesystem</h4>
<p>You can now mount this newly created filesystem somewhere and copy a  root filesystem into it. If that filesystem happens to be a Xen image  from Amazon, you can use that.</p>
<div>
<div>
<pre style="font-family: monospace"><span style="color: #c20cb9;font-weight: bold">mkdir</span> <span style="color: #660033">-p</span> <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop<span style="color: #000000;font-weight: bold">/</span><span style="color: #000000">1</span>
<span style="color: #c20cb9;font-weight: bold">mount</span> <span style="color: #660033">-t</span> ext3 <span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop1 <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop<span style="color: #000000;font-weight: bold">/</span><span style="color: #000000">1</span>
<span style="color: #c20cb9;font-weight: bold">cp</span> <span style="color: #660033">-a</span> <span style="color: #000000;font-weight: bold">/</span>some<span style="color: #000000;font-weight: bold">/</span>root<span style="color: #000000;font-weight: bold">/</span>filesystem<span style="color: #000000;font-weight: bold">/*</span> <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop<span style="color: #000000;font-weight: bold">/</span><span style="color: #000000">1</span><span style="color: #000000;font-weight: bold">/</span></pre>
</div>
</div>
<p>Xen virtual machines run with a special kernel that can run under KVM  using Xenner, but not other platforms like VirtualBox, so we’re going to  copy a real kernel in there. You can use one from another linux system  if you want, it will work fine, but you should use one that has the  modules required by your virtualization platform. We already have a KVM  tuned kernel and initrd available so we’re going to use those.</p>
<p><strong>Note: </strong>If you’re going to just copy in the initrd and kernel  then make sure the initrd includes all of the modules required to boot  your machine.</p>
<div>
<div>
<pre style="font-family: monospace"><span style="color: #c20cb9;font-weight: bold">cp</span> <span style="color: #660033">-r</span> <span style="color: #000000;font-weight: bold">/</span>some<span style="color: #000000;font-weight: bold">/</span>boot<span style="color: #000000;font-weight: bold">/</span>filesystem<span style="color: #000000;font-weight: bold">/*</span> <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop<span style="color: #000000;font-weight: bold">/</span><span style="color: #000000">1</span><span style="color: #000000;font-weight: bold">/</span>boot<span style="color: #000000;font-weight: bold">/</span></pre>
</div>
</div>
<p>You should now see a the kernel, initrd and the grub directory in  there.</p>
<p>Edit the menu.lst and make sure the root= is set to /dev/sda1</p>
<div>
<div>
<pre style="font-family: monospace"><span style="color: #c20cb9;font-weight: bold">vim</span> <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop<span style="color: #000000;font-weight: bold">/</span><span style="color: #000000">1</span><span style="color: #000000;font-weight: bold">/</span>boot<span style="color: #000000;font-weight: bold">/</span>grub<span style="color: #000000;font-weight: bold">/</span>menu.lst</pre>
</div>
</div>
<p>Edit the /etc/fstab in your mounted vm</p>
<div>
<div>
<pre style="font-family: monospace"><span style="color: #c20cb9;font-weight: bold">vim</span> <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop<span style="color: #000000;font-weight: bold">/</span><span style="color: #000000">1</span><span style="color: #000000;font-weight: bold">/</span>etc<span style="color: #000000;font-weight: bold">/</span>fstab</pre>
</div>
</div>
<p>Because amazon’s best practices involve setting a random root  password, which gets overridden at start time, you’ll have to solve that  little problem.</p>
<div>
<div>
<pre style="font-family: monospace"><span style="color: #c20cb9;font-weight: bold">chroot</span> <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop<span style="color: #000000;font-weight: bold">/</span><span style="color: #000000">1</span>
<span style="color: #c20cb9;font-weight: bold">mv</span> <span style="color: #000000;font-weight: bold">/</span>etc<span style="color: #000000;font-weight: bold">/</span>rc.local <span style="color: #000000;font-weight: bold">/</span>etc<span style="color: #000000;font-weight: bold">/</span>rc.local-old
<span style="color: #c20cb9;font-weight: bold">passwd</span> root
<span style="color: #7a0874;font-weight: bold">exit</span></pre>
</div>
</div>
<h4>5) Setup Grub on the New Drive</h4>
<p>Now unmount /mnt/loop/1 and delete the loopback device for the  partition (the one with the offset) so we can setup the bootloader. Grub  complains about installing the MBR code when the loopback device is  still active on the partition. Leave the loopback device for the entire  drive. We’ll need that to get some numbers from fdisk.</p>
<div>
<div>
<pre style="font-family: monospace"><span style="color: #c20cb9;font-weight: bold">umount</span> <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop<span style="color: #000000;font-weight: bold">/</span><span style="color: #000000">1</span>
losetup <span style="color: #660033">-d</span> <span style="color: #000000;font-weight: bold">/</span>mnt<span style="color: #000000;font-weight: bold">/</span>loop1</pre>
</div>
</div>
<div>
<div>
<pre style="font-family: monospace">fdisk <span style="color: #660033">-l</span> <span style="color: #660033">-u</span> <span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop0

Disk <span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop0: <span style="color: #000000">10.7</span> GB, <span style="color: #000000">10737418240</span> bytes
<span style="color: #000000">255</span> heads, <span style="color: #000000">63</span> sectors<span style="color: #000000;font-weight: bold">/</span>track, <span style="color: #000000">1305</span> cylinders, total <span style="color: #000000">20971520</span> sectors
Units = sectors of <span style="color: #000000">1</span> <span style="color: #000000;font-weight: bold">*</span> <span style="color: #000000">512</span> = <span style="color: #000000">512</span> bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System
<span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>loop0p1   <span style="color: #000000;font-weight: bold">*</span>          <span style="color: #000000">63</span>    <span style="color: #000000">20964824</span>    <span style="color: #000000">10482381</span>   <span style="color: #000000">83</span>  Linux</pre>
</div>
</div>
<p>Make a note of the numbers that were presented here. We’ll need the  following to setup grub</p>
<ul>
<li>Cylinders : 1305</li>
<li>Heads : 255</li>
<li>Sectors / Track : 63</li>
</ul>
<p>These numbers may be different for you depending on the size of  partition you created, or a whole bunch of other variables. It’s  important to remember these values because we’ll need them for our next  step, which is to setup grub.</p>
<p>The following lists the set of commands required to setup the  bootloader on a file backed disk over a loopback device.</p>
<div>
<div>
<pre style="font-family: monospace">grub <span style="color: #660033">--device-map</span>=<span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>null
device <span style="color: #7a0874;font-weight: bold">(</span>hd0<span style="color: #7a0874;font-weight: bold">)</span> <span style="color: #000000;font-weight: bold">/</span>images<span style="color: #000000;font-weight: bold">/</span>newimage.raw
geometry <span style="color: #7a0874;font-weight: bold">(</span>hd0<span style="color: #7a0874;font-weight: bold">)</span> <span style="color: #000000">1305</span> <span style="color: #000000">255</span> <span style="color: #000000">63</span>
root <span style="color: #7a0874;font-weight: bold">(</span>hd0,<span style="color: #000000">0</span><span style="color: #7a0874;font-weight: bold">)</span>
setup <span style="color: #7a0874;font-weight: bold">(</span>hd0<span style="color: #7a0874;font-weight: bold">)</span></pre>
</div>
</div>
<p>Here’s what that looks like in the grub dialogue:</p>
<div>
<div>
<pre style="font-family: monospace">grub <span style="color: #660033">--device-map</span>=<span style="color: #000000;font-weight: bold">/</span>dev<span style="color: #000000;font-weight: bold">/</span>null

Probing devices to guess BIOS drives. This may take a long time.
Unknown partition table signature

<span style="color: #7a0874;font-weight: bold">[</span> Minimal BASH-like line editing is supported.   For
the   first   word,  TAB  lists  possible  <span style="color: #7a0874;font-weight: bold">command</span>
completions.  Anywhere <span style="color: #000000;font-weight: bold">else</span> TAB lists the possible
completions of a device<span style="color: #000000;font-weight: bold">/</span>filename. <span style="color: #7a0874;font-weight: bold">]</span>
grub<span style="color: #000000;font-weight: bold">&gt;</span> device <span style="color: #7a0874;font-weight: bold">(</span>hd0<span style="color: #7a0874;font-weight: bold">)</span> <span style="color: #000000;font-weight: bold">/</span>images<span style="color: #000000;font-weight: bold">/</span>newimage.raw
device <span style="color: #7a0874;font-weight: bold">(</span>hd0<span style="color: #7a0874;font-weight: bold">)</span> <span style="color: #000000;font-weight: bold">/</span>images<span style="color: #000000;font-weight: bold">/</span>newimage.raw
grub<span style="color: #000000;font-weight: bold">&gt;</span> geometry <span style="color: #7a0874;font-weight: bold">(</span>hd0<span style="color: #7a0874;font-weight: bold">)</span> <span style="color: #000000">1305</span> <span style="color: #000000">255</span> <span style="color: #000000">63</span>
geometry <span style="color: #7a0874;font-weight: bold">(</span>hd0<span style="color: #7a0874;font-weight: bold">)</span> <span style="color: #000000">1305</span> <span style="color: #000000">255</span> <span style="color: #000000">63</span>
grub<span style="color: #000000;font-weight: bold">&gt;</span> root <span style="color: #7a0874;font-weight: bold">(</span>hd0,<span style="color: #000000">0</span><span style="color: #7a0874;font-weight: bold">)</span>
grub<span style="color: #000000;font-weight: bold">&gt;</span> setup <span style="color: #7a0874;font-weight: bold">(</span>hd0<span style="color: #7a0874;font-weight: bold">)</span>

Checking <span style="color: #000000;font-weight: bold">if</span> <span style="color: #ff0000">"/boot/grub/stage1"</span> exists... <span style="color: #c20cb9;font-weight: bold">yes</span>
Checking <span style="color: #000000;font-weight: bold">if</span> <span style="color: #ff0000">"/boot/grub/stage2"</span> exists... <span style="color: #c20cb9;font-weight: bold">yes</span>
Checking <span style="color: #000000;font-weight: bold">if</span> <span style="color: #ff0000">"/boot/grub/e2fs_stage1_5"</span> exists... <span style="color: #c20cb9;font-weight: bold">yes</span>
Running <span style="color: #ff0000">"embed /boot/grub/e2fs_stage1_5 (hd0)"</span>...  <span style="color: #000000">17</span> sectors are embedded.
succeeded
Running <span style="color: #ff0000">"install /boot/grub/stage1 (hd0) (hd0)1+17 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"</span>... succeeded
Done.
grub<span style="color: #000000;font-weight: bold">&gt;</span>quit</pre>
</div>
</div>
<h4>Conclusion</h4>
<p>Yay! All you need to do now is delete all those loopback devices  attached to your file, and boot it up in either KVM or VirtualBox<br />
Hope you found that useful.</p>
<p>Source: http://blog.layerboom.com/2009/10/20/how-to-move-a-virtual-machine-from-ec2-to-virtualbox-or-kvm/</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2010/04/05/how-to-move-a-virtual-machine-from-ec2-to-virtualbox-or-kvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passwordless SSH authentication with Putty</title>
		<link>http://linux.blogs.com.np/2010/02/22/passwordless-ssh-authentication-with-putty/</link>
		<comments>http://linux.blogs.com.np/2010/02/22/passwordless-ssh-authentication-with-putty/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 11:42:24 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=102</guid>
		<description><![CDATA[Putty from here. Download  PuttyGen from same link. Once installed, open Puttygen and create a new pair of keys by clicking the “Generate” button. You can keep all the options at their default settings. It might be a good idea to set a passphrase for your key. Then, save both public and private key to [...]]]></description>
			<content:encoded><![CDATA[<p>Putty from <a href="www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank">here.</a> Download  PuttyGen from same link. Once installed, open Puttygen and create a new pair of keys by clicking the “Generate” button. You can keep all the options at their default settings. It might be a good idea to set a passphrase for your key. Then, save both public and private key to a safe location. Name your public key &lt;your_key_name&gt;.pub and the private key &lt;your_key_name&gt;.ppk.</p>
<p><span id="more-102"></span>Now, upload your public key to a directory in your remote system. You need to import it and add it to the authorized_keys file with the command:</p>
<p>ssh-keygen -i -f key.pub &gt;&gt; ~/.ssh/authorized_keys</p>
<p>Replace key.pub with the path to your key. Now log out and start Putty.</p>
<p>In Putty, configure the following items:</p>
<p>* In Connection/Data, add your rmeote username<br />
* Connection/SSH/Auth, browse to your private key file (&lt;your_key_name&gt;.ppk)<br />
* Go back to Sessions, fill in the name or IP address of your remote machine, give your session a name and click on Save.</p>
<p>Now we need to set up Pageant – it is Pageant who will be doing the authentication for us. Open it up, right click on the icon in the system tray and select “Add key”. Select your private key. Now you have an item under “Saved sessions” in Pageant – clicking on your session will fire up Putty and Pageant handles authenticaton for you. Great eh? If your key has a passphrase, you will need to enter it only once, and after that Pageant remembers it for you.</p>
<p>Simple and a great time saver if you do this often</p>
<p>Source: http://www.dailyiteration.com/howto-passwordless-ssh-authentication-with-putty/</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2010/02/22/passwordless-ssh-authentication-with-putty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HOWTO SSH back door?</title>
		<link>http://linux.blogs.com.np/2009/11/05/howto-ssh-back-door/</link>
		<comments>http://linux.blogs.com.np/2009/11/05/howto-ssh-back-door/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 14:42:41 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=97</guid>
		<description><![CDATA[Many times I&#8217;ll be at a site where I need remote support from someone who is blocked on the outside by a company firewall. Few people realize that if you can get out to the world through a firewall, then it is relatively easy to open a hole so that the world can come into [...]]]></description>
			<content:encoded><![CDATA[<p>Many times I&#8217;ll be at a site where I need remote support from someone who is blocked on the outside by a company firewall. Few people realize that if you can get out to the world through a firewall, then it is relatively easy to open a hole so that the world can come into you.</p>
<p>In its crudest form, this is called &#8220;poking a hole in the firewall.&#8221; I&#8217;ll call it an SSH back door. To use it, you&#8217;ll need a machine on the Internet that you can use as an intermediary.</p>
<p>In our example, we&#8217;ll call our machine blackbox.example.com. The machine behind the company firewall is called ginger. Finally, the machine that technical support is on will be called tech. Figure 4 explains how this is set up.</p>
<p><img class="alignnone size-full wp-image-98" src="http://linux.blogs.com.np/files/2009/11/figure4.gif" alt="figure4" width="510" height="278" /></p>
<p>Here&#8217;s how to proceed:</p>
<p>1. Check that what you&#8217;re doing is allowed, but make sure you ask the right people. Most people will cringe that you&#8217;re opening the firewall, but what they don&#8217;t understand is that it is completely encrypted. Furthermore, someone would need to hack your outside machine before getting into your company. Instead, you may belong to the school of &#8220;ask-for-forgiveness-instead-of-permission.&#8221; Either way, use your judgment and don&#8217;t blame me if this doesn&#8217;t go your way.</p>
<p>2. SSH from ginger to blackbox.example.com with the -R flag. I&#8217;ll assume that you&#8217;re the root user on ginger and that tech will need the root user ID to help you with the system. With the -R flag, you&#8217;ll forward instructions of port 2222 on blackbox to port 22 on ginger. This is how you set up an SSH tunnel. Note that only SSH traffic can come into ginger: You&#8217;re not putting ginger out on the Internet naked.</p>
<p>You can do this with the following syntax:</p>
<p>~# ssh -R 2222:localhost:22 thedude@blackbox.example.com</p>
<p>Once you are into blackbox, you just need to stay logged in. I usually enter a command like:</p>
<p>thedude@blackbox:~$ while [ 1 ]; do date; sleep 300; done</p>
<p>to keep the machine busy. And minimize the window.<br />
3. Now instruct your friends at tech to SSH as thedude into blackbox without using any special SSH flags. You&#8217;ll have to give them your password:</p>
<p>root@tech:~# ssh thedude@blackbox.example.com .<br />
4. Once tech is on the blackbox, they can SSH to ginger using the following command:</p>
<p>thedude@blackbox:~$: ssh -p 2222 root@localhost<br />
5. Tech will then be prompted for a password. They should enter the root password of ginger.</p>
<p>6. Now you and support from tech can work together and solve the problem. You may even want to use screen together! (See <a href="http://www.ibm.com/developerworks/linux/library/l-10sysadtips/?S_TACT=105AGY46&amp;S_CMP=ART#T4">Trick 4</a>.)</p>
<p>Source: IBM <a href="http://www.ibm.com/developerworks/linux/library/l-10sysadtips/?S_TACT=105AGY46&amp;S_CMP=ART" target="_blank">DeveloperWorks</a></p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2009/11/05/howto-ssh-back-door/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PostgreSQL DBA Commands</title>
		<link>http://linux.blogs.com.np/2009/04/17/postgresql-dba-commands/</link>
		<comments>http://linux.blogs.com.np/2009/04/17/postgresql-dba-commands/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 15:09:53 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=94</guid>
		<description><![CDATA[In this article, We review top 15 practical postgreSQL DBA command examples.
1. How to change PostgreSQL root user password ?
$ /usr/local/pgsql/bin/psql postgres postgres
Password: (oldpassword)
# ALTER USER postgres WITH PASSWORD ‘tmppassword’;
$ /usr/local/pgsql/bin/psql postgres postgres
Password: (tmppassword)
Changing the password for a normal postgres user is similar as changing the password of the root user. Root user can change [...]]]></description>
			<content:encoded><![CDATA[<p>In this article, We review top 15 practical <strong>postgreSQL DBA command examples</strong>.<br />
<span id="more-94"></span><strong>1. How to change PostgreSQL root user password ?</strong></p>
<p>$ /usr/local/pgsql/bin/psql postgres postgres<br />
Password: (oldpassword)<br />
# ALTER USER postgres WITH PASSWORD ‘tmppassword’;</p>
<p>$ /usr/local/pgsql/bin/psql postgres postgres<br />
Password: (tmppassword)</p>
<p>Changing the password for a normal postgres user is similar as changing the password of the root user. Root user can change the password of any user, and the normal users can only change their passwords as Unix way of doing.</p>
<p># ALTER USER username WITH PASSWORD ‘tmppassword’;</p>
<p><strong>2. How to setup PostgreSQL SysV startup script?</strong></p>
<p>$ su &#8211; root</p>
<p># tar xvfz postgresql-8.3.7.tar.gz</p>
<p># cd postgresql-8.3.7</p>
<p># cp contrib/start-scripts/linux /etc/rc.d/init.d/postgresql</p>
<p># chmod a+x /etc/rc.d/init.d/postgresql</p>
<p><strong>3. How to check whether PostgreSQL server is up and running?</strong></p>
<p>$ /etc/init.d/postgresql status<br />
Password:<br />
pg_ctl: server is running (PID: 6171)<br />
/usr/local/pgsql/bin/postgres “-D” “/usr/local/pgsql/data”<br />
[Note: The status above indicates the server is up and running]</p>
<p>$ /etc/init.d/postgresql status<br />
Password:<br />
pg_ctl: no server running<br />
[Note: The status above indicates the server is down]</p>
<p><strong>4. How to start, stop and restart PostgreSQL database?</strong></p>
<p># service postgresql stop<br />
Stopping PostgreSQL: server stopped<br />
ok</p>
<p># service postgresql start<br />
Starting PostgreSQL: ok</p>
<p># service postgresql restart<br />
Restarting PostgreSQL: server stopped<br />
ok</p>
<p><strong>5. How do I find out what version of PostgreSQL I am running?</strong></p>
<p>$ /usr/local/pgsql/bin/psql test<br />
Welcome to psql 8.3.7, the PostgreSQL interactive terminal.</p>
<p>Type:  \copyright for distribution terms<br />
\h for help with SQL commands<br />
\? for help with psql commands<br />
\g or terminate with semicolon to execute query<br />
\q to quit</p>
<p>test=# select version();<br />
version<br />
—————————————————————————————————-<br />
PostgreSQL 8.3.7 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20071124 (Red Hat 4.1.2-42)<br />
(1 row)</p>
<p>test=#</p>
<p><strong>5. How to create a PostgreSQL user ?</strong></p>
<p>There are two methods in which you can create user.</p>
<p>Method 1: Creating the user in the PSQL prompt, with CREATE USER command.</p>
<p># CREATE USER ramesh WITH password ‘tmppassword’;<br />
CREATE ROLE</p>
<p>Method 2: Creating the user in the shell prompt, with createuser command.</p>
<p>$ /usr/local/pgsql/bin/createuser sathiya<br />
Shall the new role be a superuser? (y/n) n<br />
Shall the new role be allowed to create databases? (y/n) n<br />
Shall the new role be allowed to create more new roles? (y/n) n<br />
CREATE ROLE</p>
<p><strong>6. How to create a PostgreSQL Database ?</strong></p>
<p>There are two metods in which you can create two databases.</p>
<p>Method 1: Creating the database in the PSQL prompt, with createuser command.</p>
<p># CREATE DATABASE mydb WITH OWNER ramesh;<br />
CREATE DATABASE</p>
<p>Method 2: Creating the database in the shell prompt, with createdb command.</p>
<p>$ /usr/local/pgsql/bin/createdb mydb -O ramesh<br />
CREATE DATABASE</p>
<p>* -O owner name is the option in the command line.<br />
<strong>7. How do I get a list of databases in a Postgresql database ?</strong></p>
<p># \l  [Note: This is backslash followed by lower-case L]<br />
List of databases<br />
Name | Owner | Encoding<br />
———-+———-+———-<br />
backup | postgres | UTF8<br />
mydb | ramesh | UTF8<br />
postgres | postgres | UTF8<br />
template0 | postgres | UTF8<br />
template1 | postgres | UTF8</p>
<p><strong>8. How to Delete/Drop an existing PostgreSQL database ?</strong></p>
<p># \l<br />
List of databases<br />
Name | Owner | Encoding<br />
———-+———-+———-<br />
backup | postgres | UTF8<br />
mydb | ramesh | UTF8<br />
postgres | postgres | UTF8<br />
template0 | postgres | UTF8<br />
template1 | postgres | UTF8</p>
<p># DROP DATABASE mydb;<br />
DROP DATABASE</p>
<p><strong>9. Getting help on postgreSQL commands</strong></p>
<p>\? will show PSQL command prompt help. \h CREATE will shows help about all the commands that starts with CREATE, when you want something specific such as help for creating index, then you need to give CREATE INDEX.</p>
<p># \?</p>
<p># \h CREATE</p>
<p># \h CREATE INDEX</p>
<p><strong>10. How do I get a list of all the tables in a Postgresql database?</strong></p>
<p># \d</p>
<p>On an empty database, you’ll get “No relations found.” message for the above command.</p>
<p><strong>11. How to turn on timing, and checking how much time a query takes to execute ?</strong></p>
<p># \timing — After this if you execute a query it will show how much time it took for doing it.</p>
<p># \timing<br />
Timing is on.</p>
<p># SELECT * from pg_catalog.pg_attribute ;<br />
Time: 9.583 ms</p>
<p><strong>12. How To Backup and Restore PostgreSQL Database and Table?</strong></p>
<p>We discussed earlier how to backup and restore postgres database and tables using pg_dump and psql utility.</p>
<p><strong>13. How to see the list of available functions in PostgreSQL ?</strong></p>
<p>To get to know more about the functions, say \df+</p>
<p># \df</p>
<p># \df+</p>
<p><strong>14. How to edit PostgreSQL queries in your favorite editor ?</strong></p>
<p># \e</p>
<p>\e will open the editor, where you can edit the queries and save it. By doing so the query will get executed.<br />
15. Where can i find the postgreSQL history file ?</p>
<p>Similar to the Linux ~/.bash_history file, postgreSQL stores all the sql command that was executed in a history filed called ~/.psql_history as shown below.</p>
<p>$ cat ~/.psql_history<br />
alter user postgres with password ‘tmppassword’;<br />
\h alter user<br />
select version();<br />
create user ramesh with password ‘tmppassword’;<br />
\timing<br />
select * from pg_catalog.pg_attribute;</p>
<p><strong>Post from: The Geek Stuff</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2009/04/17/postgresql-dba-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading openSUSE 10.3 –&gt; 11.0 in a running system.</title>
		<link>http://linux.blogs.com.np/2009/04/06/upgrading-opensuse-103-%e2%80%93-110-in-a-running-system/</link>
		<comments>http://linux.blogs.com.np/2009/04/06/upgrading-opensuse-103-%e2%80%93-110-in-a-running-system/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 15:12:51 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[SuSe]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=86</guid>
		<description><![CDATA[Upgrading openSUSE between releases while the system is running is not a currently supported method of upgrading. The supported method is to boot from an install medium and select the upgrade option. Nevertheless, it is possible to upgrade a running system. This is more difficult than normal with openSUSE 10.3 -&#62; openSUSE 11.0 due to [...]]]></description>
			<content:encoded><![CDATA[<p>Upgrading openSUSE between releases while the system is running is not a currently supported method of upgrading. The supported method is to boot from an install medium and select the upgrade option. Nevertheless, it is possible to upgrade a running system. This is more difficult than normal with openSUSE 10.3 -&gt; openSUSE 11.0 due to the change in RPM payload format from bz2 -&gt; lzma which makes the RPM in 10.3 unable to install RPMs from 11.0.<br />
<span id="more-86"></span><strong>Method</strong></p>
<p>1. Upgrade RPM to the version in 11.0<br />
2. Install the full package management stack from 11.0<br />
3. Upgrade all packages.</p>
<p><strong>Stages</strong></p>
<p>The specific steps required to upgrade using the above method may vary from system to system, these are just those that I needed.</p>
<p>* Disable all the repositories I was using on 10.3.</p>
<p><em> mv /etc/zypp/repos.d /etc/zypp/repos.d.old</em></p>
<p>* Delete the repository cache.</p>
<p><em> rm /var/cache/zypp/zypp.db </em></p>
<p>* Add the main openSUSE 11.0 repository.</p>
<p><em> zypper ar http://download.opensuse.org/distribution/11.0/repo/oss openSUSE110</em></p>
<p>* Install the new RPM from openSUSE 11.0.</p>
<p><strong>On 64bit:</strong></p>
<p><em>rpm -Uhv &#8216;http://download.opensuse.org/distribution/11.0/repo/oss/suse/x86_64/rpm-4.4.2-199.1.x86_64.rpm&#8217;</em></p>
<p>Or if you are on 32 bit:</p>
<p><em>rpm -Uhv &#8216;http://download.opensuse.org/distribution/11.0/repo/oss/suse/i586/rpm-4.4.2-199.1.i586.rpm&#8217;</em></p>
<p>* Install the 11.0 package management stack.<br />
<em><br />
zypper in zypper</em></p>
<p>* Add the 11.0 version of the nonoss and packman repositories, as I have several packages installed from these.</p>
<p><em> zypper ar http://download.opensuse.org/distribution/11.0/repo/non-oss openSUSE110_NonFree<br />
zypper ar http://packman.iu-bremen.de/suse/11.0/ packman</em></p>
<p>* Upgrade all packages. At this point I had to confirm several package vendor changes and removal of a few obsolete packages.</p>
<p><em>zypper ref<br />
zypper dup<br />
</em><br />
* Reboot</p>
<p><strong>Problems</strong></p>
<p>I had only two significant problems after upgrading. Both turned out to be down to my having edited configuration files, so they were not automatically overwritten with the updated configuration files.</p>
<p>* Networkmanager would immediately disconnect after connecting. This turned out to be down to a stale dhclient configuration file. I solved this with:<br />
<em><br />
mv ./dhclient.conf.rpmnew ./dhclient.conf</em></p>
<p>* openSUSE updater could not find any backends. This turned out to be down to a stale zypp configuration file. I solved this with:</p>
<p><em> mv /etc/zypp/zypp.conf.rpmnew /etc/zypp/zypp.conf</em></p>
<p>Since lack of a new configuration files can cause breakage in unexpected places it would be nice to offer users the chance of replacing or merging their configuration file changes, rather than requiring users to know about these files and merge them manually.</p>
<p>Source: http://blogs.warwick.ac.uk/bweber/entry/upgrading_opensuse_103/</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2009/04/06/upgrading-opensuse-103-%e2%80%93-110-in-a-running-system/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to install Gentoo masked packages?</title>
		<link>http://linux.blogs.com.np/2009/03/24/how-to-install-masked-packages/</link>
		<comments>http://linux.blogs.com.np/2009/03/24/how-to-install-masked-packages/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 07:53:57 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[Gentoo]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=84</guid>
		<description><![CDATA[You can ask emerge to use the masked version available in portage by setting the variable ACCEPT_KEYWORDS to ACCEPT_KEYWORDS=&#8221;~x86&#8243; before running the emerge command. It makes sense to set a command alias in roots .bashrc that goes alias aemerge=&#8217;ACCEPT_KEYWORDS=&#8221;~x86&#8243; emerge&#8217;.

The alias should be used for checking what version is the latest with &#8211;pretend (-p). Actually [...]]]></description>
			<content:encoded><![CDATA[<p>You can ask emerge to use the masked version available in portage by setting the variable ACCEPT_KEYWORDS to ACCEPT_KEYWORDS=&#8221;~x86&#8243; before running the emerge command. It makes sense to set a command alias in roots .bashrc that goes alias aemerge=&#8217;ACCEPT_KEYWORDS=&#8221;~x86&#8243; emerge&#8217;.<br />
<span id="more-84"></span><br />
The alias should be used for checking what version is the latest with &#8211;pretend (-p). Actually installing packages like this is a bad idea because the setting is not stored anywhere, meaning package will be downgraded the next time you do emerge -u world.</p>
<p>Gentoo uses the file /etc/portage/package.keywords to configure when to use the masked version. Simply list the package and add your arch to unmask packages.</p>
<p>/etc/portage/package.keywords can look like this:</p>
<p><em> app-emulation/wine ~x86<br />
net-www/mplayerplug-in   ~x86<br />
media-libs/libquicktime ~x86<br />
net-www/mozilla-firefox ~x86<br />
media-video/transcode  ~x86</em></p>
<p>You can add entries to this file using the echo command:</p>
<p><em>echo app-cdr/k3b ~x86 &gt;&gt; /etc/portage/package.keywords</em></p>
<p>Explanation: (I/O Redirection, Bourne Shell Reference)</p>
<p>pgm &gt; file     Output of pgm is redirected to file.<br />
pgm &lt; file     Program pgm reads its input from file.<br />
pgm &gt;&gt; file    Output of pgm is appended to file.</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2009/03/24/how-to-install-masked-packages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Indenting selected lines</title>
		<link>http://linux.blogs.com.np/2009/03/12/indenting-selected-lines/</link>
		<comments>http://linux.blogs.com.np/2009/03/12/indenting-selected-lines/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 10:53:02 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[Vi]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=82</guid>
		<description><![CDATA[You can select lines by pressing V, then moving the cursor down or up (with j or k). After selecting lines, press &#62; to increase the indent, or &#60; to decrease it. Then press . to repeat the action, or u to undo it.
If you want the visual selection to be retained after pressing &#62; [...]]]></description>
			<content:encoded><![CDATA[<p>You can select lines by pressing V, then moving the cursor down or up (with j or k). After selecting lines, press &gt; to increase the indent, or &lt; to decrease it. Then press . to repeat the action, or u to undo it.<br />
If you want the visual selection to be retained after pressing &gt; or &lt;, use these mappings:</p>
<p>:vnoremap &gt; &gt;gv<br />
:vnoremap &lt; &lt;gv</p>
<p>An alternative for anyone using :behave mswin, is to select lines by holding down Shift and pressing the cursor down or up arrow keys. However, in select mode, if you press &gt;, the selected text will be replaced with &#8216;&gt;&#8217;. Instead, you can use Tab to increase the indent, and Shift-Tab to decrease it, with these mappings:</p>
<p>:vnoremap &lt;Tab&gt; &gt;<br />
:vnoremap &lt;S-Tab&gt; &lt;</p>
<p>In select mode, visual-mode mappings temporarily set visual mode (:help Select-mode-mapping).Also, the select mode will be retained. You could use the following alternative if you want to exit from select mode after pressing Tab or Shift-Tab:</p>
<p>:vnoremap &lt;Tab&gt; &gt;gV<br />
:vnoremap &lt;S-Tab&gt; &lt;gV</p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2009/03/12/indenting-selected-lines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Editcap Guide: 11 Examples To Handle Network Packet Dumps Effectively</title>
		<link>http://linux.blogs.com.np/2009/03/05/editcap-guide-11-examples-to-handle-network-packet-dumps-effectively/</link>
		<comments>http://linux.blogs.com.np/2009/03/05/editcap-guide-11-examples-to-handle-network-packet-dumps-effectively/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 16:29:35 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=76</guid>
		<description><![CDATA[Editcap utility is used to select or remove specific packets from dump file and translate them into a given format. Editcap does not perform packet captures like ethereal. Instead, it operates on the captured packets and writes some of the required  packets into another file. We can pass various options to editcap to get [...]]]></description>
			<content:encoded><![CDATA[<p>Editcap utility is used to select or remove specific packets from dump file and translate them into a given format. Editcap does not perform packet captures like ethereal. Instead, it operates on the captured packets and writes some of the required  packets into another file. We can pass various options to editcap to get our preferred packets.  In this article, let us review 11 practical examples on how-to use editcap to handle the packet dumps effectively.<br />
<span id="more-76"></span><br />
<strong>Primary Purpose of editcap</strong></p>
<p>Following are the main reason to use editcap command.</p>
<ul>
<li>Divide a dump file into multiple files.</li>
<li>Select only the required packets.</li>
<li>Translate the capture file from one format to another.</li>
<li>Ability to read from a compressed dump file.</li>
<li>Make the job easier for network analyzer tool by loading only selective packets, instead of loading whole dump.</li>
<li>All feature results in less time consumption when processing or analyzing packets.</li>
</ul>
<p>Let us assume the scenario where you have to analyze only some specific packet types in a huge dump file. In this situation, we cant use the network packet analyzer (wireshark or ethereal) to load the huge dump file in a single shoh, as it will be a CPU intensive process and the system may hang. Editicap utility makes the job easier by giving only relevant packets, so it could be loaded by network analyzer tool in quick time.</p>
<p>Editcap is available in the wireshark package. Make sure <a href="http://www.wireshark.org/">wireshark/ethereal package</a> is installed to use the editcap.</p>
<p><strong>11 Practical Examples Of edicap Usage</strong></p>
<p><strong>Example 1: Discard set of packets from the beginning of input_dump file</strong></p>
<p>The output_dump file will contain all packets except the first 10 packets.</p>
<pre># editcap -v input_dump output_dump 1-10</pre>
<p><strong>Example 2: Discard set of packets from the middle of input_dump file</strong></p>
<p>The output_dump file will contain all packets except packets from 200 to 210.</p>
<pre># editcap -v input_dump output_dump 200-210</pre>
<p><strong>Example 3: Select multiple range of  packets (from beginning and middle)</strong></p>
<p>The output_dump file will contain first 10 packets and packets from 100 and 200.</p>
<pre># editcap -r  -v input_dump output_dump 1-10  100-200</pre>
<p><strong>Example 4: Change the encapsulation type of the capture file using option -T</strong></p>
<p>By default the encapsulation type of the dump file is ether. The example below, translates the capture file into ieee-802-11-bsd format</p>
<pre># editcap -v -T  ieee-802-11-radiotap input_dump output_dump</pre>
<p><strong>Example 5: Process the compressed input_dump files</strong></p>
<p>editcap automatically detects the compressed capture file formats. Currently it supports for the gzip format. In the example below, it takes packets from the compressed input file and writes the first 10 packets and the packets in-between 100 and 200 into the output_dump file.</p>
<pre># editcap -r -v input_dump.gz output_dump 1-10 100-200</pre>
<p><strong>Example 6: Extract packets between a specific timeperiod using option -A and -B</strong></p>
<p>This example create the output_dump, which contains the packets that are captured between the time mentioned in option A and the time mentioned in option B.</p>
<pre># editcap -v -A "2009-02-11 11:26:30" -B "2009-02-11 11:27:00"  input_dump output_dump</pre>
<p><strong>Example 7: Change packet’s timestamp (reduce or advance) using option -t</strong></p>
<p>To advances the timestamp of packets to one hour.</p>
<pre># editcap -t 3600 input_dump output_dump</pre>
<p>To reduces the timestamp of packets to 30 minutes,</p>
<pre># editcap -t -1800 input_dump output_dump</pre>
<p><strong>Example 8: Remove duplicate packets from the output_dump file using option -d</strong></p>
<p>The example below looks back the previous frames to find the duplication. Finally it gives the dump which does not contain duplication.</p>
<pre># editcap -v -d input_dump output_dump</pre>
<p><strong>Example 9: Truncate the packets to the specific length using option -s</strong></p>
<p>Produces the ouptut_dump file with packets length limited to 100. This can be very helpful under lot of situations. For example, you can use this method if you want to get only the IP layer of all the packets and does not require other layer.</p>
<pre># editcap -s 100 -v -A "2009-02-11 11:26:30" -B "2009-02-11 11:27:00"  input_dump.gz output_dump</pre>
<p><strong>Example 10: Divide input_dump file into multiple files using option -c</strong></p>
<p>Divide the single dump into multiple file and each contains specified number of packets.</p>
<pre># editcap -v -c 1000 input_dump output</pre>
<p>If the input_dump contains 5000 packets, editcap will generate the following 5 different output files.</p>
<pre>output-00000
output-00001
output-00002
output-00003
output-00004</pre>
<p><strong>Example 11: Remove certain bytes from the bottom of all packets using option -C</strong></p>
<p>This example removes 10 bytes from every packets and writes into the output file. You can confirm this, by viewing the output file in wireshark, the frame layer of every packet will show “50 bytes bytes on wire, 40 bytes captured” (here the actual size of a packet is 50 bytes).</p>
<pre># editcap -C 10 input_dump output</pre>
<p><em>This article was written by <strong>Balakrishnan Mariyappan.</strong> He is working in <a href="http://www.bksystems.co.in/">bk Systems (p) Ltd</a>, and interested in contributing to the open source. </em><em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2009/03/05/editcap-guide-11-examples-to-handle-network-packet-dumps-effectively/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>15 Practical Linux Find Command Examples</title>
		<link>http://linux.blogs.com.np/2009/03/05/15-practical-linux-find-command-examples/</link>
		<comments>http://linux.blogs.com.np/2009/03/05/15-practical-linux-find-command-examples/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 16:12:28 +0000</pubDate>
		<dc:creator>linux</dc:creator>
				<category><![CDATA[Find]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Shell scripting]]></category>

		<guid isPermaLink="false">http://linux.blogs.com.np/?p=73</guid>
		<description><![CDATA[Apart from the basic operation of looking for files under a directory structure, you can also perform several practical operations using find command that will make your command line journey easy.In this article, let us review 15 practical examples of Linux find command that will be very useful to both newbies and experts.

1. Find Files [...]]]></description>
			<content:encoded><![CDATA[<p>Apart from the basic operation of looking for files under a directory structure, you can also perform several practical operations using find command that will make your command line journey easy.In this article, let us review 15 practical examples of Linux find command that will be very useful to both newbies and experts.<br />
<span id="more-73"></span></p>
<h3>1. Find Files Using Name</h3>
<p>This is a basic usage of the find command. This example finds all files with name — MyCProgram.c in the current directory and all it’s sub-directories.</p>
<pre># find -name "MyCProgram.c"
./backup/MyCProgram.c
./MyCProgram.c</pre>
<h3>2. Find Files Using Name and Ignoring Case</h3>
<p>This is a basic usage of the find command. This example finds all files with name — MyCProgram.c (ignoring the case) in the current directory and all it’s sub-directories.</p>
<pre># find -iname "MyCProgram.c"
./mycprogram.c
./backup/mycprogram.c
./backup/MyCProgram.c
./MyCProgram.c</pre>
<h3>3. Limit Search To Specific Directory Level Using mindepth and maxdepth</h3>
<p>Find the passwd file under all sub-directories starting from root directory.</p>
<pre># find / -name passwd
./usr/share/doc/nss_ldap-253/pam.d/passwd
./usr/bin/passwd
./etc/pam.d/passwd
./etc/passwd</pre>
<p><code> </code><br />
Find the passwd file under root and one level down. (i.e root — level 1, and one sub-directory — level 2)</p>
<pre># find -maxdepth 2 -name passwd
./etc/passwd</pre>
<p><code> </code><br />
Find the passwd file under root and two levels down. (i.e root — level 1, and two sub-directories — level 2 and 3 )</p>
<pre># find / -maxdepth 3 -name passwd
./usr/bin/passwd
./etc/pam.d/passwd
./etc/passwd</pre>
<p><code> </code><br />
Find the password file between sub-directory level 2 and 4.</p>
<pre># find -mindepth 3 -maxdepth 5 -name passwd
./usr/bin/passwd
./etc/pam.d/passwd</pre>
<h3>4. Executing Commands on the Files Found by the Find Command.</h3>
<p>In the example below, the find command calculates the md5sum of all the files with the name MyCProgram.c (ignoring case). {} is replaced by the current file name.</p>
<pre># find -iname "MyCProgram.c" -exec md5sum {} \;
d41d8cd98f00b204e9800998ecf8427e  ./mycprogram.c
d41d8cd98f00b204e9800998ecf8427e  ./backup/mycprogram.c
d41d8cd98f00b204e9800998ecf8427e  ./backup/MyCProgram.c
d41d8cd98f00b204e9800998ecf8427e  ./MyCProgram.c</pre>
<h3>5. Inverting the match.</h3>
<p>Shows the files or directories whose name are not MyCProgram.c .Since the maxdepth is 1, this will look only under current directory.</p>
<pre># find -maxdepth 1 -not -iname "MyCProgram.c"
.
./MybashProgram.sh
./create_sample_files.sh
./backup
./Program.c</pre>
<h3>6. Finding Files by its inode Number.</h3>
<p>Every file has an unique inode number, using that we can identify that file. Create two files with similar name. i.e one file with a space at the end.</p>
<pre># touch "test-file-name"

# touch "test-file-name "
[Note: There is a space at the end]

# ls -1 test*
test-file-name
test-file-name</pre>
<p><code> </code><br />
From the ls output, you cannot identify which file has the space at the end. Using option -i, you can view the inode number of the file, which will be different for these two files.</p>
<pre># ls -i1 test*
16187429 test-file-name
16187430 test-file-name</pre>
<p><code> </code><br />
You can specify inode number on a find command as shown below. In this example, find command renames a file using the inode number.</p>
<pre># find -inum 16187430 -exec mv {} new-test-file-name \;

# ls -i1 *test*
16187430 new-test-file-name
16187429 test-file-name</pre>
<p><code> </code><br />
You can use this technique when you want to do some operation with the files which are named poorly as shown in the example below. For example, the file with name — file?.txt has a special character in it. If you try to execute “rm file?.txt”, all the following three files will get removed. So, follow the steps below to delete only the “file?.txt” file.</p>
<pre># ls
file1.txt  file2.txt  file?.txt</pre>
<p><code> </code><br />
Find the inode numbers of each file.</p>
<pre># ls -i1
804178 file1.txt
804179 file2.txt
804180 file?.txt</pre>
<p><code> </code><br />
Use the inode number to remove the file that had special character in it as shown below.</p>
<pre># find -inum 804180 -exec rm {} \;

# ls
file1.txt  file2.txt
[Note: The file with name "file?.txt" is now removed]</pre>
<h3>7. Find file based on the File-Permissions</h3>
<p>Following operations are possible.</p>
<ul>
<li>Find files that match exact permission</li>
<li>Check whether the given permission matches, irrespective of other permission bits</li>
<li>Search by giving octal / symbolic representation</li>
</ul>
<p><code> </code><br />
For this example, let us assume that the directory contains the following files. Please note that the file-permissions on these files are different.</p>
<pre># ls -l
total 0
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 all_for_all
-rw-r--r-- 1 root root 0 2009-02-19 20:30 everybody_read
---------- 1 root root 0 2009-02-19 20:31 no_for_all
-rw------- 1 root root 0 2009-02-19 20:29 ordinary_file
-rw-r----- 1 root root 0 2009-02-19 20:27 others_can_also_read
----r----- 1 root root 0 2009-02-19 20:27 others_can_only_read</pre>
<p><code> </code><br />
Find files which has read permission to group. Use the following command to find all files that are readable by the world in your home directory, irrespective of other permissions for that file.</p>
<pre># find . -perm -g=r -type f -exec ls -l {} \;
-rw-r--r-- 1 root root 0 2009-02-19 20:30 ./everybody_read
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 ./all_for_all
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read
-rw-r----- 1 root root 0 2009-02-19 20:27 ./others_can_also_read</pre>
<p><code> </code><br />
Find files which has read permission only to group.</p>
<pre># find . -perm g=r -type f -exec ls -l {} \;
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read</pre>
<p><code> </code><br />
Find files which has read permission only to group [ search by octal ]</p>
<pre># find . -perm 040 -type f -exec ls -l {} \;
----r----- 1 root root 0 2009-02-19 20:27 ./others_can_only_read</pre>
<h3>8. Find all empty files (zero byte file) in your home directory and it’s subdirectory</h3>
<p>Most files of the following command output will be lock-files and place holders created by other applications.</p>
<pre># find ~ -empty</pre>
<p><code> </code><br />
List all the empty files only in your home directory.</p>
<pre># find . -maxdepth 1 -empty</pre>
<p><code> </code><br />
List only the non-hidden empty files only in the current directory.</p>
<pre># find . -maxdepth 1 -empty -not -name ".*"</pre>
<h3>9. Finding the Top 5 Big Files</h3>
<p>The following command will display the top 5 largest file in the current directory and it’s subdirectory. This may take a while to execute depending on the total number of files the command has to process.</p>
<pre># find . -type f -exec ls -s {} \; | sort -n -r | head -5</pre>
<h3>10. Finding the Top 5 Small Files</h3>
<p>Technique is same as finding the bigger files, but the only difference the sort is ascending order.</p>
<pre># find . -type f -exec ls -s {} \; | sort -n  | head -5</pre>
<p><code> </code><br />
In the above command, most probably you will get to see only the ZERO byte files ( empty files ). So, you can use the following command to list the smaller files other than the ZERO byte files.</p>
<pre># find . -not -empty -type f -exec ls -s {} \; | sort -n  | head -5</pre>
<h3>11. Find Files Based on file-type using option -type</h3>
<p>Find only the socket files.</p>
<pre># find . -type s</pre>
<p><code> </code><br />
Find all directories</p>
<pre># find . -type d</pre>
<p><code> </code><br />
Find only the normal files</p>
<pre># find . -type f</pre>
<p><code> </code><br />
Find all the hidden files</p>
<pre># find . -type f -name ".*"</pre>
<p><code> </code><br />
Find all the hidden directories</p>
<pre># find -type d -name ".*"</pre>
<h3>12. Find files by comparing with the modification time of other file.</h3>
<p>Show files which are modified after the specified file. The following find command displays all the files that are created/modified after ordinary_file.</p>
<pre># ls -lrt
total 0
-rw-r----- 1 root root 0 2009-02-19 20:27 others_can_also_read
----r----- 1 root root 0 2009-02-19 20:27 others_can_only_read
-rw------- 1 root root 0 2009-02-19 20:29 ordinary_file
-rw-r--r-- 1 root root 0 2009-02-19 20:30 everybody_read
-rwxrwxrwx 1 root root 0 2009-02-19 20:31 all_for_all
---------- 1 root root 0 2009-02-19 20:31 no_for_all

# find -newer ordinary_file
.
./everybody_read
./all_for_all
./no_for_all</pre>
<h3>13. Find Files by Size</h3>
<p>Using the -size option you can find files by size.<br />
<code> </code><br />
Find files bigger than the given size</p>
<pre># find ~ -size +100M</pre>
<p><code> </code><br />
Find files smaller than the given size</p>
<pre># find ~ -size -100M</pre>
<p><code> </code><br />
Find files that matches the exact given size</p>
<pre># find ~ -size 100M</pre>
<p><code> </code><br />
Note: – means less than the give size, + means more than the given size, and no symbol means exact given size.</p>
<h3>14. Create Alias for Frequent Find Operations</h3>
<p>If you find some thing as pretty useful, then you can make it as an alias. And execute it whenever you want.</p>
<p><code> </code><br />
Remove the files named a.out frequently.</p>
<pre># alias rmao="find . -iname a.out -exec rm {} \;"
# rmao</pre>
<p><code> </code><br />
Remove the core files generated by c program.</p>
<pre># alias rmc="find . -iname core -exec rm {} \;"
# rmc</pre>
<p><code> </code></p>
<h3>15. Remove big archive files using find command</h3>
<p>The following command removes *.zip files that are over 100M.</p>
<pre># find / -type f -name *.zip -size +100M -exec rm -i {} \;"</pre>
<p>Remove all *.tar file that are over 100M using the alias rm100m (Remove 100M). Use the similar concepts and create alias like rm1g, rm2g, rm5g to remove file size greater than 1G, 2G and 5G respectively.</p>
<pre># alias rm100m="find / -type f -name *.tar -size +100M -exec rm -i {} \;"
# alias rm1g="find / -type f -name *.tar -size +1G -exec rm -i {} \;"
# alias rm2g="find / -type f -name *.tar -size +2G -exec rm -i {} \;"
# alias rm5g="find / -type f -name *.tar -size +5G -exec rm -i {} \;"

# rm100m
# rm1g
# rm2g
# rm5g</pre>
<p><code> </code><br />
<em>This article was written by <strong>SathiyaMoorthy, author of </strong><a href="http://www.vim.org/scripts/script.php?script_id=2560">numbertotext Vim plugin</a>, which will replace the numbers with the equivalent text inside Vim. The Geek Stuff welcomes your tips and <a href="http://www.thegeekstuff.com/guest-blogging/">guest articles</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://linux.blogs.com.np/2009/03/05/15-practical-linux-find-command-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
