<?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; vmware</title>
	<atom:link href="http://www.dmi.me.uk/blog/tag/vmware/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dmi.me.uk/blog</link>
	<description></description>
	<lastBuildDate>Wed, 23 Nov 2011 16:01:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-nd/3.0/</creativeCommons:license>
		<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[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 [...]]]></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'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'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'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's LVM-formatted. This means we can'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'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's it! I hope this helps someone other than me...</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>

