絖綛 N@i.jp  昨日:00051060
 今日:00033483
 総計:00136850
keywords
管理者専用
  Post   Add link   Control Panel 































新しいトピック
最新:03/21 19:08


新しいコメント
最新:07/28 16:47






管理人へMAIL

プライバシーポリシー

USBメモリでRAID 5を構築(1)

参照:RAID - ArchWiki


Raspberry Pi 3で、USBメモリ3本使ってRAID 5を構築した際の作業メモ


 Raspberry Pi 3を省電力ファイルサーバとして使うべく、USBメモリを3本使ってRAID 5を構築してみました。その際の作業メモを残しておこうと思います。ただ、長いので少しづつ書きますね。(最後の方は忘れてて内容がイイカゲンになるかも^^;)

 基本的な手順は以下のようになります。

  1. USBメモリのデバイス名を調べる
  2. パーティションの再設定
  3. デバイス名の固定
  4. mdadmのインストール
  5. RAIDアレイの構築
  6. RAIDアレイの構成情報記録
  7. ファイルシステムの作成
  8. マウント設定
  9. 再起動(動作確認)
  10. 監視と通知の設定
  11. USBメモリのエージング(USBメモリの寿命差を作る。これは数ヵ月後に作業予定)

OSはRaspbian Jessie。作業はすべてrootユーザになって行います。

1. USBメモリのデバイス名を調べる

 先ず、USBメモリをUSBポートに挿す前に/dev/sd* を調べておきます。USBポートにUSBメモリを挿していない状態では、/dev/sd* は存在していない筈ですので、

# ls /dev/sd*
ls: /dev/sd* にアクセスできません: そのようなファイルやディレクトリはありません

となります。既に外付けHDD等を繋いでいる場合は、それのデバイスが表示されますので、それを憶えておきます。
 次に、USBポートにUSBメモリを挿し、再び/dev/sd*が存在するか(または、増えたデバイスがあるか)調べます。

# ls /dev/sd*
/dev/sda  /dev/sda1

 /dev/sda, /dev/sda1が現われました。これが今USBポートに挿したUSBメモリのデバイスですね。fdiskコマンドで見てみます。

# fdisk -l /dev/sda
Disk /dev/sda: 58.9 GiB, 63199772672 bytes, 123437056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1          64 123437055 123436992 58.9G  c W95 FAT32 (LBA)

 購入したUSBメモリのサイズ、FAT32でフォーマットされている事から、/dev/sdaで間違いありません。

2. パーティションの再設定

 現在のFAT32にフォーマットされているパーティションを削除して、RAID用のパーティションに設定しなおします。パーティションの削除、設定にはfdiskコマンドを使います。

# fdisk /dev/sda

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d        ←パーティションの削除
Selected partition 1
Partition 1 has been deleted.

Command (m for help): n        ←パーティションの追加
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):            ←プライマリパーティションを指定(default. 何も入力せずEnter)

Using default response p.
Partition number (1-4, default 1): 1          ←1番目のパーティションを指定
First sector (2048-123437055, default 2048):  ←開始セクタ(default. 何も入力せずEnter)
Last sector, +sectors or +size{K,M,G,T,P} (2048-123437055, default 123437055): ←終了セクタ(default. 何も入力せずEnter)

Created a new partition 1 of type 'Linux' and of size 58.9 GiB.  ★パーティションが作成された

Command (m for help): l       ←パーティションタイプの一覧表示

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix

Command (m for help): t         ←パーティションタイプを変更
Selected partition 1
Hex code (type L to list all codes): fd    ←Linux raid autoを指定
Changed type of partition 'Linux' to 'Linux raid autodetect'.  ★RAIDパーティションタイプに変更された

Command (m for help): w         ←パーティションテーブルに書き込んで終了
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

#

 確認してみます。

# fdisk -l /dev/sda

Disk /dev/sda: 58.9 GiB, 63199772672 bytes, 123437056 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1        2048 123437055 123435008 58.9G fd Linux raid autodetect

