{"id":616,"date":"2010-04-04T23:22:56","date_gmt":"2010-04-05T03:22:56","guid":{"rendered":"https:\/\/lowtek.ca\/roo\/?p=616"},"modified":"2019-12-07T09:59:09","modified_gmt":"2019-12-07T13:59:09","slug":"how-to-resize-a-mirrored-volume","status":"publish","type":"post","link":"https:\/\/lowtek.ca\/roo\/2010\/how-to-resize-a-mirrored-volume\/","title":{"rendered":"How to: resize a mirrored volume"},"content":{"rendered":"<div><a href=\"http:\/\/www.flickr.com\/photos\/lindztrom\/2964704126\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" title=\"Apple &amp; Orange by lindztrom, on Flickr\" src=\"https:\/\/farm4.static.flickr.com\/3253\/2964704126_3ecf791022.jpg\" border=\"0\" alt=\"Apple &amp; Orange by lindztrom, on Flickr\" \/><\/a><br \/>\n<a href=\"http:\/\/creativecommons.org\/licenses\/by-nc-nd\/2.0\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" title=\"Creative Commons Attribution-Noncommercial-No Derivative Works 2.0 Generic License\" src=\"https:\/\/i.creativecommons.org\/l\/by-nc-nd\/2.0\/80x15.png\" border=\"0\" alt=\"Creative Commons Attribution-Noncommercial-No Derivative Works 2.0 Generic License\" align=\"left\" \/><\/a> by\u00a0<a href=\"http:\/\/www.flickr.com\/people\/lindztrom\/\" target=\"_blank\" rel=\"noopener noreferrer\"> lindztrom<\/a><a href=\"http:\/\/www.imagecodr.org\/\" target=\"_blank\" rel=\"noopener noreferrer\"> <\/a><\/div>\n<p>Having recently <a href=\"https:\/\/lowtek.ca\/roo\/2010\/mirrored-drives-with-ubuntu\/\">setup mirrored volumes with a pair of 1TB drives<\/a>, I could now migrate data off the pair of 250Gb data drives to allow me to combine those two drives into a single volume. \u00a0Way back when I purchased these drives I had intended to run a mirrored setup, but at the time decided that having more storage was more important. \u00a0I had &#8220;cleverly&#8221; purchased two 250Gb drives from different manufacturers, in theory to avoid concurrent failures. \u00a0It turns out that not all 250Gb drives are made the same.<\/p>\n<p>Following the instructions from my <a href=\"https:\/\/lowtek.ca\/roo\/2010\/mirrored-drives-with-ubuntu\/\">previous posting<\/a>, all went well up to where I tried to add the 2nd volume to the mirrored set. \u00a0If you run into a similar problem you&#8217;ll likely see one of the two following errors:<\/p>\n<p><code>mdadm: add new device failed for \/dev\/hda1 as 2: No space left on device<br \/>\nmdadm: add new device failed for \/dev\/hda1 as 2: Invalid argument<\/code><\/p>\n<p>I found some good <a href=\"http:\/\/www.tgunkel.de\/it\/software\/doc\/linux_server.en\">hints on how to diagnose the problem<\/a>, it turns out you can check the partition sizes manually<\/p>\n<p><code><strong>$ cat \/proc\/partitions<\/strong><br \/>\nmajor minor \u00a0#blocks \u00a0name<\/code><\/p>\n<p><code> <\/code><\/p>\n<p><code>8 \u00a0 \u00a017 \u00a0244196001 sdb1<br \/>\n8 \u00a0 \u00a065 \u00a0244198552 sde1<\/code><\/p>\n<p>Close, but not quite the same. \u00a0As it was, I had unluckily chosen \/dev\/sdb as the 1st drive in the mirrored set. \u00a0It turns out that fdisk tells an even more interesting story.<\/p>\n<p><code><strong>$ sudo fdisk -l \/dev\/sdb<\/strong><\/code><\/p>\n<p><code>Disk \/dev\/sdb: 250.0 GB, 250059350016 bytes<br \/>\n255 heads, 63 sectors\/track, 30401 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<br \/>\nDisk identifier: 0x000c0f4f<\/code><\/p>\n<p><code>Device Boot      Start         End      Blocks   Id  System<br \/>\n\/dev\/sdb1               1       30401   244196001   83  Linux<\/code><\/p>\n<p><code> <\/code><\/p>\n<p><code><strong>$ sudo fdisk -l \/dev\/sde<\/strong><\/code><\/p>\n<p><code>Disk \/dev\/sde: 250.0 GB, 250059350016 bytes<br \/>\n16 heads, 63 sectors\/track, 484521 cylinders<br \/>\nUnits = cylinders of 1008 * 512 = 516096 bytes<br \/>\nDisk identifier: 0x00000000<\/code><\/p>\n<p><code> <\/code><\/p>\n<p><code> Device Boot      Start         End      Blocks   Id  System<br \/>\n\/dev\/sde1               1      484521   244198552+  83  Linux<\/code><\/p>\n<p>Yuck, looks messy. At this point I&#8217;ve got some of my live data sitting on one half of the mirrored set, and no suitable 2nd drive to act as the mirror. \u00a0Somewhat predictably <a href=\"http:\/\/www.howtoforge.com\/how-to-resize-raid-partitions-shrink-and-grow-software-raid\">there is a solution<\/a> that minimizes downtime and avoids copying all of the data to a new location.<\/p>\n<p>First you unmount the volume and run resize2fs on it. \u00a0We don&#8217;t need to know the correct size, just any size smaller than the 2nd volume &#8211; so I used 200Gb.<\/p>\n<p><code><strong>$ sudo umount \/media\/data\/<\/strong><br \/>\n<strong> $ sudo e2fsck -f \/dev\/md2<\/strong><br \/>\ne2fsck 1.40.8 (13-Mar-2008)<br \/>\nPass 1: Checking inodes, blocks, and sizes<br \/>\nPass 2: Checking directory structure<br \/>\nPass 3: Checking directory connectivity<br \/>\nPass 4: Checking reference counts<br \/>\nPass 5: Checking group summary information<br \/>\n\/dev\/md2: 1890279\/15269888 files (0.2% non-contiguous), 32742192\/61049616 blocks<br \/>\n<strong> $ sudo resize2fs \/dev\/md2 200G<\/strong><br \/>\nresize2fs 1.40.8 (13-Mar-2008)<br \/>\nResizing the filesystem on \/dev\/md2 to 52428800 (4k) blocks.<br \/>\nThe filesystem on \/dev\/md2 is now 52428800 blocks long.<\/code><\/p>\n<p>Now we need to calculate what the correct size of the mirrored partition should be.  I looked at two bits of data: the size the mdadm -D reported for the partition I wanted to resize, and the size that was in \/proc\/partitions for the same.  These differed by 88 blocks, so I used the value 88 as a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Fudge_factor\">fudge factor<\/a> &#8211; it may not be required but it worked for me.  I then also ensured that I supplied a value that was an even multiple of 64 (blocks).<\/p>\n<p>So starting with\u00a0244196001 from \/proc\/partitions:<\/p>\n<p><code>(244196001 - 88) \/ 64 = 3815561.14<br \/>\n<\/code><br \/>\nDrop the decimal places and multiply by 64 to get the number of blocks.<\/p>\n<p><code>3815561 * 64 =\u00a0244195904<\/code><\/p>\n<p>Now we feed this new size into mdadm and specify the &#8211;grow flag (which can also be used to shrink if you specify a block size smaller than the current which is what we are doing in this case). \u00a0We then re-run resize2fs without a specified size, which will cause it to expand the filesystem to fill the partition.<\/p>\n<p><code><strong>$ sudo mdadm --grow \/dev\/md2 --size=244195904<\/strong><br \/>\n<strong> $ sudo resize2fs \/dev\/md2<\/strong><br \/>\nresize2fs 1.40.8 (13-Mar-2008)<br \/>\nResizing the filesystem on \/dev\/md2 to 61048976 (4k) blocks.<br \/>\nThe filesystem on \/dev\/md2 is now 61048976 blocks long.<\/code><\/p>\n<p>Now all that is left is to run a filesystem check, and remount it.<\/p>\n<p><code><strong>$sudo e2fsck -f \/dev\/md2<\/strong><br \/>\ne2fsck 1.40.8 (13-Mar-2008)<br \/>\nPass 1: Checking inodes, blocks, and sizes<br \/>\nPass 2: Checking directory structure<br \/>\nPass 3: Checking directory connectivity<br \/>\nPass 4: Checking reference counts<br \/>\nPass 5: Checking group summary information<br \/>\n\/dev\/md2: 1890279\/15269888 files (0.2% non-contiguous), 32742192\/61048976 blocks<br \/>\n<strong> $ sudo mount -a<\/strong><\/code><\/p>\n<p>Now when you attempt to add the 2nd volume, it will be a matching size and the mirror will work. \u00a0In the future, I intend to be a little more careful when I plan to setup mirrored drives and pick the smaller volume as the starting point.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>by\u00a0 lindztrom Having recently setup mirrored volumes with a pair of 1TB drives, I could now migrate data off the pair of 250Gb data drives to allow me to combine those two drives into a single volume. \u00a0Way back when I purchased these drives I had intended to run a mirrored setup, but at the &hellip; <a href=\"https:\/\/lowtek.ca\/roo\/2010\/how-to-resize-a-mirrored-volume\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to: resize a mirrored volume&#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-616","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\/616","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=616"}],"version-history":[{"count":4,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/616\/revisions"}],"predecessor-version":[{"id":1656,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/616\/revisions\/1656"}],"wp:attachment":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/media?parent=616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/categories?post=616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/tags?post=616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}