Linux RAID: Nastavení zrcadlení disků přes mdadm

Linux RAID: Nastavení zrcadlení disků přes mdadm

V následující modelové situaci provedeme nastavení zrcadlení disků (RAID 1 - mirror) /dev/sdc a /dev/sdb jako softwarový raid s nástrojem mdadm. Zkrácené to znamená následující - nainstalovat balíčky initramfs-tools a mdadm, vytvoření GPT oddílu pomocí gdisk, překopírování rozložení oddílů 1:1 mezi oběma disky s balíčkem sfdisk a konečně vytvoření diskového pole md0. Pro rozumné uživatele je na konci připojen i postup na zašifrování celého diskového pole /dev/md0 pomocí LUKS.

Linux mdadm: Nastavujeme RAID 1

user@server # apt-get install initramfs-tools mdadm #instalace
user@server # lsblk #výpis blokových zařízení (disků)

NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda              8:0    0 111,8G  0 disk  
├─sda1           8:1    0   487M  0 part  /boot
└─sda2           8:2    0 111,3G  0 part  
  └─sda2_crypt 252:0    0 111,3G  0 crypt /
sdb              8:16   0   1,8T  0 disk  
sdc              8:32   0   1,8T  0 disk  
sdd              8:48   0 465,8G  0 disk  
├─sdd1           8:49   0   450M  0 part  
├─sdd2           8:50   0   100M  0 part  
├─sdd3           8:51   0    16M  0 part  
├─sdd4           8:52   0  97,1G  0 part  
└─sdd5           8:53   0 368,1G  0 part 

user@server # gdisk /dev/sdc #vytvoření GPT oddílu

GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1): Enter
First sector (34-3907029134, default = 2048) or {+-}size{KMGTP}: Enter
Last sector (2048-3907029134, default = 3907029134) or {+-}size{KMGTP}: Enter
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): fd00
Changed type of partition to 'Linux RAID'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.

user@server # gdisk -l /dev/sdc #kontrola rozložení

GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sdc: 3907029168 sectors, 1.8 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): ABE09C96-41FB-4BD8-B53F-2BAAC39BD654
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 3907029134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      3907029134   1.8 TiB     FD00  Linux RAID

user@server # sfdisk -d /dev/sdc | sfdisk /dev/sdb #překlonování rozložení oddílů

Checking that no-one is using this disk right now ... OK

Disk /dev/sdb: 1,8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new GPT disklabel (GUID: ABE09C96-41FB-4BD8-B53F-2BAAC39BD654).
Created a new partition 1 of type 'Linux RAID' and of size 1,8 TiB.
/dev/sdb2: 
New situation:

Device     Start        End    Sectors  Size Type
/dev/sdb1   2048 3907029134 3907027087  1,8T Linux RAID

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

user@server # lsblk #výpis pro kontrolu

NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda              8:0    0 111,8G  0 disk  
├─sda1           8:1    0   487M  0 part  /boot
└─sda2           8:2    0 111,3G  0 part  
  └─sda2_crypt 252:0    0 111,3G  0 crypt /
sdb              8:16   0   1,8T  0 disk  
└─sdb1           8:17   0   1,8T  0 part  
sdc              8:32   0   1,8T  0 disk  
└─sdc1           8:33   0   1,8T  0 part  
sdd              8:48   0 465,8G  0 disk  
├─sdd1           8:49   0   450M  0 part  
├─sdd2           8:50   0   100M  0 part  
├─sdd3           8:51   0    16M  0 part  
├─sdd4           8:52   0  97,1G  0 part  
└─sdd5           8:53   0 368,1G  0 part  

user@server # mdadm --create /dev/md0 --level=1 --raid-disks=2 /dev/sdc1 /dev/sdb1 #konečně vytvoření raidového pole

mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

user@server # mdadm -D /dev/md0 #kontrola stavu diskového pole

/dev/md0:
        Version : 1.2
  Creation Time : Mon Oct 16 14:09:35 2017
     Raid Level : raid1
     Array Size : 1953382464 (1862.89 GiB 2000.26 GB)
  Used Dev Size : 1953382464 (1862.89 GiB 2000.26 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

  Intent Bitmap : Internal

    Update Time : Mon Oct 16 14:10:51 2017
          State : clean, resyncing 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

  Resync Status : 0% complete

           Name : server:0  (local to host server)
           UUID : e05778a4:a880b7bb:d25596aa:d6a9c4d3
         Events : 15

    Number   Major   Minor   RaidDevice State
       0       8       33        0      active sync   /dev/sdc1
       1       8       17        1      active sync   /dev/sdb1

user@server # cat /proc/mdstat #kontrola stavu diskového pole

Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 sdb1[1] sdc1[0]
      1953382464 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  0.5% (10889088/1953382464) finish=247.7min speed=130679K/sec
      bitmap: 15/15 pages [60KB], 65536KB chunk

unused devices: 

A jdeme RAID šifrovat :-)

user@server # cryptsetup -y -v luksFormat -c aes-xts-plain64 -s 512 /dev/md0 #vytvoření šifrovaného oddílu

WARNING!
========
This will overwrite data on /dev/md0 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase: 
Verify passphrase: 
Command successful.

user@server # cryptsetup luksOpen /dev/md0 luks1 #dešifrování šifrovaného oddílu

Enter passphrase for /dev/md0: heslo k zašifrování

user@server # mkfs.ext4 /dev/mapper/luks1 #formátování oddílu na ext4

mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 488345104 4k blocks and 122093568 inodes
Filesystem UUID: 06a2cca9-c547-4892-a5f7-008648333fd4
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

A pro jistotu i cvičně dešifrovat a mountnout

user@server # cryptsetup luksOpen /dev/md0 disk #dešifrování šifrovaného oddílu
user@server # mount /dev/mapper/disk /mnt/disk #mount dešifrovaného oddílu

# Data tedy budou dostupná na /mnt/disk
Jak se ti článek líbil?

Komentáře (0)

Přidat komentář