<?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>necessary and sufficient &#187; linux</title>
	<atom:link href="http://shortbus.org/bloggin/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://shortbus.org/bloggin</link>
	<description>internet is so computer</description>
	<lastBuildDate>Tue, 08 Dec 2009 19:44:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>how to un-shoot your foot</title>
		<link>http://shortbus.org/bloggin/2008/09/29/dm-mapper-how-to-un-shoot-your-foot/</link>
		<comments>http://shortbus.org/bloggin/2008/09/29/dm-mapper-how-to-un-shoot-your-foot/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 18:39:15 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[shortbus]]></category>
		<category><![CDATA[dm-mapper]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[san]]></category>
		<category><![CDATA[snapshot]]></category>
		<category><![CDATA[whoops]]></category>

		<guid isPermaLink="false">http://shortbus.org/bloggin/?p=12</guid>
		<description><![CDATA[Recently I shot myself in the foot pretty bad. We have a ~12TB data array that was set up as a raw LVM2 device- no partition table. There were some issues with one of the cluster members, so I went to rescue boot to attempt to correct it. Redhat&#8217;s rescue boot, in the name of [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I shot myself in the foot pretty bad. We have a ~12TB data array that was set up as a raw LVM2 device- no partition table. There were some issues with one of the cluster members, so I went to rescue boot to attempt to correct it. Redhat&#8217;s rescue boot, in the name of spreading democracy, proactively offers to put a partition table on anything that doesn&#8217;t have one already, and I fat-fingered the key that made this happen right over the top of our array. Whoops.</p>
<p>This isn&#8217;t impossible to recover from- the only thing that got overwritten was, for the most part, LVM data, and it so happens that the boundaries of the volumes is more or less known (25% each), so recovery should be possible just by re-writing correct (or near-correct) headers setting the boundaries in the right spot. Problem with this approach is that you get one shot, and it&#8217;s not like we have another 12TB sitting around that we can copy the data to. Here&#8217;s where dm-mapper came in to save my ass.<br />
<span id="more-12"></span></p>
<p>Using dm-mapper&#8217;s snapshot target, you can create a working copy of a large device that you want to test a few smallish changes to- like, for example, rewriting the partition table and fscking.</p>
<p>The snapshot target actually uses two separate device-mapper types, <code>snapshot-origin</code>, which is the device that you want to create the snapshot of, and <code>snapshot</code>, which becomes the device that you&#8217;ll be able to make your ephemeral changes to. The <code>snapshot</code> device requires a <code>snapshot-origin</code> device as well as a device to hold the written changes. For this, it&#8217;s easy to use a file-backed loopback device.</p>
<p>First, we set up the <code>snapshot-origin</code> device:</p>
<pre>DEVSIZE=`sudo /sbin/blockdev --getsize /dev/sdb`
sudo /sbin/dmsetup create rescue-base-real --table \
        "0 $DEVSIZE linear /dev/loop0 0"
sudo /sbin/dmsetup create rescue-base --table \
        "0 $DEVSIZE snapshot-origin "</pre>
<p>Next, we make a file as large as we expect the changes to be and create a loopback device for it:</p>
<pre>dd if=/dev/zero of=/tmp/backing-store bs=1048576 count=1024 # 1GB
# get name of first available loopback
BACKINGDEV=`sudo /sbin/losetup -f`
sudo /sbin/losetup -f /tmp/backing-store</pre>
<p>Now, finally, create the snapshot device:</p>
<pre>sudo /sbin/dmsetup create rescue-snap --table \
        "0 $DEVSIZE snapshot /dev/mapper/rescue-base $BACKINGDEV n 8"</pre>
<p>The last two arguments to the above command instruct dm-mapper that this is a non-persistent device, and to use a chunk size of 8 for copy-on-write operations.</p>
<p>Now you&#8217;ve got yourself a device you can play with that won&#8217;t cause any permanent changes if you guess the extents incorrectly, or if a fsck does the wrong thing. As an example, it took me about three tries to get the extents set up correctly for maximum data recovery. If I&#8217;d been working with the bare device, this wouldn&#8217;t have ended as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://shortbus.org/bloggin/2008/09/29/dm-mapper-how-to-un-shoot-your-foot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
