<?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>Sexy Sexy Penguins &#187; Recovery</title>
	<atom:link href="http://sexysexypenguins.com/category/recovery/feed/" rel="self" type="application/rss+xml" />
	<link>http://sexysexypenguins.com</link>
	<description>I love the smell of &#34;Free Software&#34; in the morning</description>
	<lastBuildDate>Fri, 20 Jan 2012 15:35:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>sfdisk &#8211; My new Saving Grace</title>
		<link>http://sexysexypenguins.com/2007/03/16/sfdisk-my-new-saving-grace/</link>
		<comments>http://sexysexypenguins.com/2007/03/16/sfdisk-my-new-saving-grace/#comments</comments>
		<pubDate>Fri, 16 Mar 2007 16:55:27 +0000</pubDate>
		<dc:creator>herlo</dc:creator>
				<category><![CDATA[Recovery]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://fedora-tutorials.com/2007/03/16/sfdisk-my-new-saving-grace/</guid>
		<description><![CDATA[How many of you have ever lost your data on a hard drive? I know I have, more than once. Usually, I give up on recovering the drive but this time I really couldn&#8217;t. I was installing a machine as I normally do for class, I have a removable usb drive (80GB) that I keep <a href="http://sexysexypenguins.com/2007/03/16/sfdisk-my-new-saving-grace/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>How many of you have ever lost your data on a hard drive?  I know I have, more than once.  Usually, I give up on recovering the drive but this time I really couldn&#8217;t.</p>
<p>I was installing a machine as I normally do for class, I have a removable usb drive (80GB) that I keep the installation media spooled.  For some reason, this time when the installation had completed, the disk appeared to be completely wiped.  I thought I was screwed.  The data I had was company data which has to be saved for several months.  It was important that I recover this data.</p>
<p>Luckily for me, the data wasn&#8217;t gone, just the partition table.  I hunted around the interweb for a while and struggled to find anything useful to help me recover the lost partition.  After about a day and a half searching, I was about to give up, when I found <a href="http://www.linuxplanet.com/linuxplanet/tutorials/3174/7/" target="_blank">this guide</a>.  The guide is a bit cryptic but nonetheless gets the job done.</p>
<p>This is my saving grace.  I&#8217;ve got this tutorial bookmarked in several places now and intend on making a tutorial here on how to accomplish this as well, mainly just so I always have it available.</p>
<p>Now, I could have completely avoided the situation if I had backed up my partition table.  And because of what had happened, I am going to show you how to back up your partition tables quickly and easily using <strong>sfdisk</strong>.</p>
<p><strong>sfdisk</strong>, or scriptable <strong>fdisk</strong> is useful for creating partitions on the fly, or in our case, quickly backing up partition tables.</p>
<p>First, take a look at this partition table.  Note that I have 7 partitions here:</p>
<p><code># fdisk -l</code><br />
<code>Disk /dev/sdc: 66 MB, 66240512 bytes</code><br />
<code>3 heads, 43 sectors/track, 1002 cylinders</code><br />
<code>Units = cylinders of 129 * 512 = 66048 bytes</code></p>
<p><code>Device Boot      Start         End      Blocks   Id  System</code><br />
<code>/dev/sdc1               1         152        9782+  83  Linux</code><br />
<code>/dev/sdc2             153         259        6901+  83  Linux</code><br />
<code>/dev/sdc3             260         305        2967   82  Linux swap / Solaris</code><br />
<code>/dev/sdc4             306        1002       44956+   5  Extended</code><br />
<code>/dev/sdc5             306         563       16640+  fd  Linux raid autodetect</code><br />
<code>/dev/sdc6             564         776       13738   fd  Linux raid autodetect</code><br />
<code>/dev/sdc7             777        1002       14576+  83  Linux</code></p>
<p>/dev/sdc1 is mounted at /mnt and has a couple files loaded:</p>
<p><code># mount</code><br />
<code>..snip..</code><br />
<code>/dev/sdc1 on /mnt type ext3 (rw)</code></p>
<p><code># ls -l /mnt</code><br />
<code>total 8353</code><br />
<code>-rw-rw-r-- 1 root root   65182 Mar 16 10:42 iah-sna.pdf</code><br />
<code>drwx------ 2 root root   12288 Mar 16 10:35 lost+found</code><br />
<code>-rw------- 1 root root 8437760 Mar 16 10:42 zlm-administrator-guide.pdf</code></p>
<p>To back up the partition table run the following command:</p>
<p><code># sfdisk -d /dev/sdc &gt; /tmp/sdc-backup.txt</code></p>
<p>What does that produce:</p>
<p><code># </code><code>cat /tmp/sdc-backup.txt</code><br />
<code>partition table of /dev/sdc</code><br />
<code>unit: sectors</code></p>
<p><code>/dev/sdc1 : start=       43, size=    19565, Id=83</code><br />
<code>/dev/sdc2 : start=    19608, size=    13803, Id=83</code><br />
<code>/dev/sdc3 : start=    33411, size=     5934, Id=82</code><br />
<code>/dev/sdc4 : start=    39345, size=    89913, Id= 5</code><br />
<code>/dev/sdc5 : start=    39346, size=    33281, Id=fd</code><br />
<code>/dev/sdc6 : start=    72628, size=    27476, Id=fd</code><br />
<code>/dev/sdc7 : start=   100105, size=    29153, Id=83</code></p>
<p>Looks pretty much like what <strong>fdisk <em>-l</em></strong> show, but in a slightly different format.  <strong>sfdisk </strong>will use this file later on to recover.</p>
<p>Let&#8217;s destroy the partition table.  The <strong>dd</strong> command overwrites the first 512 bytes of the disk with zeros.</p>
<p><code># dd if=/dev/zero of=/dev/sdc bs=512 count=1</code></p>
<p><code># fdisk -l /dev/sdc</code><br />
<code>Disk /dev/sdc: 66 MB, 66240512 bytes</code><br />
<code>3 heads, 43 sectors/track, 1002 cylinders</code><br />
<code>Units = cylinders of 129 * 512 = 66048 bytes</code></p>
<p><code>Disk /dev/sdc doesn't contain a valid partition table</code></p>
<p>Oops, gone is the partition table.  That&#8217;s not good.  Luckily a backup has been made, and should be able to restore it quite easily:</p>
<p><code># sfdisk /dev/sdc &lt; /</code><code>tmp/sdc-backup.txt</code><br />
<code>Checking that no-one is using this disk right now ...</code><br />
<code>OK</code></p>
<p><code>Disk /dev/sdc: 1002 cylinders, 3 heads, 43 sectors/track</code></p>
<p><code>sfdisk: ERROR: sector 0 does not have an msdos signature</code><br />
<code> /dev/sdc: unrecognized partition table type</code><br />
<code>Old situation:</code><br />
<code>No partitions found</code><br />
<code>New situation:</code><br />
<code>Units = sectors of 512 bytes, counting from 0</code></p>
<p><code>   Device Boot    Start       End   #sectors  Id  System</code><br />
<code>/dev/sdc1            43     19607      19565  83  Linux</code><br />
<code>/dev/sdc2         19608     33410      13803  83  Linux</code><br />
<code>/dev/sdc3         33411     39344       5934  82  Linux swap / Solaris</code><br />
<code>/dev/sdc4         39345    129257      89913   5  Extended</code><br />
<code>/dev/sdc5         39346     72626      33281  fd  Linux raid autodetect</code><br />
<code>/dev/sdc6         72628    100103      27476  fd  Linux raid autodetect</code><br />
<code>/dev/sdc7        100105    129257      29153  83  Linux</code><br />
<code>Warning: no primary partition is marked bootable (active)</code><br />
<code>This does not matter for LILO, but the DOS MBR will not boot this disk.</code><br />
<code>Successfully wrote the new partition table</code></p>
<p><code>Re-reading the partition table ...</code></p>
<p><code>If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)</code><br />
<code>to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1</code><br />
<code>(See fdisk(8).)</code></p>
<p>Remount <em>/dev/sdc1</em> to see if the partition data is still there:</p>
<p><code># mount -t ext3 /dev/sdc1 /mnt</code><br />
<code># ls -l /mnt</code><br />
<code>total 8353</code><br />
<code>-rw-rw-r-- 1 root root   65182 Mar 16 10:42 iah-sna.pdf</code><br />
<code>drwx------ 2 root root   12288 Mar 16 10:35 lost+found</code><br />
<code>-rw------- 1 root root 8437760 Mar 16 10:42 zlm-administrator-guide.pdf</code></p>
<p>There it is!  Wow, data was never lost, just hidden for a while.</p>
<p>This can be helpful in other ways too.  Using <strong>sfdisk </strong>to build scripted partitions is never easier now.  Just build a file from one pre-partitioned disk, modify and use it everywhere else.</p>
<p>Cheers,</p>
<p>Herlo</p>
]]></content:encoded>
			<wfw:commentRss>http://sexysexypenguins.com/2007/03/16/sfdisk-my-new-saving-grace/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

