-
Notifications
You must be signed in to change notification settings - Fork 0
/
article2.html
430 lines (296 loc) · 18.3 KB
/
article2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<!doctype html>
<head>
<link href='http://fonts.googleapis.com/css?family=Metrophobic|Roboto:700' rel='stylesheet' type='text/css'>
<title>Cross Region AWS</title>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="_js/nav1.1.min.js"></script>
<link href="css/style.css" rel="stylesheet">
</head>
<script>
$(document).ready( function() {
$('.navlink').mouseenter(function() {
$(this).addClass("navlinkhover");
}); // end onMouseOver
$('.navlink').mouseleave(function() {
$(this).removeClass("navlinkhover")
}); //end mouseLeave
$('#nav').navPlugin({
'itemWidth': 245,
'itemHeight': 30,
'navEffect': 'fade',
'speed': 250,
'vertical': false
}); //end navPlugin
}); //end ready
</script>
<body>
<div class="header">
JavaScript
</div>
<div class="nav">
<ul id="nav">
<li>
<a class="navlink" href="index.html">home</a>
</li>
<li>
<a class="navlink" href="info.html">collected information</a>
<ul>
<li>
<a class="navlink" href="article1.html">Obtvse Install</a>
</li>
<li>
<a class="navlink" href="article2.html">Cross Region AWS</a>
</li>
</ul>
</li>
<li>
<a class="navlink" href="newsletter.html">newsletter</a>
</li>
<li>
<a class="navlink" href="about.html">about</a>
</li>
</ul>
</div>
<div class="content">
<h2>Overview</h2>
<p>Basically we are going make an image of the EBS volumes attached to the instance you want to run locally and, download them, and finally extract them onto .VHDX and spin up an new hyper-v machine using that .VHDX</p>
<h2>Create the image of your EBS volume</h2>
<h3>First we need to create a micro linux instance to aid in the creation of the image.</h3>
<ol>
<li>From your EC2console click the “Launch Instance button”</li>
<li>From here we can select the “Classic Wizard” and click “Continue”</li>
<li>We’ll use the Amazon Linux AMI in 64bit</li>
<li>Now select a “T1 Micro” instance type and place it in the Availability Zone that the instance we are downloading is currently located.</li>
<li>Go ahead and continue through and name your instance “Migration Helper”</li>
<li>Use the existing key that the instance we are moving currently uses</li>
<li>Add it to the same security group(s) as well</li>
</ol>
<h3>Next we’ll create new EBS volumes, an empty one and a clone of the EBS volume from the instance.</h3>
<ol>
<li>Find the EBS ID of your volume by selecting it in the console and scrolling down in the information panel and clicking on the device in “Block Devices”</li>
<li>Move to the “Volumes” console and find your EBS volume.</li>
<li>Right click the volume and select “Create snapshot”</li>
<li>Name the snapshot and set it to create.</li>
<li>While the snapshot is being created go ahead and create an empty EBS volume the same size as the volume you are currently snapshotting in the same availability zone as the instance we are moving.</li>
<li>Attach the blank volume to your “Migration Helper” instance as /dev/sdf.</li>
<li>Once the snapshot has been created move over to the snapshots console and find the snapshot.</li>
<li>Right click the snapshot and select “Create Volume from Snapshot”</li>
<li>Size it the same as the empty volume you just created and add it to the same availability zone as well.</li>
<li>Once the volume has been created attach it you your “Migration Helper” instance as /dev/sdg</li>
</ol>
<h3>Finally we will create the image</h3>
<ul>
<li>SSH into your “Migration Helper instance”</li>
<li>Switch to the root user</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>sudo su -
</span><span class='line'>
</span><span class='line'>+ Create a file system on the blank volume
</span></code></pre></td></tr></table></div></figure>
<p>bash
mkfs.ext3 /dev/sdf</p>
<ul>
<li>Create a mount point and mount the blank volume</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>mkdir /mnt/img
</span><span class='line'>mount /dev/sdf /mnt/img
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Using dd create an image of the cloned volume.</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>dd <span class="k">if</span><span class="o">=</span>/dev/sdg | gzip -c > /mnt/img/sda1.img.gz
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Once the image has been created we need to change ownership of the /mnt/img directory</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>chown -R ec2-user:ec2-user /mnt/img
</span></code></pre></td></tr></table></div></figure>
<h2>Downloading the image</h2>
<h3>First we need to add the AWS key to your local Hyper-V instance</h3>
<ul>
<li>Create a directory called key in your home directory</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>mkdir ~/key
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Create a file called aws.pem</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>vim aws.pem
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Paste your private key information into the file, then save and close it.</li>
<li>Change permissions so only the owner can read and write to the key file.</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>chmod 600 aws.pem
</span></code></pre></td></tr></table></div></figure>
<h3>Now we’re ready to download the image.</h3>
<ul>
<li>Create a directory in your home directory to store the image.</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>mkdir ~/imgStore
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Now using scp we will copy down the image file we created from our “Migration Helper”</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>scp -i ~/key/aws.pem ec2-user@us-west-ip:/mnt/img/sda1.img.gz ~/imgStore
</span></code></pre></td></tr></table></div></figure>
<h2>Create a VHDX for the cloned machine</h2>
<h3>First we need to create a blank VHDX to unpack the cloned image onto</h3>
<ul>
<li>Open Hyper-V Manager</li>
<li>Select New>Hard Disk…</li>
<li>Choose a Fixed size disk</li>
<li>Choose a name and location for the blank drive</li>
<li>Size it appropriately to fit the unpacked image</li>
<li>Review your selections and click finish</li>
</ul>
<h3>Now we need to attach the blank .VHDX to our local Hyoer-V linux instance</h3>
<ul>
<li>Shut down the instance</li>
<li>Open the settings forthe instance</li>
<li>Select IDE Controller 0</li>
<li>Add a hard drive</li>
<li>Enter the path of your newly created blank .VHDX</li>
<li>Click OK, and start the machine back up</li>
</ul>
<h3>Before we can unpack the image onto the new drive we have to re-create the partition table</h3>
<ul>
<li>Start parted</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>parted
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Set device to the newly attached blank drive</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="o">(</span>parted<span class="o">)</span> <span class="k">select</span> /dev/sdb
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Create the the partition that you will be cloning the image we brought down from EC2 onto. (substitute your own start end values)</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="o">(</span>parted<span class="o">)</span> mkpart primary ext4 0 30000
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Next create your swap partition (substitute your own start end values)</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="o">(</span>parted<span class="o">)</span> mkpart primary linux-swap 30000 32048
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Finally we will set the first partition to boot</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="o">(</span>parted<span class="o">)</span> <span class="nb">set </span>1 boot
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Exit parted</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'><span class="nb">exit</span>
</span></code></pre></td></tr></table></div></figure>
<h3>Now we unpack the image</h3>
<p>As root</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>gunzip -c ~/imgStore/sda1.img.gz | dd <span class="nv">of</span><span class="o">=</span>/dev/sdb1
</span></code></pre></td></tr></table></div></figure>
<h2>Final config and boot</h2>
<ul>
<li><p>Because of how EC2 handles virtual instances there are a few things that we need to make a few more changes to get this VM to boot in a timely fashion.</p></li>
<li><p>First let’s mount the new drive and put ourselves in a chroot shell</p></li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>mount /dev/sdb1 /mnt
</span><span class='line'>mount --bind /dev /mnt/dev
</span></code></pre></td></tr></table></div></figure>
<ul>
<li>Now we can chroot into the system and mount some important virtual filesystems</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>chroot /mnt
</span><span class='line'>mount -t proc none /proc
</span><span class='line'>mount -t sysfs none /sys
</span><span class='line'>mount -t devpts none /dev/pts
</span><span class='line'><span class="nb">export </span><span class="nv">HOME</span><span class="o">=</span>/root
</span><span class='line'><span class="nb">export </span><span class="nv">LC_ALL</span><span class="o">=</span>C
</span></code></pre></td></tr></table></div></figure>
<p>Because EC2 instances don’t actually have a kernel installed and instead have it loaded by the Xen server on boot, we need to install a kernel via apt-get.</p>
<p>Before we can do this though we need to fix our hosts file so we can access the internet.</p>
<p>We’ll do this by copying the host file currently being used by our current boot drive.</p>
<ul>
<li>In a new terminal issue these commands</li>
</ul>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>sudo cp /mnt/etc/hosts /mnt/etc/hosts.old
</span><span class='line'>sudo cp /etc/hosts /mnt/etc/hosts
</span><span class='line'>sudo cp /etc/resolv.conf /mnt/etc/resolv.conf
</span><span class='line'><span class="nb">exit</span>
</span></code></pre></td></tr></table></div></figure>
<h3>Onto installing the kernel!</h3>
<p>There are three kernels that you can install, and it’s important to choose the correct one.</p>
<p>Ubuntu 12.10 and above</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install -y linux-image-generic
</span></code></pre></td></tr></table></div></figure>
<p>Ubuntu 12.04 64-bit</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install -y linux-image-generic
</span></code></pre></td></tr></table></div></figure>
<p>Ubuntu 12.04 32-bit < 3gig of RAM</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install -y linux-image-generic
</span></code></pre></td></tr></table></div></figure>
<p>Ubuntu 12.04 32-bit >3 gig of RAM</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install -y linux-image-generic-pae
</span></code></pre></td></tr></table></div></figure>
<p>Ubuntu 11.10 and below Server</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install -y linux-image-server
</span></code></pre></td></tr></table></div></figure>
<p>Ubuntu 11.10 and below 64-bit</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install -y linux-image-generic
</span></code></pre></td></tr></table></div></figure>
<p>Ubuntu 11.10 and below 32-bit < 3gig of RAM</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install -y linux-image-generic
</span></code></pre></td></tr></table></div></figure>
<p>Ubuntu 11.10 and below 32-bit >3 gig of RAM</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get install -y linux-image-generic-pae
</span></code></pre></td></tr></table></div></figure>
<p>Once the kernel is installed we can go ahead and remove the cloud-init package to improve boot times</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='bash'><span class='line'>apt-get remove cloud-init
</span></code></pre></td></tr></table></div></figure>
<h2>Boot the virtual machine</h2>
<p>Now we create a new virtual machine in Hyper-V using our newly cloned disk and boot.</p>
</div>
<div class="footer">
copyright christopher stafford 2013
</div>
</body>
</html>