このように表示されればOK。同様に、他のUSBメモリもUSBポートに挿してパーティションを作成していきます。

3. デバイス名を固定する

 /dev/sd* というデバイス名は、OSがデバイスを認識した順に割り振られるらしく、再起動やUSBメモリの抜き差しでデバイス名が変わってしまうことがあります。デバイス名が変わるとRAID構成が崩れてしまうそうなので、udev機能で各USBメモリ固有のデバイス名を付けてデバイス名を固定します。

 でも、この作業が本当に必要なのか、イマイチ分かってません。と言うのも、後で構築されたRAIDアレイの情報を見る(mdadm --detail /dev/md0)と、構成デバイス名は /dev/sd* の方で表示されていますし、構成情報にはUUIDで記録されている様子だからです。
  1. デバイスの情報を取得する

     "udevadm info -a -n /dev/sda"でデバイスの詳細な情報が表示されますが、出力される量があまりに多い(*1)。とりあえずシリアル番号で固定する方針で、serialだけを抽出します。

    # udevadm info -a -n /dev/sda | grep serial
        ATTRS{serial}=="55WWWN4CFK04UUMU"
        ATTRS{serial}=="3f980000.usb"
    # udevadm info -a -n /dev/sdb | grep serial
        ATTRS{serial}=="55F61HE3NQYMG17D"
        ATTRS{serial}=="3f980000.usb"
    # udevadm info -a -n /dev/sdc | grep serial
        ATTRS{serial}=="55F6ZK9OLK1G4LEA"
        ATTRS{serial}=="3f980000.usb"
    
  2. udevのルールファイルを作る

     udevのルールファイルは"/etc/udev/rules.d"配下に置きます。

    # cd /etc/udev/rules.d
    # ls -l
    -rw-r--r-- 1 root root 114  3月 18 17:45 40-scratch.rules
    -rw-r--r-- 1 root root 983  3月 21 22:43 99-com.rules

    上記のように、既に2つのファイルがありますが、これらを編集するのではなく、新しいファイルを追加します。先頭の数字は優先順位ですので、一番最後に追加されるよう、例えば"99-usbmem.rules"という名前のファイルを任意のエディタ(以下ではviを使用)で作成します。

    # vi 99-usbmem.rules

    ファイルの内容は、

    KERNEL=="sd*", SUBSYSTEMS=="usb", ATTRS{serial}=="55WWWN4CFK04UUMU", SYMLINK+="usbma%n"
    KERNEL=="sd*", SUBSYSTEMS=="usb", ATTRS{serial}=="55F61HE3NQYMG17D", SYMLINK+="usbmb%n"
    KERNEL=="sd*", SUBSYSTEMS=="usb", ATTRS{serial}=="55F6ZK9OLK1G4LEA", SYMLINK+="usbmc%n"

    こんな感じ。

  3. USBメモリを一旦抜き、再び挿してシンボリックリンクが作成されるか確認する
    # ls -l /dev/usbm*
    lrwxrwxrwx 1 root root 3  7月 30 10:52 /dev/usbma -> sda
    lrwxrwxrwx 1 root root 4  7月 30 10:52 /dev/usbma1 -> sda1
    lrwxrwxrwx 1 root root 3  7月 30 10:52 /dev/usbmb -> sdb
    lrwxrwxrwx 1 root root 4  7月 30 10:52 /dev/usbmb1 -> sdb1
    lrwxrwxrwx 1 root root 3  7月 30 10:52 /dev/usbmc -> sdc
    lrwxrwxrwx 1 root root 4  7月 30 10:52 /dev/usbmc1 -> sdc1

     ちゃんと作成されていますね。もしUSBメモリが壊れても、"/etc/udev/rules.d/99-usbmem.rules"を書き換えれば、同じデバイス名でアクセスできるようになる(と思う)。

[続く]

