Thursday 28 May 2015

Partial RAID-1 mounting

I recently (read: ages ago) needed to bring my RAID1 disks to a friend, and it seemed silly for a mirrored disk array to bring more than 1 harddisk. Surely a single harddisk would cover it? Mount it read-only and away we go.

Let's take /dev/sdb1 drive of an array {/dev/sdb1, /dev/sdc1}.

The simplest way is to just start up the raid array using mdadm with a single disk2. But for some reason I failed to get this to work.

One way to do it (according to [1]), is to assume that the raidarray uses ext4 as an underlying filesystem and then just fiddle with the offsets.

The command "mdadm --examine /dev/sdb1" shows "Data Offset : 262144 sectors".

Then create a loop device, starting from that offset multiplied by the mdadm sector size (512).
losetup --find --show --read-only --offset $((262144*512)) /dev/sdb1
Than, simply mount the loop device.
mount /dev/loop0 /mnt/raid1/

References

[1] StackExchange - How to mount/recover data on a disk that was part of a mdadm raid 1 on another machine?
http://unix.stackexchange.com/questions/64889/how-to-mount-recover-data-on-a-disk-that-was-part-of-a-mdadm-raid-1-on-another-m
[2] sleeplessbeastie's notes - How to mount software RAID1 member using mdadm
https://blog.sleeplessbeastie.eu/2012/05/08/how-to-mount-software-raid1-member-using-mdadm/

Thursday 21 May 2015

Mirroring a.k.a. RAID 1 - Followup

When connecting my two mirrored drives created with mdadm to another machine (my labtop in this case), this happens:

[ 3006.059308] usb 2-1.1: new high-speed USB device number 3 using ehci_hcd
[ 3006.145807] usb 2-1.1: New USB device found, idVendor=1058, idProduct=1021
[ 3006.145818] usb 2-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3006.145823] usb 2-1.1: Product: Ext HDD 1021
[ 3006.145828] usb 2-1.1: Manufacturer: Western Digital
[ 3006.145832] usb 2-1.1: SerialNumber: 574D43315431373033343231
[ 3006.149589] scsi8 : usb-storage 2-1.1:1.0
[ 3007.154933] scsi 8:0:0:0: Direct-Access WD Ext HDD 1021 2021 PQ: 0 ANSI: 4
[ 3007.157133] sd 8:0:0:0: [sdb] 3907024896 512-byte logical blocks: (2.00 TB/1.81 TiB)
[ 3007.157508] sd 8:0:0:0: Attached scsi generic sg2 type 0
[ 3007.158940] sd 8:0:0:0: [sdb] Write Protect is off
[ 3007.158956] sd 8:0:0:0: [sdb] Mode Sense: 17 00 10 08
[ 3007.160824] sd 8:0:0:0: [sdb] No Caching mode page present
[ 3007.160835] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[ 3007.166300] sd 8:0:0:0: [sdb] No Caching mode page present
[ 3007.166312] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[ 3007.182900] sdb: sdb1
[ 3007.188055] sd 8:0:0:0: [sdb] No Caching mode page present
[ 3007.188067] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[ 3007.188073] sd 8:0:0:0: [sdb] Attached SCSI disk
[ 3007.764265] md: bind
[ 3013.631277] usb 2-1.2: new high-speed USB device number 4 using ehci_hcd
[ 3013.717235] usb 2-1.2: New USB device found, idVendor=1058, idProduct=1021
[ 3013.717246] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 3013.717251] usb 2-1.2: Product: Ext HDD 1021
[ 3013.717256] usb 2-1.2: Manufacturer: Western Digital
[ 3013.717261] usb 2-1.2: SerialNumber: 574D43315432313138383334
[ 3013.718543] scsi9 : usb-storage 2-1.2:1.0
[ 3014.722760] scsi 9:0:0:0: Direct-Access WD Ext HDD 1021 2021 PQ: 0 ANSI: 4
[ 3014.724734] sd 9:0:0:0: Attached scsi generic sg3 type 0
[ 3014.725314] sd 9:0:0:0: [sdc] 3907024896 512-byte logical blocks: (2.00 TB/1.81 TiB)
[ 3014.727731] sd 9:0:0:0: [sdc] Write Protect is off
[ 3014.727744] sd 9:0:0:0: [sdc] Mode Sense: 17 00 10 08
[ 3014.729563] sd 9:0:0:0: [sdc] No Caching mode page present
[ 3014.729575] sd 9:0:0:0: [sdc] Assuming drive cache: write through
[ 3014.735276] sd 9:0:0:0: [sdc] No Caching mode page present
[ 3014.735287] sd 9:0:0:0: [sdc] Assuming drive cache: write through
[ 3014.753371] sdc: sdc1
[ 3014.758786] sd 9:0:0:0: [sdc] No Caching mode page present
[ 3014.758796] sd 9:0:0:0: [sdc] Assuming drive cache: write through
[ 3014.758802] sd 9:0:0:0: [sdc] Attached SCSI disk
[ 3015.063908] md: bind
[ 3015.153298] md: raid1 personality registered for level 1
[ 3015.153537] bio: create slab at 1
[ 3015.153667] md/raid1:md127: not clean -- starting background reconstruction
[ 3015.153670] md/raid1:md127: active with 2 out of 2 mirrors
[ 3015.153729] md127: detected capacity change from 0 to 2000261283840
[ 3015.161179] md127: unknown partition table
Turns out, a device is automatically made, called /dev/md127.

Thursday 14 May 2015

Operator Precedence

I see a number of people get the answer to the following equation wrong:
1 + 5 * 2
Depending who you talk to, it could either be 12 (6 * 2) or the appropriate and correct answer 11 (1 + 10).

Everybody knows the precedence of things, but to make matters clear, here's the list ordered in descending precedence:
  1. parenthesis (also known as brackets)
  2. exponents/roots
  3. multiplication/division
  4. addition/subtraction

Mnemonics

Several mnemonics are in use to remember the correct precedence. Below are three examples.

“Please Excuse My Dear Aunt Sally”
  • Parentheses
  • Exponents
  • Multiplication
  • Division
  • Addition
  • Subtraction

However, this mnemonic doesn't do justice to the fact that some operations actually have the same precedence, for example subtraction and addition.

“Hallo, Meneer van Dalen wacht op antwoord!”
  • Haakjes (Parentheses)
  • Machtsverheffen (Exponents)
  • Vermenigvuldigen (Multiplication)
  • Delen (Division)
  • Worteltrekken (Root)
  • Optellen (Addition)
  • Aftrekken (Subtraction)

This Dutch mnemonic is very very old (and very wrong nowadays). It indicates that roots are very low in priority. Also, if taken literally, it means there's a difference in precedence between, for example, addition and subtraction, similar to the English mnemonic.

“Hé, Mw. v/d Aorta!”

A different Dutch mnemonic (written above), also contains information regarding the equality of certain operations.
  1. Haakjes (Parentheses)
  2. Machtsverheffen (Exponents)/Worteltrekken (Root)
  3. Vermenigvuldigen (Multiplication)/Delen (Division)
  4. Aftrekken (Subtraction)/Optellen (Addition)
Unfortunately, it contains a number of abbreviations:
Mw.
mevrouw (misses)
v/d
van de (of)

References

Wikipedia - Order of operations
http://en.wikipedia.org/wiki/Order_of_operations
Wikipedia - Bewerkingsvolgorde
http://nl.wikipedia.org/wiki/Bewerkingsvolgorde