{"id":582,"date":"2010-03-06T23:27:09","date_gmt":"2010-03-07T03:27:09","guid":{"rendered":"https:\/\/lowtek.ca\/roo\/?p=582"},"modified":"2010-03-06T23:27:09","modified_gmt":"2010-03-07T03:27:09","slug":"mirrored-drives-with-ubuntu","status":"publish","type":"post","link":"https:\/\/lowtek.ca\/roo\/2010\/mirrored-drives-with-ubuntu\/","title":{"rendered":"Mirrored Drives with Ubuntu"},"content":{"rendered":"<p><a href=\"https:\/\/lowtek.ca\/roo\/wp-content\/uploads\/2010\/03\/IMG_0005.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-583\" title=\"IMG_0005\" src=\"https:\/\/lowtek.ca\/roo\/wp-content\/uploads\/2010\/03\/IMG_0005.jpg\" alt=\"\" width=\"500\" height=\"379\" \/><\/a><\/p>\n<p>Mirrored drives are also known as a <a href=\"http:\/\/en.wikipedia.org\/wiki\/RAID#RAID_1\">RAID 1<\/a> configuration. \u00a0It is important to note that running mirrored drives should not be used as a substitute for doing backups. \u00a0My motivation for running a RAID 1 is simply that with the drive densities today, I expect these drives to fail. \u00a0A terabyte unit is <a href=\"http:\/\/redflagdeals.pricecanada.com\/p.php\/Western-Digital-Caviar-Green-1TB-SATA2-WD10EADS-579400\/\">cheap enough<\/a> that multiplying the cost by two isn&#8217;t a big deal, and it gives my data a better chance of surviving a hardware failure.<\/p>\n<p>I purchased two identical drives several months apart &#8211; in the hopes of getting units from different batches. I even put them into use staggered by a few months as well. \u00a0The intent here was to try to avoid simultaneous failure of the drives due to similarities in manufacture date \/ usage. \u00a0In the end, the environment they are in is probably a bigger factor in leading to failure but what can you do?<\/p>\n<p>Linux has reasonable <a href=\"http:\/\/en.wikipedia.org\/wiki\/RAID#Operating_system_based_.28.22software_RAID.22.29\">software raid<\/a> support. \u00a0There is a debate of the merits of software raid vs. hardware raid, as well as which level of raid is most useful. \u00a0I leave this as an exercise up to the reader. \u00a0The remainder of this posting will be the details of setting up a raid 1 on a live system. \u00a0I found two forum <a href=\"http:\/\/ubuntuforums.org\/showthread.php?t=1027240\">postings that talked about this process<\/a>, the <a href=\"http:\/\/ubuntuforums.org\/showthread.php?t=705780\">latter being most applicable<\/a>.<\/p>\n<p>We will start with the assumption that you do have the drive physically installed into your system. \u00a0The first step is to partition the disk. \u00a0I prefer using <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cfdisk\">cfdisk<\/a>, but <a href=\"http:\/\/en.wikipedia.org\/wiki\/Fdisk\">fdisk<\/a> will work too. \u00a0This is always a little scary, but if this is a brand new drive it should not have an existing partition table. \u00a0In my scenario I wanted to split the 1TB volume into two partitions, a 300Gb and a 700Gb.<\/p>\n<p>Now let&#8217;s use fdisk to dump the results of our partitioning work:<\/p>\n<p><code>$ sudo fdisk -l \/dev\/sdd<\/code><\/p>\n<p><code>Disk \/dev\/sdd: 1000.2 GB, 1000204886016 bytes<br \/>\n255 heads, 63 sectors\/track, 121601 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<br \/>\nDisk identifier: 0x00000000<\/code><\/p>\n<p><code> <\/code><\/p>\n<p><code>Device Boot \u00a0 \u00a0 \u00a0 \u00a0 Start \u00a0 \u00a0 \u00a0 \u00a0 End \u00a0 \u00a0 \u00a0Blocks \u00a0 Id \u00a0System<br \/>\n\/dev\/sdd1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 1 \u00a0 \u00a0 \u00a0 36473 \u00a0 292969341 \u00a0 83 \u00a0Linux<br \/>\n\/dev\/sdd2 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 36474 \u00a0 \u00a0 \u00a0121601 \u00a0 683790660 \u00a0 83 \u00a0Linux<br \/>\n<\/code><\/p>\n<p>Next we need to install the RAID tools if you don&#8217;t have them already:<\/p>\n<p><code>$ sudo apt-get install mdadm initramfs-tools<\/code><\/p>\n<p>Now recall that we are doing this in a live system, I&#8217;ve already got another 1TB volume (\/dev\/sda) partitioned and full of data I want to keep.   So we&#8217;re going to create the RAID array in a degraded state, this is the reason for the use of the &#8216;missing&#8217; option.  As I have two partitions I need to run the create command twice, once for each of them.<\/p>\n<p><code>$ sudo mdadm --create --verbose \/dev\/md0 --level=mirror --raid-devices=2 missing \/dev\/sdd1<br \/>\n$ sudo mdadm --create --verbose \/dev\/md1 --level=mirror --raid-devices=2 missing \/dev\/sdd2<\/code><\/p>\n<p>Now we can take a look at \/proc\/mdstat to see how things look:<\/p>\n<p><code>$ cat \/proc\/mdstat<br \/>\nPersonalities : [raid1]<br \/>\nmd1 : active raid1 sdd2[1]<br \/>\n683790592 blocks [2\/1] [_U]<\/code><\/p>\n<p><code> <\/code><\/p>\n<p><code>md0 : active raid1 sdd1[1]<br \/>\n292969216 blocks [2\/1] [_U]<\/code><\/p>\n<p><code>unused devices: &lt;none&gt;<\/code><\/p>\n<p>Now we format the new volumes. I&#8217;m using <a href=\"http:\/\/en.wikipedia.org\/wiki\/Ext3\">ext3 filesystems<\/a>, feel free to choose your favorite.<\/p>\n<p><code>$ sudo mkfs -t ext3 \/dev\/md0<br \/>\n$ sudo mkfs -t ext3 \/dev\/md1<\/code><\/p>\n<p>Mount the newly formatted partitions and copy data to it from the existing drive.  I used <a href=\"http:\/\/en.wikipedia.org\/wiki\/Rsync\">rsync<\/a> to perform this as it is an easy way to maintain permissions, and as I&#8217;m working on a live system I can re-do the rsync later to grab any updated files before I do the actual switch over.<\/p>\n<p><code>$ sudo mount \/dev\/md0 \/mntpoint<br \/>\n$ sudo rsync -av \/source\/path \/mntpoint<br \/>\n<\/code><\/p>\n<p>Once the data is moved, and you need to make the new copy of the data on the new degraded mirror volume the live one.  Now unmount the original 1TB drive.  Assuming things look ok on your system (no lost data) now we partition that drive we just unmounted (double and triple check the device names!) and format those new partitions.<\/p>\n<p>All that is left to do is add the new volume(s) to the array:<\/p>\n<p><code>$ sudo mdadm \/dev\/md0 --add \/dev\/sda1<br \/>\n$ sudo mdadm \/dev\/md1 --add \/dev\/sda2<\/code><\/p>\n<p>Again we can check \/proc\/mdstat to see the status of the array.  Or use the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Watch_(Unix)\">watch command<\/a> on the same file to monitor the progress.<\/p>\n<p><code>$ cat \/proc\/mdstat<br \/>\nPersonalities : [raid1]<br \/>\nmd1 : active raid1 sdd2[1]<br \/>\n683790592 blocks [2\/1] [_U]<\/code><\/p>\n<p><code>md0 : active raid1 sda1[2] sdd1[1]<br \/>\n292969216 blocks [2\/1] [_U]<\/code><code> [&gt;....................]  recovery =  0.6% (1829440\/292969216) finish=74.2min speed=65337K\/sec<\/code><\/p>\n<p><code>unused devices: &lt;none&gt;<\/code><\/p>\n<p>That&#8217;s all there is to it. \u00a0Things get a bit more complex if you are working on your root volume, but in my case I was simply mirroring one of my data volumes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mirrored drives are also known as a RAID 1 configuration. \u00a0It is important to note that running mirrored drives should not be used as a substitute for doing backups. \u00a0My motivation for running a RAID 1 is simply that with the drive densities today, I expect these drives to fail. \u00a0A terabyte unit is cheap &hellip; <a href=\"https:\/\/lowtek.ca\/roo\/2010\/mirrored-drives-with-ubuntu\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Mirrored Drives with Ubuntu&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,12],"tags":[],"class_list":["post-582","post","type-post","status-publish","format-standard","hentry","category-computing","category-how-to"],"_links":{"self":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/comments?post=582"}],"version-history":[{"count":11,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/582\/revisions"}],"predecessor-version":[{"id":594,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/582\/revisions\/594"}],"wp:attachment":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/media?parent=582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/categories?post=582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/tags?post=582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}