<?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>AWS Linux &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/aws-linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sun, 11 Oct 2020 13:11:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Linux: Corrupt AWS Linux AMI</title>
		<link>https://blog.andreev.it/2016/07/92-linux-corrupt-aws-linux-ami/</link>
					<comments>https://blog.andreev.it/2016/07/92-linux-corrupt-aws-linux-ami/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Sun, 31 Jul 2016 12:48:29 +0000</pubDate>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[AWS Linux]]></category>
		<category><![CDATA[corrupt AMI]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=2650</guid>

					<description><![CDATA[Recently, when I tried to ssh to my AWS Linux AMI, I got an&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>Recently, when I tried to <strong>ssh </strong>to my AWS Linux AMI, I got an error that the key is not valid. First, I thought that somehow my private key was stolen, but upon further investigation in the logs, I found these errors. </p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
/ containts a file system with errors, check forced
</pre>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-01.png" alt="" width="874" height="552" class="aligncenter size-full wp-image-7532" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-01.png 874w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-01-300x189.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-01-768x485.png 768w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-01-585x369.png 585w" sizes="(max-width: 874px) 100vw, 874px" /></a></p>
<div style="border:1px solid red; padding:16px;">
<p style="text-align:center;"><strong><span style="color:#800000;">NOTE: At the end I wasn’t able to recover my instance and I have to restore it from the backups, but the steps outlined below might help you.</span> </strong></p>
</div>
<p>The AMI will try to <strong>fsck </strong>automatically. Most of the time, this will fix your problems. In my case it failed and I got a useless AMI that won&#8217;t boot. If <strong>fsck </strong>doesn’t work, check the console. I saw that one of the checks failed. </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-02.png" alt="" width="1537" height="534" class="aligncenter size-full wp-image-7533" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-02.png 1537w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-02-300x104.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-02-1024x356.png 1024w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-02-768x267.png 768w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-02-1170x406.png 1170w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-02-585x203.png 585w" sizes="(max-width: 1537px) 100vw, 1537px" /></a><br />
According to AWS and this troubleshooting <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstances.html" target="_blank" rel="noopener noreferrer">AWS Troubleshooting</a>, first stop the instance.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-03.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-03.png" alt="" width="1014" height="497" class="aligncenter size-full wp-image-7534" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-03.png 1014w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-03-300x147.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-03-768x376.png 768w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-03-585x287.png 585w" sizes="(max-width: 1014px) 100vw, 1014px" /></a><br />
Go to <strong>Volumes</strong>, <strong>Detach volume</strong> and wait until it says available.</p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-04.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-04.png" alt="" width="1626" height="229" class="aligncenter size-full wp-image-7535" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-04.png 1626w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-04-300x42.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-04-1024x144.png 1024w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-04-768x108.png 768w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-04-1536x216.png 1536w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-04-1170x165.png 1170w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-04-585x82.png 585w" sizes="(max-width: 1626px) 100vw, 1626px" /></a><br />
Create a new instance, same AMI type, same resources. Right click the newly created AMI, choose to <strong>Attach volume</strong> and select the instance where this volume will be attached.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-05.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-05.png" alt="" width="1366" height="447" class="aligncenter size-full wp-image-7536" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-05.png 1366w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-05-300x98.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-05-1024x335.png 1024w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-05-768x251.png 768w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-05-1170x383.png 1170w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-05-585x191.png 585w" sizes="(max-width: 1366px) 100vw, 1366px" /></a><br />
Once attached, in the new AMI do <strong>fdisk -l</strong> to see the device name for your attached disk. In my case I see <strong>/dev/xvdf</strong>.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-06.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-06.png" alt="" width="724" height="233" class="aligncenter size-full wp-image-7537" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-06.png 724w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-06-300x97.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-06-585x188.png 585w" sizes="(max-width: 724px) 100vw, 724px" /></a><br />
Try to repair it from here. In my case I got the following errors. </p>
<div style="border:1px solid red; padding:16px;">
<p style="text-align:center;"><strong><span style="color:#800000;">NOTE: The highlighted is what you type, the rest is the output.</span> </strong></p>
</div>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
fsck.ext4 -v /dev/xvdf
e2fsck 1.42.12 (29-Aug-2014)
ext2fs_open2: Bad magic number in super-block
fsck.ext4: Superblock invalid, trying backup blocks...
fsck.ext4: Bad magic number in super-block while trying to open /dev/xvdf

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 &lt;device&gt;
 or
    e2fsck -b 32768 &lt;device&gt;
</pre>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-07.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-07.png" alt="" width="741" height="303" class="aligncenter size-full wp-image-7538" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-07.png 741w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-07-300x123.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-07-585x239.png 585w" sizes="(max-width: 741px) 100vw, 741px" /></a><br />
We have to find the superblocks that are corrupt. Now, let’s see where my superblocks are kept.</p>
<pre class="brush: bash; highlight: [1,4]; title: ; notranslate">
mke2fs -n /dev/xvdf
mke2fs 1.42.12 (29-Aug-2014)
Found a gpt partition table in /dev/xvdf
Proceed anyway? (y,n) y
Creating filesystem with 2097152 4k blocks and 524288 inodes
Filesystem UUID: 350b4d59-28c8-422f-a3af-ede9daae43e3
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
</pre>
<p><strong>NOTE: You’ll get different numbers. Use yours not mine.</strong> </p>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-08.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-08.png" alt="" width="711" height="237" class="aligncenter size-full wp-image-7539" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-08.png 711w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-08-300x100.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-08-585x195.png 585w" sizes="(max-width: 711px) 100vw, 711px" /></a><br />
Next step is to try to restore the superblocks.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
e2fsck -b 1605632 /dev/xvdf
e2fsck 1.42.12 (29-Aug-2014)
e2fsck: Invalid argument while trying to open /dev/xvdf

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 &lt;device&gt;
 or
    e2fsck -b 32768 &lt;device&gt;
</pre>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-09.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-09.png" alt="" width="705" height="262" class="aligncenter size-full wp-image-7540" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-09.png 705w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-09-300x111.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-09-585x217.png 585w" sizes="(max-width: 705px) 100vw, 705px" /></a><br />
I tried all superblock numbers and all failed. Finally, I tried with the last resort.</p>
<pre class="brush: bash; highlight: [1,4]; title: ; notranslate">
mke2fs -S /dev/xvdf
mke2fs 1.42.12 (29-Aug-2014)
Found a gpt partition table in /dev/xvdf
Proceed anyway? (y,n) y
Creating filesystem with 2097152 4k blocks and 524288 inodes
Filesystem UUID: 97fc1ad1-b8dc-44ec-ba46-33061541cd60
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing superblocks and filesystem accounting information: done
</pre>
<p><a href="https://blog.andreev.it/wp-content/uploads/2016/07/P071-10.png"><img loading="lazy" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2016/07/P071-10.png" alt="" width="696" height="242" class="aligncenter size-full wp-image-7541" srcset="https://blog.andreev.it/wp-content/uploads/2016/07/P071-10.png 696w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-10-300x104.png 300w, https://blog.andreev.it/wp-content/uploads/2016/07/P071-10-585x203.png 585w" sizes="(max-width: 696px) 100vw, 696px" /></a><br />
Force the checks on the filesystem.</p>
<pre class="brush: bash; title: ; notranslate">
e2fsck -f /dev/xvdf -y
/dev/xvdf: ***** FILE SYSTEM WAS MODIFIED *****
/dev/xvdf: 9001/524288 files (5.0% non-contiguous), 114693/2097152 blocks
</pre>
<p>At the end, mount the volume and see if you see your data. In my case, I got nothing.</p>
<pre class="brush: bash; highlight: [1]; title: ; notranslate">
ls -l
total 148
drwx------ 516 root root 147456 May 13 23:23 lost+found
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2016/07/92-linux-corrupt-aws-linux-ami/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
