{"id":161,"date":"2008-03-20T22:23:56","date_gmt":"2008-03-20T21:23:56","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/archives\/2008\/03\/20\/raid-1-sans-disks\/"},"modified":"2008-12-07T00:13:52","modified_gmt":"2008-12-06T23:13:52","slug":"raid-1-sans-disks","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2008\/03\/20\/raid-1-sans-disks\/","title":{"rendered":"RAID-1 sans disks"},"content":{"rendered":"<p>In preparation for a somewhat more dramatic future experiment, I&#8217;ve been trying out RAID-1 failure modes using linux&#8217;s loopback capabilities to avoid having to actually buy any more real hard drives.  You can simulate drive failures, failover and easily see what the current disk contents are.  It should go without saying that, if you have a real RAID system currently running, you probably don&#8217;t want to execute these commands without thinking a bit first:<\/p>\n<pre lang=\"bash\">\r\n# Creating and destroying disks from the safety of your own console\r\nmkdir ~\/raid; cd ~\/raid\r\n\r\n# Create two 10Mb files called disk0 and disk1\r\nfor d in 0 1; do dd if=\/dev\/zero of=disk${d} bs=1024 count=10240; done\r\n\r\n# Make them available as block devices using the loopback device\r\nfor d in 0 1; do sudo losetup \/dev\/loop$d disk$d; done\r\n\r\n# Combine the two 'disks' into a RAID-1 mirrored block device\r\n# Using '--build' rather than '--create' means there is no device\r\n# specific metadata, and so the contents of the disks will be identical\r\nsudo mdadm --build --verbose \/dev\/md0 --level=1 --raid-devices=2 \/dev\/loop[01]\r\n\r\n# Create a filesystem on our raid device and mount it\r\nsudo mkfs.ext3 \/dev\/md0 \r\nmkdir \/tmp\/raidmnt\r\nsudo mount \/dev\/md0 \/tmp\/raidmnt\r\nsudo chown $USER \/tmp\/raidmnt\r\n\r\n# The contents of both disks change in unison\r\nmd5sum disk[01]\r\ndate > \/tmp\/raidmnt\/datefile\r\nsync\r\nmd5sum disk[01]\r\n\r\n# If we mark one disk as failed, disk contents diverge\r\nsudo mdadm --fail \/dev\/md0 \/dev\/loop0\r\ndate > \/tmp\/raidmnt\/datefile\r\nsync\r\nmd5sum disk[01]\r\n\r\n# Remove the failed disk and readd it, and RAID1 will sync\r\nsudo mdadm --remove \/dev\/md0 \/dev\/loop0\r\nsudo mdadm --add \/dev\/md0 \/dev\/loop0\r\nsleep 1\r\nmd5sum disk[01]\r\n\r\n# Add a third (unused) disk into the system to test failover\r\ndd if=\/dev\/zero of=disk2 bs=1024 count=10240\r\nsudo losetup \/dev\/loop2 disk2\r\nsudo mdadm --add \/dev\/md0 \/dev\/loop2\r\nsudo mdadm --detail \/dev\/md0\r\n\r\n# When one of original two disks fail, the new disk gets used\r\nmd5sum disk[012]\r\nsudo mdadm --fail \/dev\/md0 \/dev\/loop0\r\ndate > \/tmp\/raidmnt\/datefile\r\nsync\r\nmd5sum disk[012]\r\n\r\n# Tidy up the world\r\nsudo umount \/dev\/md0\r\nsudo mdadm -S \/dev\/md0\r\nfor x in \/dev\/loop[012]; do sudo losetup -d $x; done\r\nrm -rf \/tmp\/raidmnt ~\/raid\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In preparation for a somewhat more dramatic future experiment, I&#8217;ve been trying out RAID-1 failure modes using linux&#8217;s loopback capabilities to avoid having to actually buy any more real hard drives. You can simulate drive failures, failover and easily see what the current disk contents are. It should go without saying that, if you have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[29,13],"class_list":["post-161","post","type-post","status-publish","format-standard","hentry","category-general","tag-raid","tag-unix"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":1,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":201,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/161\/revisions\/201"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}