<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>A mind less ordinary &#187; emergency</title>
	<atom:link href="http://www.dmi.me.uk/blog/tag/emergency/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dmi.me.uk/blog</link>
	<description></description>
	<lastBuildDate>Wed, 18 Aug 2010 13:17:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/3.0/</creativeCommons:license>
		<item>
		<title>Recovering from pvmove failure</title>
		<link>http://www.dmi.me.uk/blog/2010/01/07/recovering-from-pvmove-failure/</link>
		<comments>http://www.dmi.me.uk/blog/2010/01/07/recovering-from-pvmove-failure/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 23:25:29 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[emergency]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[lvm2]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://www.dmi.me.uk/blog/?p=203</guid>
		<description><![CDATA[
<p>Note: This is a fairly rambling explanation of recent events. I assume that you have at least a passing knowledge of LVM and its terminology. This was written to prove that it is possible to recover from pvmove failing (in certain cases) due to the way it performs its operations and backs up metadata.</p>
The background
<p>I recently <a href="http://www.dmi.me.uk/blog/2010/01/07/recovering-from-pvmove-failure/">[...]</a>]]></description>
			<content:encoded><![CDATA[
<p>Note: This is a fairly rambling explanation of recent events. I assume that you have at least a passing knowledge of <a title="LVM HOWTO (Chapter 3: Anatomy of LVM)" href="http://tldp.org/HOWTO/LVM-HOWTO/anatomy.html" target="_blank">LVM</a> and its terminology. This was written to prove that it is possible to recover from <code class="codecolorer text default"><span class="text">pvmove</span></code> failing (in certain cases) due to the way it performs its operations and backs up metadata.<span id="more-203"></span></p>
<h2>The background</h2>
<p>I recently received a new hard drive, and so I excitedly partitioned and formatted it, extended my <abbr title="Logical Volume Manager">LVM</abbr> <abbr title="Volume Groups">VGs</abbr> and merrily moved my <abbr title="logical volumes">LVs</abbr> completely across to the new drive using <code class="codecolorer text default"><span class="text">pvmove</span></code>. So far, so wonderful &#8212; I was now ready to rebuild my other two drives so that only critical things were covered by <abbr title="Redundant Array of Inexpensive Disks">RAID</abbr> and everything else was just in a large VG that spanned multiple drives. I now had three drives, all Samsung SpinPoint:</p>
<ol>
<li>500GB  (<code class="codecolorer text default"><span class="text">sdb</span></code>)</li>
<li>1TB (<code class="codecolorer text default"><span class="text">sda</span></code>)</li>
<li>1.5TB (<code class="codecolorer text default"><span class="text">sdc</span></code>, and brand-new)</li>
</ol>
<p>The partition setup I wanted:</p>
<ul>
<li>48MiB RAID-1 across all drives, for <code class="codecolorer text default"><span class="text">/boot</span></code> (already set up across <code class="codecolorer text default"><span class="text">sda</span></code> and <code class="codecolorer text default"><span class="text">sdb</span></code>)</li>
<li>4.8GiB RAID-1 across all drives, for <code class="codecolorer text default"><span class="text">/</span></code>(already set up across <code class="codecolorer text default"><span class="text">sda</span></code> and <code class="codecolorer text default"><span class="text">sdb</span></code>)</li>
<li>50GiB RAID-1 across all drives, for  <code class="codecolorer text default"><span class="text">/usr</span></code>, <code class="codecolorer text default"><span class="text">/opt</span></code>, <code class="codecolorer text default"><span class="text">/var</span></code></li>
<li>50GiB RAID-5 across all drives, for <code class="codecolorer text default"><span class="text">/home</span></code> (giving 100GiB usable space)</li>
<li>The rest of each drive divided into 50/100GiB partitions, to be spread among my large data VG, containing films, music, backups, and other large data.</li>
</ul>
<h2>The disaster</h2>
<p>I moved all of the existing LVs to the new drive, which had plenty of space. Next, I sorted out the partitions for the two older drives, and initialised the RAIDs for my <code class="codecolorer text default"><span class="text">sys</span></code> and <code class="codecolorer text default"><span class="text">safe</span></code> VGs:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># set up RAID-1 across /dev/sda3, /dev/sdb3 and (later) /dev/sdc3</span><br />
mdadm <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md2 <span style="color: #660033;">-l1</span> <span style="color: #660033;">-n3</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda3 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb3 missing<br />
<span style="color: #666666; font-style: italic;"># initialise the RAID for LVM</span><br />
pvcreate <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md2<br />
<span style="color: #666666; font-style: italic;"># set up RAID-5 across /dev/sda5, /dev/sdb5 and (later) /dev/sdb5</span><br />
mdadm <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md3 <span style="color: #660033;">-l5</span> <span style="color: #660033;">-n3</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda5 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb5 missing<br />
pvcreate <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md3</div></div>
<p>I then expanded the VGs and started to copy data across. I began with the <code class="codecolorer text default"><span class="text">safe</span></code> VG that contained <code class="codecolorer text default"><span class="text">/home</span></code>, as I wanted to be sure it was indeed safe. I have all of the photos I&#8217;ve ever taken, my email backups and archives, and various private keys and other important data, as well as things that could be replaced due to duplication elsewhere (including working copies of most of my projects). Being LVM, I could move the LVs around without needing to unmount them or reboot into a LiveCD:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># extend the volume groups</span><br />
vgextend sys <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md2<br />
vgextend safe <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md3<br />
<span style="color: #666666; font-style: italic;"># move all data from /dev/sdc2 to other volumes in the group</span><br />
pvmove <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdc2<br />
<span style="color: #666666; font-style: italic;"># ... disaster struck before the second pvmove</span><br />
pvmove <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdc1</div></div>
<p>Then, disaster struck:  <code class="codecolorer text default"><span class="text">pvmove</span></code> spat a set of I/O errors at me&#8230; but kept running! I wasn&#8217;t paying attention (as moving 40GiB of data takes quite a while) and so I had just left it to work away.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">pvmove: dev_open(/dev/sda) called while suspended<br />
pvmove: dev_open(/dev/sda1) called while suspended<br />
pvmove: dev_open(/dev/sda2) called while suspended<br />
pvmove: dev_open(/dev/sda3) called while suspended<br />
pvmove: dev_open(/dev/sda5) called while suspended<br />
pvmove: dev_open(/dev/md2) called while suspended<br />
pvmove: dev_open(/dev/md3) called while suspended</div></div>
<p>It was only after it had completed and I started getting I/O and &#8220;permission denied&#8221; errors while trying to access my home directory that I first realised anything had gone wrong. After some <a title="Google: pvmove dev_open called while suspended recover" href="http://www.google.com/search?q=pvmove+dev_open+called+while+suspended+recover" target="_blank">frantic searching</a> on the Internet, it seemed that I had to wave goodbye to all of my personal data, including those bits that weren&#8217;t backed up (though I&#8217;ve learned my lesson about backups now!).</p>
<p>I was determined not to give in to data loss, and so I gave myself a few recovery options:</p>
<ol>
<li>Create an image of the partition where the data used to reside.</li>
<li>Try to recover pictures (the most critical thing for me) via <a title="Foremost on SourceForge" href="http://foremost.sourceforge.net/" target="_blank">foremost</a>, which is a non-destructive operation.</li>
<li>Try to rebuild the file system using <code class="codecolorer text default"><span class="text">reiserfsck --rebuild-tree</span></code>.</li>
</ol>
<p>During my investigations and poking around, I discovered that there was another option: I could try to rebuild the VG from an old copy of its metadata.</p>
<h2>Introduction to recovery</h2>
<p>It turns out that many LVM utilities store a backup of the VG&#8217;s metadata before and after performing various operations, so as long as your <code class="codecolorer text default"><span class="text">/etc/lvm</span></code> directory is fine, you have a fighting chance. (Actually, it is theoretically possible to retrieve old versions of the metadata from the LVM partition itself, but this gets much more complex and I won&#8217;t deal with it here.)</p>
<p>The reason for this is that <code class="codecolorer text default"><span class="text">pvmove</span></code> works by creating a temporary target LV, mirroring data from the existing LV to the temporary target (making checkpoints along the way), and only removing the original once the mirroring has completed. This operation can then be interrupted and resumed at any time without loss of data. This also has the advantage that a full copy of the data on the original LV is still available; only the metadata explaining where it begins and ends has changed.</p>
<p>To access the old versions of this metadata, investigate the contents of your <code class="codecolorer text default"><span class="text">/etc/lvm/archive</span></code> directory as root. You should find one or more files of the form <code class="codecolorer text default"><span class="text">volgroup_nnnnn.vg</span></code>, where <code class="codecolorer text default"><span class="text">volgroup</span></code> is the name of the relevant VG and <code class="codecolorer text default"><span class="text">nnnnn</span></code> is a number. These files contain a backup of the volume group&#8217;s metadata, such as which partitions it resides on and where it&#8217;s located. The contents may look something like this:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># Generated by LVM2 version 2.02.56(1) (2009-11-24): Mon Jan &nbsp;4 17:09:24 2010<br />
<br />
contents = &quot;Text Format Volume Group&quot;<br />
version = 1<br />
<br />
description = &quot;Created *before* executing 'vgextend safe /dev/md/3'&quot;<br />
<br />
creation_host = &quot;hostname&quot; &nbsp;# Linux hostname 2.6.31-gentoo-r3 #3 SMP Mon Nov 23 11:31:59 GMT 2009 i686<br />
creation_time = 1262624964 &nbsp;# Mon Jan &nbsp;4 17:09:24 2010<br />
<br />
safe {<br />
id = &quot;zbSAI8-ExUy-PxJw-SHX7-y9PL-AL2y-kiTk8g&quot;<br />
seqno = 10<br />
status = [&quot;RESIZEABLE&quot;, &quot;READ&quot;, &quot;WRITE&quot;]<br />
flags = []<br />
extent_size = 8192 &nbsp; &nbsp;# 4 Megabytes<br />
max_lv = 0<br />
max_pv = 0<br />
<br />
physical_volumes {<br />
<br />
pv0 {<br />
id = &quot;Vw3IF5-U92i-V2aL-9we1-A4E7-7j1P-4G142u&quot;<br />
device = &quot;/dev/sdc1&quot; &nbsp;# Hint only<br />
<br />
status = [&quot;ALLOCATABLE&quot;]<br />
flags = []<br />
dev_size = 199993122 &nbsp;# 95.3642 Gigabytes<br />
pe_start = 384<br />
pe_count = 24413 &nbsp;# 95.3633 Gigabytes<br />
}<br />
}<br />
<br />
logical_volumes {<br />
<br />
home {<br />
id = &quot;glU5zb-l9I7-SzGg-aXx5-lvgL-on4r-Faqkes&quot;<br />
status = [&quot;READ&quot;, &quot;WRITE&quot;, &quot;VISIBLE&quot;]<br />
flags = []<br />
segment_count = 1<br />
<br />
segment1 {<br />
start_extent = 0<br />
extent_count = 12799 &nbsp;# 49.9961 Gigabytes<br />
<br />
type = &quot;striped&quot;<br />
stripe_count = 1 &nbsp;# linear<br />
<br />
stripes = [<br />
&quot;pv0&quot;, 0<br />
]<br />
}<br />
}<br />
}<br />
}</div></div>
<p>I went through the backups for my <code class="codecolorer text default"><span class="text">safe</span></code> volume group, and found the one before I extended the volume group to the (now corrupt) <code class="codecolorer text default"><span class="text">/dev/md3</span></code>, which is actually the example given above.</p>
<h2>Recovering the volume group</h2>
<p>It was at this point that I rebooted and held my breath. I brought the system into runlevel 1 (single-user mode) and logged in as root. Out of curiosity I ran some SMART tests on the drives &#8212; <code class="codecolorer text default"><span class="text">sda</span></code> was reporting no partitions, and internal testing eventually reported a persistent read error at about 80% into the drive. It looked like that drive was toast, which would explain why writing to the RAID-5 had failed.</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">smartctl <span style="color: #660033;">-t</span> short <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda<br />
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">180</span><br />
smartctl <span style="color: #660033;">--all</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda</div></div>
<p>After verifying that it was a hardware issue, I decided to try to point the VG at its previous location (just <code class="codecolorer text default"><span class="text">/dev/sdc1</span></code>), thereby getting it to forget that the <code class="codecolorer text default"><span class="text">home</span></code> LV was on the now-inaccessible RAID-5. This could be accomplished by the magic of <code class="codecolorer text default"><span class="text">vgcfgrestore</span></code>:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># restore the VG metadata for the &quot;safe&quot; VG from the given file</span><br />
vgcfgrestore <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>lvm<span style="color: #000000; font-weight: bold;">/</span>archive<span style="color: #000000; font-weight: bold;">/</span>safe_00006.vg safe<br />
<span style="color: #666666; font-style: italic;"># re-scan for VGs, and &quot;safe&quot; should show up as inactive</span><br />
vgscan<br />
<span style="color: #666666; font-style: italic;"># activate the VG and any LVs inside</span><br />
vgchange <span style="color: #660033;">-ay</span> safe<br />
<span style="color: #666666; font-style: italic;"># re-scan for LVs and verify that safe/home exists</span><br />
lvscan<br />
<span style="color: #666666; font-style: italic;"># not taking any chances -- mount it read-only</span><br />
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-o</span> ro <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>safe<span style="color: #000000; font-weight: bold;">/</span>home <span style="color: #000000; font-weight: bold;">/</span>home</div></div>
<p>After the <code class="codecolorer text default"><span class="text">mount</span></code> succeeded, I began to copy all of the data to my large partition, where it should be safe. I also copied the major bits I didn&#8217;t want to lose to a USB flash drive as well, just to be certain. Once that was done, I took a deep breath and rebooted again, this time back to the full system.</p>
<h2>Clearing up afterwards</h2>
<p>Fortunately, everything worked fine &#8212; it was as if nothing had ever gone wrong! All that was left now was to rebuild the broken RAID section.</p>
<p>I decided for safety that I would re-initialise the <code class="codecolorer text default"><span class="text">safe</span></code> VG&#8217;s RAID as RAID-1 rather than RAID-5, so that any two of the drives could fail without losing my precious data:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># stop the RAID array</span><br />
mdadm <span style="color: #660033;">-S</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md3<br />
<span style="color: #666666; font-style: italic;"># remove the RAID descriptors from the partitions</span><br />
mdadm <span style="color: #660033;">--zero-superblock</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda5<br />
mdadm <span style="color: #660033;">--zero-superblock</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb5<br />
<span style="color: #666666; font-style: italic;"># create as RAID-1</span><br />
mdadm <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md3 <span style="color: #660033;">-l1</span> <span style="color: #660033;">-n3</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda5 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb5 missing</div></div>
<p>What I hadn&#8217;t anticipated was that this would rebuild the RAID-1 using the data from the previous RAID-5&#8230; including the LVM descriptors and corrupt content. Once the RAID was online, I ran <code class="codecolorer text default"><span class="text">pvscan</span></code> and received a warning that the VG metadata was inconsistent. For one heart-stopping moment, it also appeared that LVM thought my home partition was on the corrupt RAID! I quickly stopped the array and thought again.</p>
<p>After some further investigation, I discovered that the first 256 sectors of a partition are used by LVM to hold various information (including multiple copies of the VG metadata). All I had to do to fix this was to destroy that information:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># ensure the array is stopped</span><br />
mdadm <span style="color: #660033;">-S</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md3<br />
<span style="color: #666666; font-style: italic;"># zero the first 256 sectors</span><br />
<span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>zero <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda5 <span style="color: #007800;">bs</span>=<span style="color: #000000;">512</span> <span style="color: #007800;">count</span>=<span style="color: #000000;">256</span><br />
<span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>zero <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb5 <span style="color: #007800;">bs</span>=<span style="color: #000000;">512</span> <span style="color: #007800;">count</span>=<span style="color: #000000;">256</span><br />
<span style="color: #666666; font-style: italic;"># recreate the array -- it may complain that they are already in an array</span><br />
mdadm <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md3 <span style="color: #660033;">-l1</span> <span style="color: #660033;">-n3</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda5 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb5 missing</div></div>
<p>Once this was done, I could run <code class="codecolorer text default"><span class="text">pvcreate /dev/md3</span></code> and proceed to extend the VG and <code class="codecolorer text default"><span class="text">pvmove</span></code> data as before, without worrying that <code class="codecolorer text default"><span class="text">sda</span></code> would give out on me and cause everything to fail again.</p>
<p>I hope this helps someone!</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 3427px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">mdadm -C /dev/md3 -l1 -n3 /dev/sda5 /dev/sdb5 missing</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dmi.me.uk/blog/2010/01/07/recovering-from-pvmove-failure/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Restoring from LVM and VMWare disks</title>
		<link>http://www.dmi.me.uk/blog/2009/02/22/restoring-from-lvm-and-vmware-disks/</link>
		<comments>http://www.dmi.me.uk/blog/2009/02/22/restoring-from-lvm-and-vmware-disks/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 13:37:28 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[emergency]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[lvm2]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[useful]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.dmi.me.uk/blog/?p=91</guid>
		<description><![CDATA[<p>I recently had to restore a server that failed to boot after a power cut. This machine was a Linux VMWare host, and it had three Linux guest virtual machines that were running at the time. While we had full backups available, I decided to set myself the challenge of recovering the entire images, to save <a href="http://www.dmi.me.uk/blog/2009/02/22/restoring-from-lvm-and-vmware-disks/">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I recently had to restore a server that failed to boot after a power cut. This machine was a Linux VMWare host, and it had three Linux guest virtual machines that were running at the time. While we had full backups available, I decided to set myself the challenge of recovering the entire images, to save the pain of a complete rebuild.</p>
<p>The host server partitions were LVM-formatted volumes on top of hardware RAID-1, and each of the virtual hosts were partitioned with LVM too, internally. This means that the restore process will not be at all trivial. With just a complete image of the host system, I would need to restore (deep breath) files on a partition on an LVM logical volume (inside a volume group, on a physical volume) in a VMWare hard disk stored on LVM (logical volume inside volume group of physical volumes) inside a disk image that is itself a file on a disk. How very convoluted.</p>
<p>I used a Gentoo system to restore the data, although any Linux system with the appropriate packages should be able to do it. No searches turned up information on doing all of this, and I had to come up with some of it myself, so I thought I would document the process.</p>
<p><span id="more-91"></span>Just to illustrate the complexity of the data layout:</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-174" title="LVM Restore Diagram" src="http://www.dmi.me.uk/blog/wp-content/uploads/2009/07/lvm-restore-diag-2.png" alt="LVM Restore Diagram" width="650" height="250" /></p>
<h2>Requirements</h2>
<p>The machine that is performing the restore requires:</p>
<ul>
<li>Linux</li>
<li>LVM2</li>
<li>VMWare Server</li>
<li>losetup</li>
<li>NBD (Network Block Device) kernel driver</li>
<li>file system drivers (if applicable)</li>
</ul>
<h2>Procedure</h2>
<p>Boot the dead server (<strong>vm-host</strong>) using a Linux LiveCD and copy its partitions to files on another drive. If you don&#8217;t know which partitions the LVM was stored across, you can either copy all of them, or use &lt;tt&gt;pvscan&lt;/tt&gt; (possibly after running &lt;tt&gt;vgscan&lt;/tt&gt;) to work out which belong to the appropriate volume group. This dump may take some time.</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda2 <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>ext-drive<span style="color: #000000; font-weight: bold;">/</span>sda2-data<br />
<span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda3 <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>ext-drive<span style="color: #000000; font-weight: bold;">/</span>sda3-data<br />
<span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda5 <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>ext-drive<span style="color: #000000; font-weight: bold;">/</span>sda5-data</div></div>
<p>Attach the drive with the partition images to the rescue machine (<strong>rescue-host</strong>), edit <kbd>/etc/lvm/lvm.conf</kbd> on <strong>rescue-host</strong>, and modify the <kbd>filter</kbd> line to allow LVM to scan loopback and network block devices. You&#8217;ll probably want to change this back afterwards, so remember what it was.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">filter = [ &quot;a|/dev/nbd.*|&quot;, &quot;a|loop|&quot;, &quot;a|/dev/[hs]d|&quot;, &quot;a/.*/&quot; ]</div></div>
<p>Set up the partition images as loop devices:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">losetup <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0 <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>ext-drive<span style="color: #000000; font-weight: bold;">/</span>sda2-data<br />
losetup <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>ext-drive<span style="color: #000000; font-weight: bold;">/</span>sda3-data<br />
losetup <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop2 <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>ext-drive<span style="color: #000000; font-weight: bold;">/</span>sda5-data</div></div>
<p>Scan for and activate the volume group:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">vgscan<br />
vgchange <span style="color: #660033;">-ay</span></div></div>
<p>Find the logical volume with the data we&#8217;re after (<strong>LogVol06</strong> in volume group <strong>VolGroup00</strong> in this case) and mount it:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">lvscan<br />
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VolGroup00<span style="color: #000000; font-weight: bold;">/</span>LogVol06 <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>rescue</div></div>
<p>Copy the VMWare hard disk files out of the LVM mount, because we know that the volume group stored on them will conflict with the existing one:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>rescue<span style="color: #000000; font-weight: bold;">/</span>vmware<span style="color: #000000; font-weight: bold;">/</span>vhostname<span style="color: #000000; font-weight: bold;">/</span>vhostname.vmdk <span style="color: #000000; font-weight: bold;">/</span>rescue<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>Check the partition table on the virtual hard disk:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">vmware-mount <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>rescue<span style="color: #000000; font-weight: bold;">/</span>vhostname.vmdk</div></div>
<p>This will give you something like:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">--------------------------------------------<br />
VMware for Linux - Virtual Hard Disk Mounter<br />
Version: 1.0 build-80004<br />
Copyright 1998 VMware, Inc. All rights reserved. -- VMware Confidential<br />
--------------------------------------------<br />
<br />
Nr Start &nbsp; &nbsp; &nbsp;Size &nbsp; &nbsp; &nbsp; Type Id Sytem<br />
-- ---------- ---------- ---- -- ------------------------<br />
1 &nbsp;63 &nbsp; &nbsp; &nbsp; &nbsp; 208782 &nbsp; &nbsp; BIOS 83 Linux<br />
2 &nbsp;208845 &nbsp; &nbsp; 16563015 &nbsp; BIOS 8E Unknown</div></div>
<p>The second partition (with type <kbd>8E</kbd>) is the one we wanted in this case, but it&#8217;s LVM-formatted. This means we can&#8217;t use <kbd>vmware-mount</kbd> because an LVM partition cannot be mounted normally.</p>
<p>We need to unmount the currently-active volume group on the loopback devices (i.e. the LVM from <strong>vm-host</strong>):</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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>rescue<br />
<span style="color: #666666; font-style: italic;"># repeat the next line for all volume groups from the loopback devices</span><br />
vgchange <span style="color: #660033;">-an</span> VolGroup00<br />
losetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop0<br />
losetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop1<br />
losetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop2</div></div>
<p>Now you need a dedicated terminal to mount the LVM partition from the virtual hard disk, as this process must stay running in order to access the virtual drive:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">vmware-loop <span style="color: #000000; font-weight: bold;">/</span>rescue<span style="color: #000000; font-weight: bold;">/</span>vhostname.vmdk <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>nbd0</div></div>
<p>If you have more than one virtual partition as part of the LVM, you&#8217;ll need to have one terminal for each, and select partition numbers and NBD device numbers as appropriate.<br />
Now find the volume group again:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">vgscan<br />
vgchange <span style="color: #660033;">-ay</span></div></div>
<p>Find the appropriate logical volume and mount it:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">lvscan<br />
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>VolGroup00<span style="color: #000000; font-weight: bold;">/</span>LogVol06 <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>rescue</div></div>
<p>Do whatever you need to do with the data, then unmount it all:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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>rescue<br />
vgchange <span style="color: #660033;">-an</span> VolGroup00<br />
<span style="color: #666666; font-style: italic;"># either press ctrl-c in the vmware-loop terminal(s), or:</span><br />
<span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-INT</span> vmware-loop<br />
<span style="color: #666666; font-style: italic;"># then finally refresh the volume group list to remove old entries</span><br />
vgscan</div></div>
<p>And that&#8217;s it! I hope this helps someone other than me&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dmi.me.uk/blog/2009/02/22/restoring-from-lvm-and-vmware-disks/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>