(*1):udevadmで表示された全情報。色々と興味深い情報が表示されてます。ATTRS{bMaxPower}=="300mA"って、このUSBメモリは最大300mAを要求してるってことかい?

# udevadm info -a -n /dev/sda

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.4/1-1.5.4:1.0/host1/target1:0:0/1:0:0:0/block/sda':
    KERNEL=="sda"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{ro}=="0"
    ATTR{size}=="123437056"
    ATTR{stat}=="     341        0     5376      220        2        0        8        0        0      190      220"
    ATTR{range}=="16"
    ATTR{discard_alignment}=="0"
    ATTR{events}=="media_change"
    ATTR{ext_range}=="256"
    ATTR{events_poll_msecs}=="2000"
    ATTR{alignment_offset}=="0"
    ATTR{inflight}=="       0        0"
    ATTR{removable}=="1"
    ATTR{capability}=="51"
    ATTR{events_async}==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.4/1-1.5.4:1.0/host1/target1:0:0/1:0:0:0':
    KERNELS=="1:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{rev}=="1100"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="7"
    ATTRS{model}=="Transcend 64GB  "
    ATTRS{state}=="running"
    ATTRS{queue_type}=="none"
    ATTRS{iodone_cnt}=="0x77e"
    ATTRS{iorequest_cnt}=="0x77e"
    ATTRS{device_busy}=="0"
    ATTRS{evt_capacity_change_reported}=="0"
    ATTRS{timeout}=="30"
    ATTRS{evt_media_change}=="0"
    ATTRS{max_sectors}=="240"
    ATTRS{ioerr_cnt}=="0x7"
    ATTRS{queue_depth}=="1"
    ATTRS{vendor}=="JetFlash"
    ATTRS{evt_soft_threshold_reached}=="0"
    ATTRS{device_blocked}=="0"
    ATTRS{evt_mode_parameter_change_reported}=="0"
    ATTRS{evt_lun_change_reported}=="0"
    ATTRS{evt_inquiry_change_reported}=="0"
    ATTRS{iocounterbits}=="32"
    ATTRS{inquiry}==""
    ATTRS{eh_timeout}=="10"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.4/1-1.5.4:1.0/host1/target1:0:0':
    KERNELS=="target1:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.4/1-1.5.4:1.0/host1':
    KERNELS=="host1"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.4/1-1.5.4:1.0':
    KERNELS=="1-1.5.4:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb-storage"
    ATTRS{bInterfaceClass}=="08"
    ATTRS{bInterfaceSubClass}=="06"
    ATTRS{bInterfaceProtocol}=="50"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{authorized}=="1"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.4':
    KERNELS=="1-1.5.4"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1.5.4"
    ATTRS{idVendor}=="8564"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="6"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="300mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="1100"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="55WWWN4CFK04UUMU"
    ATTRS{version}==" 2.10"
    ATTRS{urbnum}=="4531"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="JetFlash"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="1000"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}=="Mass Storage Device"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5':
    KERNELS=="1-1.5"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{devpath}=="1.5"
    ATTRS{idVendor}=="1a40"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="4"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="100mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="4"
    ATTRS{bcdDevice}=="0111"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="80"
    ATTRS{ltm_capable}=="no"
    ATTRS{removable}=="removable"
    ATTRS{idProduct}=="0101"
    ATTRS{bDeviceClass}=="09"
    ATTRS{product}=="USB 2.0 Hub"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="02"
    ATTRS{devpath}=="1"
    ATTRS{idVendor}=="0424"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="2"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="2mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="5"
    ATTRS{bcdDevice}=="0200"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="43"
    ATTRS{ltm_capable}=="no"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="9514"
    ATTRS{bDeviceClass}=="09"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{devpath}=="0"
    ATTRS{idVendor}=="1d6b"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{authorized_default}=="1"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="1"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="0mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="1"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{bcdDevice}=="0404"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="3f980000.usb"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="25"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 4.4.16-v7+ dwc_otg_hcd"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="0002"
    ATTRS{bDeviceClass}=="09"
    ATTRS{product}=="DWC OTG Controller"

  looking at parent device '/devices/platform/soc/3f980000.usb':
    KERNELS=="3f980000.usb"
    SUBSYSTEMS=="platform"
    DRIVERS=="dwc_otg"
    ATTRS{hnp}=="HstNegScs = 0x0"
    ATTRS{srp}=="SesReqScs = 0x1"
    ATTRS{regvalue}=="invalid offset"
    ATTRS{hsic_connect}=="HSIC Connect = 0x1"
    ATTRS{guid}=="GUID = 0x2708a000"
    ATTRS{mode}=="Mode = 0x1"
    ATTRS{srpcapable}=="SRPCapable = 0x1"
    ATTRS{regdump}=="Register Dump"
    ATTRS{gpvndctl}=="GPVNDCTL = 0x00000000"
    ATTRS{ggpio}=="GGPIO = 0x00000000"
    ATTRS{hprt0}=="HPRT0 = 0x00001005"
    ATTRS{wr_reg_test}=="Time to write GNPTXFSIZ reg 10000000 times: 350 msecs (35 jiffies)"
    ATTRS{driver_override}=="(null)"
    ATTRS{hcd_frrem}=="HCD Dump Frame Remaining"
    ATTRS{mode_ch_tim_en}=="Mode Change Ready Timer Enable = 0x0"
    ATTRS{gnptxfsiz}=="GNPTXFSIZ = 0x01000306"
    ATTRS{remote_wakeup}=="Remote Wakeup Sig = 0 Enabled = 0 LPM Remote Wakeup = 0"
    ATTRS{busconnected}=="Bus Connected = 0x1"
    ATTRS{hcddump}=="HCD Dump"
    ATTRS{gotgctl}=="GOTGCTL = 0x001c0001"
    ATTRS{spramdump}=="SPRAM Dump"
    ATTRS{grxfsiz}=="GRXFSIZ = 0x00000306"
    ATTRS{gsnpsid}=="GSNPSID = 0x4f54280a"
    ATTRS{gusbcfg}=="GUSBCFG = 0x20001700"
    ATTRS{hptxfsiz}=="HPTXFSIZ = 0x02000406"
    ATTRS{devspeed}=="Device Speed = 0x0"
    ATTRS{fr_interval}=="Frame Interval = 0x1d4c"
    ATTRS{rem_wakeup_pwrdn}==""
    ATTRS{bussuspend}=="Bus Suspend = 0x0"
    ATTRS{buspower}=="Bus Power = 0x1"
    ATTRS{hnpcapable}=="HNPCapable = 0x1"
    ATTRS{rd_reg_test}=="Time to read GNPTXFSIZ reg 10000000 times: 800 msecs (80 jiffies)"
    ATTRS{enumspeed}=="Device Enumeration Speed = 0x1"
    ATTRS{inv_sel_hsic}=="Invert Select HSIC = 0x0"
    ATTRS{regoffset}=="0xffffffff"

  looking at parent device '/devices/platform/soc':
    KERNELS=="soc"
    SUBSYSTEMS=="platform"
    DRIVERS==""
    ATTRS{driver_override}=="(null)"

  looking at parent device '/devices/platform':
    KERNELS=="platform"
    SUBSYSTEMS==""
    DRIVERS==""


■ このトピックへのコメント投稿フォーム ■
キャンセル
※ HTMLタグは使えません
* 名前
* MAIL
* URL
本文
PASS ※ 半角英数8文字まで
認証 ※ 六壱四九弐を半角数字で入力して下さい
  * 印の項目をcookieに保存する

2016 calendar
8月
123456
78910111213
14151617181920
21222324252627
28293031


掲示板
最新:08/15 17:19


GsBlog was developed by GUSTAV, Copyright(C) 2003, Web Application Factory All Rights Reserved.