ソフトウェアRAID1設定

Seagateの8TBハードディスクを2台購入したので、RAIDを組むことにした。デスクトップに使用しているマザーボードにはfake RAID機能はあるが、柔軟に運用したいのでソフトウェアRAIDを使う。RAIDのレベルは1のミラーリング。作業が終わってからまとめたので実際の作業と違う場合があると思う。あくまで防備録。このとおり作業してうまく行かないかもしれないので、自己責任で参考にして欲しい。

概 要

  • 500GBのSSDにxubuntu16.04がインストール済み。ファイルフォーマットはLVM。
  • 新規に8TBのハードディクスを2台購入したので、これらをRAID化する。
  • デスクトップにハードディスクに搭載したところ、デバイス名は/dev/sdbと/dev/sdcになった。
  • 上記のRAID化されたハードディスクにはSSDの/home以下のすべてのファイルを移動する。

作 業

  • ハードディスクのフォーマット
    •  $ sudo gdisk /dev/sdb
      GPT fdisk (gdisk) version 1.0.1Partition table scan:
      MBR: protective
      BSD: not present
      APM: not present
      GPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): ?
      b back up GPT data to a file
      c change a partition’s name
      d delete a partition
      i show detailed information on a partition
      l list known partition types
      n add a new partition
      o create a new empty GUID partition table (GPT)
      p print the partition table
      q quit without saving changes
      r recovery and transformation options (experts only)
      s sort partitions
      t change a partition’s type code
      v verify disk
      w write table to disk and exit
      x extra functionality (experts only)
      ? print this menuCommand (? for help): i
      No partitionsCommand (? for help): n
      Partition number (1-128, default 1):
      First sector (34-15628053134, default = 2048) or {+-}size{KMGTP}:
      Last sector (2048-15628053134, default = 15628053134) or {+-}size{KMGTP}:
      Current type is ‘Linux filesystem’
      Hex code or GUID (L to show codes, Enter = 8300): L
      0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
      3000 ONIE boot 3001 ONIE config 3900 Plan 9
      4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata
      4202 Windows Storage Spac 7501 IBM GPFS 7f00 ChromeOS kernel
      7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap
      8300 Linux filesystem 8301 Linux reserved 8302 Linux /home
      8303 Linux x86 root (/) 8304 Linux x86-64 root (/ 8305 Linux ARM64 root (/)
      8306 Linux /srv 8307 Linux ARM32 root (/) 8400 Intel Rapid Start
      8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot
      a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS
      a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot
      a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS
      a585 Midnight BSD Vinum a600 OpenBSD disklabel a800 Apple UFS
      a901 NetBSD swap a902 NetBSD FFS a903 NetBSD LFS
      a904 NetBSD concatenated a905 NetBSD encrypted a906 NetBSD RAID
      ab00 Recovery HD af00 Apple HFS/HFS+ af01 Apple RAID
      af02 Apple RAID offline af03 Apple label af04 AppleTV recovery
      af05 Apple Core Storage bc00 Acronis Secure Zone be00 Solaris boot
      bf00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap
      bf03 Solaris backup bf04 Solaris /var bf05 Solaris /home
      bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2
      Press the <Enter> key to see more codes: 8e00
      bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5
      c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT
      eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit
      ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition
      f800 Ceph OSD f801 Ceph dm-crypt OSD f802 Ceph journal
      f803 Ceph dm-crypt journa f804 Ceph disk in creatio f805 Ceph dm-crypt disk i
      fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p
      fd00 Linux RAID
      Hex code or GUID (L to show codes, Enter = 8300): 8e00
      Changed type of partition to ‘Linux LVM’Command (? for help): ?
      b back up GPT data to a file
      c change a partition’s name
      d delete a partition
      i show detailed information on a partition
      l list known partition types
      n add a new partition
      o create a new empty GUID partition table (GPT)
      p print the partition table
      q quit without saving changes
      r recovery and transformation options (experts only)
      s sort partitions
      t change a partition’s type code
      v verify disk
      w write table to disk and exit
      x extra functionality (experts only)
      ? print this menuCommand (? for help): t
      Using 1
      Current type is ‘Linux LVM’
      Hex code or GUID (L to show codes, Enter = 8300): fd00
      Changed type of partition to ‘Linux RAID’Command (? for help): p
      Disk /dev/sdb: 15628053168 sectors, 7.3 TiB
      Logical sector size: 512 bytes
      Disk identifier (GUID): 3989C8E8-0741-47FE-B36E-B96590B6BD7E
      Partition table holds up to 128 entries
      First usable sector is 34, last usable sector is 15628053134
      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 15628053134 7.3 TiB FD00 Linux RAIDCommand (? for help): wFinal 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/sdb.
      The operation has completed successfully.
    • $ sudo gdisk /dev/sdc
      GPT fdisk (gdisk) version 1.0.1Partition table scan:
      MBR: not present
      BSD: not present
      APM: not present
      GPT: not presentCreating new GPT entries.Command (? for help): ?
      b back up GPT data to a file
      c change a partition’s name
      d delete a partition
      i show detailed information on a partition
      l list known partition types
      n add a new partition
      o create a new empty GUID partition table (GPT)
      p print the partition table
      q quit without saving changes
      r recovery and transformation options (experts only)
      s sort partitions
      t change a partition’s type code
      v verify disk
      w write table to disk and exit
      x extra functionality (experts only)
      ? print this menuCommand (? for help): n
      Partition number (1-128, default 1):
      First sector (34-15628053134, default = 2048) or {+-}size{KMGTP}:
      Last sector (2048-15628053134, default = 15628053134) or {+-}size{KMGTP}:
      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): wFinal 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.
    • RAIDソフトウェアのインストール
      • $ sudo apt install mdadm
    • HDD(/dev/sdb1, /dev/sdc1) 2台をソフトウェアRAIDにするために /dev/md0 に割り当てる。
      • $ sudo mdadm --create /dev/md0 --level=raid1 --raid-devices=2 /dev/sdb1 /dev/sdc1 --assume-clean
      • /dev/sdb1, /dev/sdc1はブート可能なパーティションでないので以下のようにwarningが出るがyキーを押して次に進むとRAIDアレー/dev/md0がスタートする。
        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.
    • RAIDができているか次のコマンドで確認する。
      • $ cat /proc/mdstat
      • 以下のようなメッセージが出たら成功
        Personalities : [raid1]
        md0 : active raid1 sdc1[1] sdb1[0]
        7813894464 blocks super 1.2 [2/2] [UU]
        bitmap: 0/59 pages [0KB], 65536KB chunkunused devices: <none>
  • RAIDの設定
    • ここでは、RAIDシステムからブートをしないので、LVMだけの1パーティションとする。2TBを超えるRAIDシステムからブートしたい場合はGPTからブートするための1MBの領域を先頭に確保する必要があるが、ここではしない。
    • $ sudo gdisk /dev/md0
      [sudo] パスワード:
      GPT fdisk (gdisk) version 1.0.1Partition table scan:
      MBR: not present
      BSD: not present
      APM: not present
      GPT: not presentCreating new GPT entries.Command (? for help): n
      Partition number (1-128, default 1):
      First sector (34-15627788894, default = 2048) or {+-}size{KMGTP}:
      Last sector (2048-15627788894, default = 15627788894) or {+-}size{KMGTP}:
      Current type is ‘Linux filesystem’
      Hex code or GUID (L to show codes, Enter = 8300): L
      0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
      3000 ONIE boot 3001 ONIE config 3900 Plan 9
      4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata
      4202 Windows Storage Spac 7501 IBM GPFS 7f00 ChromeOS kernel
      7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap
      8300 Linux filesystem 8301 Linux reserved 8302 Linux /home
      8303 Linux x86 root (/) 8304 Linux x86-64 root (/ 8305 Linux ARM64 root (/)
      8306 Linux /srv 8307 Linux ARM32 root (/) 8400 Intel Rapid Start
      8e00 Linux LVM a500 FreeBSD disklabel a501 FreeBSD boot
      a502 FreeBSD swap a503 FreeBSD UFS a504 FreeBSD ZFS
      a505 FreeBSD Vinum/RAID a580 Midnight BSD data a581 Midnight BSD boot
      a582 Midnight BSD swap a583 Midnight BSD UFS a584 Midnight BSD ZFS
      a585 Midnight BSD Vinum a600 OpenBSD disklabel a800 Apple UFS
      a901 NetBSD swap a902 NetBSD FFS a903 NetBSD LFS
      a904 NetBSD concatenated a905 NetBSD encrypted a906 NetBSD RAID
      ab00 Recovery HD af00 Apple HFS/HFS+ af01 Apple RAID
      af02 Apple RAID offline af03 Apple label af04 AppleTV recovery
      af05 Apple Core Storage bc00 Acronis Secure Zone be00 Solaris boot
      bf00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap
      bf03 Solaris backup bf04 Solaris /var bf05 Solaris /home
      bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2
      Press the <Enter> key to see more codes: 8e00
      bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5
      c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT
      eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit
      ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition
      f800 Ceph OSD f801 Ceph dm-crypt OSD f802 Ceph journal
      f803 Ceph dm-crypt journa f804 Ceph disk in creatio f805 Ceph dm-crypt disk i
      fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p
      fd00 Linux RAID
      Hex code or GUID (L to show codes, Enter = 8300): 8e00
      Changed type of partition to ‘Linux LVM’Command (? for help): wFinal 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/md0.
      The operation has completed successfully.
    • ボリュームグループの作成
      • $ sudo vgcreate vg0 /dev/md0p1
    • 論理グループの作成(容量7000GB, グループ名home)
      • $ sudo lvcreate -L 7000G -n home vg0
    • 論理グループの確認
      • $ sudo lvdisplay
        — Logical volume —
        LV Path /dev/vg0/home
        LV Name home
        VG Name vg0
        LV UUID istCD7-ChY7-wnln-7p7C-BmFN-zktF-qpwZ1x
        LV Write Access read/write
        LV Creation host, time deneb, 2019-03-14 12:11:06 +0900
        LV Status available
        # open 0
        LV Size 6.84 TiB
        Current LE 1792000
        Segments 1
        Allocation inherit
        Read ahead sectors auto
        – currently set to 256
        Block device 252:2— Logical volume —
        LV Path /dev/xubuntu-vg/root
        LV Name root
        VG Name xubuntu-vg
        LV UUID YXZMxe-ZRvz-E925-dXq7-ifam-6D2E-2gjmYK
        LV Write Access read/write
        LV Creation host, time xubuntu, 2017-11-27 19:11:58 +0900
        LV Status available
        # open 1
        LV Size 433.34 GiB
        Current LE 110936
        Segments 1
        Allocation inherit
        Read ahead sectors auto
        – currently set to 256
        Block device 252:0— Logical volume —
        LV Path /dev/xubuntu-vg/swap_1
        LV Name swap_1
        VG Name xubuntu-vg
        LV UUID 9UY9Wk-DRAD-J0ou-OD2Y-Vkhk-JZcJ-L6Xn3w
        LV Write Access read/write
        LV Creation host, time xubuntu, 2017-11-27 19:11:58 +0900
        LV Status available
        # open 2
        LV Size 31.94 GiB
        Current LE 8176
        Segments 1
        Allocation inherit
        Read ahead sectors auto
        – currently set to 256
        Block device 252:1
    • 論理グループにext4ファイルシステムを作成
      • $ sudo mkfs -t ext4 /dev/vg0/home
      • 以下のようなメッセージが表示される。
        mke2fs 1.42.13 (17-May-2015)
        Creating filesystem with 1835008000 4k blocks and 229376000 inodes
        Filesystem UUID: 20824f90-4741-4c0a-8947-d53945ff2a13
        Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000, 550731776, 644972544Allocating group tables: done
        Writing inode tables: done
        Creating journal (32768 blocks): done
        Writing superblocks and filesystem accounting information: done
  • RAIDのディスクをマウント
    • $ cd /
    • $ sudo mkdir  home_raid
    • $ sudo mount -o rw -t ext4 /dev/vg0/home  /home_raid
  • 起動時に自動的にマウントするために、/etc/fstabを以下のように変更する。

# /etc/fstab: static file system information.
#
# Use ‘blkid’ to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/xubuntu–vg-root / ext4 errors=remount-ro 0 1
/dev/mapper/xubuntu–vg-swap_1 none swap sw 0 0
/dev/vg0/home /home_raid ext4 defaults 1 2

  • 再起動してマウントされているか確認する。
    • $ sudo reboot
  • 起動したら以下のコマンドでマウントされているか 確認する
    • $ df

Filesystem 1K-blocks Used Available Use% Mounted on
udev 16414044 0 16414044 0% /dev
tmpfs 3287988 9716 3278272 1% /run
/dev/mapper/xubuntu–vg-root 447132544 411764952 12631516 98% /
tmpfs 16439936 4228 16435708 1% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 16439936 0 16439936 0% /sys/fs/cgroup
/dev/loop0 93184 93184 0 100% /snap/core/6405
/dev/loop1 108288 108288 0 100% /snap/cloudcompare/131
/dev/loop2 93312 93312 0 100% /snap/core/6531
/dev/loop3 93184 93184 0 100% /snap/core/6350
/dev/mapper/vg0-home 7282070296 51592 6915000720 1% /home_raid
tmpfs 3287988 4 3287984 1% /run/user/108
tmpfs 3287988 40 3287948 1% /run/user/1000

  • マウントされていたら、SSDにある/homeの内容をRAIDに移動させるためにTRL+ALT+F1を同時に押してXを落としてrootでログインする。/homeを/home_ssdに移動する。
    • #  mv  /home   /home_ssd
  • 空の/homeディレクトリを作成する
    • # mkdir  /home
  •  /home_ssdの内容を/home_raidにコピーする。
    • # cp -a /home_ssd   /home_raid
  • SSDの/homeの内容をRAIDに移動したのでマウントポイントを変更するために、/etc/fstabの一番下の行を以下のように変更してリブートする。# /etc/fstab: static file system information.
    #
    # Use ‘blkid’ to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point> <type> <options> <dump> <pass>
    /dev/mapper/xubuntu–vg-root / ext4 errors=remount-ro 0 1
    /dev/mapper/xubuntu–vg-swap_1 none swap sw 0 0
    /dev/vg0/home /home ext4 defaults 1 2

再起動して /homeの内容に問題なければ成功。

終わり

参 考

  • https://www.linuxmania.jp/raid_md_grub.html

コメント

Folding@home Kanazawa (ID 257261)

みんなのためにおうちで新型コロナウイルスを解析しよう!

タイトルとURLをコピーしました