{"id":472,"date":"2013-09-03T12:00:39","date_gmt":"2013-09-03T10:00:39","guid":{"rendered":"http:\/\/dety.net.ua\/?p=472"},"modified":"2013-11-08T12:00:05","modified_gmt":"2013-11-08T10:00:05","slug":"amazon-ec2-ubuntu-raid","status":"publish","type":"post","link":"https:\/\/dety.net.ua\/?p=472","title":{"rendered":"Amazon EC2 + Ubuntu + Raid"},"content":{"rendered":"<p>I had to add Raid to the EC2 instance with Ubuntu.<\/p>\n<p>I chose RAID10.<\/p>\n<p>So,<\/p>\n<p>1. Add disks to the instance (I added 4 disks for RAID10):<\/p>\n<div>\n<div>\n<div>\n<blockquote>\n<h2 id=\"Using_AddingDefaultLocalInstanceStorageToAMI\">Adding Instance Store Volumes to an AMI<\/h2>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<blockquote><p>Amazon EBS-backed AMIs don&#8217;t include an instance store by default. However, you might want instances launched from your Amazon EBS-backed AMIs to include instance store volumes. This section describes how to create an AMI that includes instance store volumes.<\/p>\n<div>\n<div>\n<div>\n<h3 id=\"Using_AddingDefaultLocalInstanceStorageToAMI_console\">AWS Management Console<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<p><a name=\"d0e44349\"><\/a><\/p>\n<p><b>To add instance store volumes to an AMI<\/b><\/p><\/blockquote>\n<ol type=\"1\">\n<li>\n<blockquote><p>Open the Amazon EC2 console at <a href=\"https:\/\/console.aws.amazon.com\/ec2\/\" target=\"_blank\">https:\/\/console.aws.amazon.com\/ec2\/<\/a>.<\/p><\/blockquote>\n<\/li>\n<li>\n<blockquote><p>In the navigation pane, click Instances.<\/p><\/blockquote>\n<\/li>\n<li>\n<blockquote><p>Select an instance and select Create Image (EBS AMI) from the Actions list.<\/p><\/blockquote>\n<\/li>\n<li>\n<blockquote><p>In the Create Image dialog, add a meaningful name and description to your image.<\/p><\/blockquote>\n<\/li>\n<li>\n<blockquote><p>Click Instance Store Volumes.<\/p><\/blockquote>\n<\/li>\n<li>\n<blockquote><p>For each instance store volume, select a volume from the Instance Store list and a device name from Device, and then click Add.<\/p><\/blockquote>\n<div>\n<blockquote>\n<div><img decoding=\"async\" alt=\"Instance Store Volumes tab in the Create Image dialog box\" src=\"http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/images\/create-image-instance-store.png\" \/><\/div>\n<\/blockquote>\n<div><\/div>\n<div>took from Amazon: <a href=\"http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/InstanceStorage.html#Using_AddingDefaultLocalInstanceStorageToAMI\" target=\"_blank\">http:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/InstanceStorage.html#Using_AddingDefaultLocalInstanceStorageToAMI<\/a><\/div>\n<div>This step just create a new AMI for the next creating.<\/div>\n<div>For the current instance you have to create volumes on EBS and attach them to the instance.<\/div>\n<p>2. Install mdadm for RAID: <strong>sudo apt-get install mdadm<\/strong> (Choose e-mail configuration during install &#8211; I chose No configuration)<\/p>\n<div>3. The next step &#8211; check that Ubuntu doesn&#8217;t mount these disks automatically &#8211; I don&#8217;t know why Ubuntu mount it, so, unmount them if needed and edit fstab:<\/div>\n<div><strong>sudo umount \/mnt<\/strong><\/div>\n<div><\/div>\n<div>4. Create RAID10:<\/div>\n<div><strong>sudo mdadm &#8211;create &#8211;verbose \/dev\/md0 &#8211;level=10 &#8211;raid-devices=4 \/dev\/xvd[b-e]<\/strong><\/div>\n<div><\/div>\n<div>5. Monitor the creation: <strong>sudo cat \/proc\/mdstat <\/strong>or<strong> sudo watch cat \/proc\/mdstat<br \/>\n<\/strong><\/div>\n<div><\/div>\n<div>6. Update initramfs to up RAID after reboot:<\/div>\n<div><strong>sudo update-initramfs -u<\/strong><\/div>\n<div><\/div>\n<div>7. Format the new disk: <strong>sudo mkfs.ext4 \/dev\/md0<\/strong><\/div>\n<div><\/div>\n<div>8. Edit mdadm.conf:<\/div>\n<div>get UUID from<strong> sudo mdadm -Db \/dev\/md0<\/strong><\/div>\n<div>and add to mdadm.conf the next e.g.:<\/div>\n<blockquote>\n<div>DEVICES \/dev\/xvdk \/dev\/xvdh \/dev\/xvdi \/dev\/xvfl<\/div>\n<div>ARRAY \/dev\/md0 level=10 num-devices=4 metadata=1.2 UUID=2cfdb9f9:4126fc1b:3c32dc68:473d8c4e<\/div>\n<\/blockquote>\n<div><\/div>\n<div>9. Edit fstab:<\/div>\n<div><strong>sudo echo &#8220;\/dev\/md0 \/usr\/data ext4\u00a0defaults,nobootwait,noatime 0 0&#8221;<\/strong><\/div>\n<div>(\/usr\/data &#8211; mount point)<\/div>\n<div><\/div>\n<div>10. Make changes in \/etc\/initramfs-tools\/conf.d\/mdadm to allow boot with degraded RAID:<\/div>\n<div><strong>sudo nano \/etc\/initramfs-tools\/conf.d\/mdadm<\/strong><\/p>\n<blockquote><p># BOOT_DEGRADED:<br \/>\n# Do you want to boot your system if a RAID providing your root filesystem<br \/>\n# becomes degraded?<br \/>\n#<br \/>\n# Running a system with a degraded RAID could result in permanent data loss<br \/>\n# if it suffers another hardware fault.<br \/>\n#<br \/>\n# However, you might answer \u201cyes\u201d if this system is a server, expected to<br \/>\n# tolerate hardware faults and boot unattended.<br \/>\nBOOT_DEGRADED=yes<\/p><\/blockquote>\n<\/div>\n<div>For Red Hat and etc you need run the command dracut -f<\/div>\n<div>\n<p>What you need to do is something like this:<\/p>\n<pre><code>mkinitrd \/boot\/initrd-&lt;kernel-version&gt;.img &lt;kernel-version&gt;\r\n<\/code><\/pre>\n<p>I&#8217;m assuming here that the CentOS version you&#8217;re using is still using <code>mkinitrd<\/code> &#8211; if it has switched to <code>dracut<\/code> then you will want:<\/p>\n<pre><code>dracut \/boot\/initramfs-&lt;kernel-version&gt;.img &lt;kernel-version&gt;\r\n<\/code><\/pre>\n<\/div>\n<div>11. For getting e-mails about raid status you can add string like this MAILADDR mail@domain.com into mdadm.conf. You must have sendmail or another e-mailer.<\/div>\n<div><\/div>\n<div>12. Reboot and check.<\/div>\n<div>13. Conclusions:<\/div>\n<div>1. I did it in Ubuntu 12\u00a0 on the Amazon. I tried make RAID10 but it didn&#8217;t up after reboot and I lost the access to instances.<\/div>\n<div>So, I detached disk from instance, made a new instance in the same location us-east-1b and attached disk to the new VM, edited \/etc\/fstab, detached the disk again and attached it to the old instance (\/dev\/sda1 by default &#8211; check it before detaching) &#8211; I got the instances back and rebuild RAID sucessfully.<\/div>\n<div>2. If you have problems with raid and system doesn&#8217;t boot, you can detach disk and attach to another VM, then mount it and chroot. Then do some changes and do update-initramfs -u, then attach it to source VM.<\/div>\n<div>3. Make RAID only with EBS disks because internal (ephernal) disks will be cleaned after stop.<\/div>\n<div><\/div>\n<div>Script for temp disks:<\/div>\n<blockquote>\n<div>#!\/bin\/sh<\/div>\n<div>sudo mdadm &#8211;force &#8211;run &#8211;create &#8211;verbose \/dev\/md0 &#8211;level=10 &#8211;raid-devices=4 \/dev\/xvd[b-e]<\/div>\n<div>mkfs.ext4 \/dev\/md0<\/div>\n<div>mount \/dev\/md0 \/usr\/data<\/div>\n<\/blockquote>\n<div><\/div>\n<\/div>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I had to add Raid to the EC2 instance with Ubuntu. I chose RAID10. So, 1. Add disks to the instance (I added 4 disks for RAID10): Adding Instance Store Volumes to an AMI Amazon EBS-backed AMIs don&#8217;t include an instance store by default. However, you might want instances launched from your Amazon EBS-backed AMIs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,6,13],"tags":[],"class_list":["post-472","post","type-post","status-publish","format-standard","hentry","category-amazon","category-linux","category-novosti"],"_links":{"self":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=472"}],"version-history":[{"count":9,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions"}],"predecessor-version":[{"id":504,"href":"https:\/\/dety.net.ua\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions\/504"}],"wp:attachment":[{"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dety.net.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}