<?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>Abraxas &#187; LUKS</title>
	<atom:link href="http://www.effinger.org/blog/tag/luks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.effinger.org/blog</link>
	<description>a personal knowledge base</description>
	<lastBuildDate>Sun, 06 Jun 2010 17:41:45 +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>Daten von mit LUKS-verschlüsselter Platte retten</title>
		<link>http://www.effinger.org/blog/2008/10/12/daten-von-mit-luks-verschlusselter-platte-retten/</link>
		<comments>http://www.effinger.org/blog/2008/10/12/daten-von-mit-luks-verschlusselter-platte-retten/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 19:14:40 +0000</pubDate>
		<dc:creator>Markus Effinger</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Datenrettung]]></category>
		<category><![CDATA[LUKS]]></category>

		<guid isPermaLink="false">http://www.effinger.org/blog/?p=34</guid>
		<description><![CDATA[<p>Nachdem der Ubuntu-Installer meine Platte /dev/hda, die in verschlüsselter Form das Backup enthielt, durch die Installation von grub in den Bootsektor unbrauchbar gemacht hatte (LUKS-Header überschrieben). Musste ich mich an die Wiederherstellung der Daten von der Platte machen, auf die ich das System neu installiert hatte. Gott sei Dank hatte ich bei der Neupartitionierung meines [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem der Ubuntu-Installer meine Platte /dev/hda, die in verschlüsselter Form das Backup enthielt, durch die Installation von grub in den Bootsektor unbrauchbar gemacht hatte (LUKS-Header überschrieben). Musste ich mich an die Wiederherstellung der Daten von der Platte machen, auf die ich das System neu installiert hatte. Gott sei Dank hatte ich bei der Neupartitionierung meines Systems andere Partitionsgrößen gewählt, so dass noch Hoffnung bestand, dass die LUKS-Header der ehemaligen Partitionen intakt sein könnte. Meine Rettungsstrategie bestand darin, zunächst zu überprüfen, ob dieser Header noch vorhanden ist, um dann ggfs. über ein Loop-Back Device die Entschlüsselung vorzunehmen und zu schauen, ob noch etwas zu retten ist. Dazu verwendete ich die aktuelle <a href="http://www.knoppix.org/">Knoppix-CD</a>.</p>
<p>Mein neues System hatte ich auf /dev/sda installiert. Im Zuge der Neuinstallation hatte ich vier Partitionen erstellt: /dev/sda1 bis /dev/sda4, die teilweise auch verschlüsselt sind. Auf der Platte /dev/sda musste ich also nach meinem alten LUKS-Header für die Datenpartition suchen. Bevor man jedoch mit der Suche loslegt, sollte man auf Nummer sicher gehen und die Partition in den nur-Lesemodus versetzen.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">400</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda<span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>Mit dem Hex-Editor hexedit suchen wir nun nach LUKS-Headern:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> hexedit <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda</pre></div></div>

<p>Mit der Taste &lt;Tab&gt; erstmal in den ASCII-Teil wechseln und dann mit der Tastenkombination &lt;Strg&gt;+&lt;S&gt; die Suche nach dem Wort LUKS starten. Sobald ich einen Header gefunden hatte, musste ich überprüfen, ob es ein Header der neuen verschlüsselten Partition war oder aber der meiner alten, den ich verzweifelt suchte. Dazu öffnete ich dann jeweils die anderen Partitionen im Hexeditor und verglich die Zeichenfolgen, die ein paar Bytes nach dem Schlüsselwort LUKS kommen.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> hexedit <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1</pre></div></div>

<p>Nachdem ich an dem Offset 0&#215;2E44CCC00 den entsprechenden Header meiner alten Partition gefunden hatte, musste ich noch herausfinden, wie groß die alte Partition war. Ich hatte Glück, da die Partition den gesamten Rest der Festplatte einnahm und somit 237639177216 Bytes groß gewesen sein musste.</p>
<p>Mit diesen Informationen kann man nun mittels losetup ein Loopback-Device erzeugen, das genau auf den Teil verweist, der die urpsrüngliche verschlüsselte Partition ausgemacht hat.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> losetup <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">@</span>0x2E44CCC00 <span style="color: #660033;">-s</span> <span style="color: #000000;">237639177216</span> <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>dev<span style="color: #000000; font-weight: bold;">/</span>sda</pre></div></div>

<p>Nun kann man das Loopback-Device ebenfalls read-only setzen und mit cryptsetup öffnen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">400</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop1
<span style="color: #c20cb9; font-weight: bold;">sudo</span> cryptsetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>key luksOpen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop1 cryptbackup</pre></div></div>

<p>Die Partition können wir nun mit mounten mit einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> jfs <span style="color: #660033;">-o</span> ro <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>cryptbackup <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>recover</pre></div></div>

<p>oder als Image sichern (Achtung unverschlüsselt!)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">if</span></span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>cryptbackup <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>location<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>backup.img <span style="color: #007800;">bs</span>=10M</pre></div></div>

<p>Den Fortschritt von dd kann man übrigens mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">while</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">true</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">5</span>; <span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-USR1</span> DD-PID; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>verfolgen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.effinger.org/blog/2008/10/12/daten-von-mit-luks-verschlusselter-platte-retten/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
