Vor ein paar Tagen hatte ich auf der Arbeit ein paar Minuten Zeit und habe mich mal mit dem Thema Software-RAID1 beschäftigt. Da ich aber leider keine 2 1TB-USB-Platten zur Verfügung hatte, habe ich das Ganze auf einer SD-Karte probiert. Ist zwar völlig sinnlos - funktioniert aber ohne größere Probleme. Es sollte daher auch mit 2 externen USB-Platten gehen. Dazu sind nur die Device-Nodes /dev/mmcblk0p* durch die entsprechenden Nodes (wahrscheinlich /dev/sdx*) zu ersetzen.
Schritt 1 - vorbereiten der SD-Karten - Aufteilen in zwei Partitionen
root@debian:/$ fdisk /dev/mmcblk0
The number of cylinders for this disk is set to 2860.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/mmcblk0: 2059 MB, 2059403264 bytes
38 heads, 37 sectors/track, 2860 cylinders
Units = cylinders of 1406 * 512 = 719872 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2860, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2860, default 2860): 1430
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1431-2860, default 1431):
Using default value 1431
Last cylinder, +cylinders or +size{K,M,G} (1431-2860, default 2860):
Using default value 2860
Command (m for help): p
Disk /dev/mmcblk0: 2059 MB, 2059403264 bytes
38 heads, 37 sectors/track, 2860 cylinders
Units = cylinders of 1406 * 512 = 719872 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 1 1430 1005271+ 83 Linux
/dev/mmcblk0p2 1431 2860 1005290 83 Linux
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/mmcblk0: 2059 MB, 2059403264 bytes
38 heads, 37 sectors/track, 2860 cylinders
Units = cylinders of 1406 * 512 = 719872 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 1 1430 1005271+ fd Linux raid autodetect
/dev/mmcblk0p2 1431 2860 1005290 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
root@debian:/$ reboot
Was ist denn da gerade passiert? Eigentlich Ganz einfach: Ich habe zwei primäre Partitionen angelegt und den vorhanden Speicherplatz zwischen diesen 1:1 aufgeteilt.Anschließen wurde der Partitionstyp auf "Linux raid autodetect" gesetzt und das System rebootet. Weiter geht's!
Schritt 2 - Installation der Initramfs-tools und mdadm
Nun installieren wir die initramfs-tools und mdadm. Sollten diese schon vorhanden sein: auch gut.
root@debian:/$ apt-get install initramfs-tools mdadm
Reading package lists... Done
Building dependency tree
Reading state information... Done
initramfs-tools is already the newest version.
mdadm is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Schritt 3 - RAID checken, bereinigen erzeugen und starten
Nun gehen wir hin und checken mal, was wir denn schon so an RAIDs im System haben. Naja. Keine halt. Dann leeren wir die Superblocks der SD-Kartenartitionen, für den Fall, dass da irgendwelche seltsamen Experimente Ihre Spuren hinterlassen haben.
root@debian:/$ cat /proc/mdstatNun folgt der Mühe Lohn: Wir erzeugen unser neues Raid 'Level 1'
Personalities : [linear] [raid0] [raid1] [raid6] [raid5] [raid4]
unused devices:
root@debian:/$ mdadm --zero-superblock /dev/mmcblk0p1
mdadm: Unrecognised md component device - /dev/mmcblk0p1
root@debian:/$ mdadm --zero-superblock /dev/mmcblk0p2
mdadm: Unrecognised md component device - /dev/mmcblk0p2
root@debian:/$ mdadm --create /dev/md0 --level=1 --raid-disks=2 /dev/mmcblk0p1 /dev/mmcblk0p2Wenn man nix anderen zu tun hat, kann man jetzt dem ersten Sync zuschauen. Ich gehe in so Situationen immer zu unseren Windows-Admins eine Kaffee trinken und Grundsatzdiskussionen führen.
mdadm: array /dev/md0 started.
root@debian:/$ watch cat /proc/mdstatSoweit, sogut! Was uns nun noch fehlt, ist ein Dateisystem. Also braten wir dem neuen Device /dev/md0 unseren Stempel auf!
Personalities : [linear] [raid0] [raid1] [raid6] [raid5] [raid4]
md0 : active raid1 mmcblk0p2[1] mmcblk0p1[0]
1005184 blocks [2/2] [UU]
[=========>...........] resync = 47.5% (479196/1005184) finish=4.7min speed=1823K/sec
unused devices:
root@debian:/$ mkfs.ext3 /dev/md0Nun können wir das neue und fertige Device mounten und uns mal anschauen, was an Speicher übriggeblieben ist. Naja, nur die Hälfte ;-)
mke2fs 1.41.4 (27-Jan-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
62848 inodes, 251296 blocks
12564 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=260046848
8 block groups
32768 blocks per group, 32768 fragments per group
7856 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@debian:/$ mkdir /mnt/raid1Es kann sein, dass das /dev/md0 den nächsten Reboot nicht übersteht. In diesem Fall muss die mdadm.conf erweitert werden. Bei mir war das nicht erforderlich...
root@debian:/$ mount /dev/md0 /mnt/raid1/
root@debian:/$ df -h /dev/md0
Filesystem Size Used Avail Use% Mounted on
/dev/md0 967M 18M 900M 2% /mnt/raid1
root@debian:~# mdadm --examine --scan
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=71afdab4:e906dd0c:9d4deba6:47ca997f
root@debian:~# cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig
root@debian:~# mdadm --examine --scan >> /etc/mdadm/mdadm.conf
Damit das RAID beim Reboot automatisch gemounted wird, muss die /etc/fstab angepasst werden:
/dev/md0 /mnt/raid1 ext3 defaults 0 0Und nun: viel Spass mit Eurem SD-Karten-RAID1 ;-)





